Home > Database > Redis > body text

Where is redis generally used?

(*-*)浩
Release: 2019-11-30 09:09:58
Original
2807 people have browsed it

Where is redis generally used?

redis is a key-value storage system, which can be used in the following scenarios, 1, 2, and 5 are more commonly used

1. Cache

Hot data (data that is often queried but not often modified or deleted), the first choice is to use redis cache. (Recommended learning: Redis video tutorial)

2. Counter

Single thread avoids concurrency problems, high performance, such as inventory reduction.

3. Queue

is equivalent to a messaging system. ActiveMQ, RocketMQ and other tools are similar, but I personally think it is okay to use it simply if the data consistency requirements are high. Or use professional systems such as RocketMQ.

4. Bit operations

Use setbit, getbit, and bitcount commands, such as counting user sign-ins, counting the number of deduplication logins, whether a user is online, etc.;

Construct a long enough array in redis. Each array element can only have two values ​​​​0 and 1, and then the subscript index of this array is used to represent the user ID in our example above (must be a number) , then it is obvious that this large array with a length of hundreds of millions can build a memory system through subscripts and element values ​​​​(0 and 1), and the several scenarios I mentioned above can also be realized. The commands used are: setbit, getbit, bitcount

5, distributed lock and single-thread

to verify repeated requests from the front end (similar situations can be freely expanded), Filtering can be done through redis: for each request, the hash of the request IP, parameters, interface, etc. is used as a key to store redis (idempotent request), how long the validity period is set, and then when the next request comes, first search in redis to see if there is this key, and then verify whether it is a repeated submission within a certain period of time.

The flash kill system is based on the single-threaded feature of redis to prevent database "explosion"

6. The latest list

Redis's LPUSH command builds the List .

7. Ranking list

Whoever scores higher will be ranked higher. Command: ZADD (sorted set).

For more Redis-related technical articles, please visit the Redis Getting Started Tutorial column to learn!

The above is the detailed content of Where is redis generally used?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!