What are the application scenarios of Redis
Redis is a key-value storage system, which can be used in the following scenarios.
1. Caching
Hot spot data (data that is often queried but not often modified or deleted) is preferred to use redis caching.
2. Counter
Single thread avoids concurrency problems with high performance, such as inventory reduction.
3. Queue
It is similar to messaging system, ActiveMQ,RocketMQ and other tools, but I think it is OK to use it simply. If it requires high data consistency, I still use professional systems such as RocketMQ.
4. Bit operation
Use setbit, getbit, bitcount commands, such as statistics of user check-in, re-login statistics, whether a user is online, etc.
Build an array long enough in redis, each array element can only be 0 and 1, and then the subscript index of this array is used to represent the user id in our example above (must be numeric ha), then obviously, this multi-million-long array can build a memory system by subscript and element values (0 and 1), and the above scenarios can also be implemented. The commands used are: setbit, getbit, bitcount
5. Distributed lock and single thread
To verify the repeated requests at the frontend (similar cases can be expanded freely), you can filter through redis: each request stores request Ip, parameters, APIs and other hash as key (idempotent request), sets the validity period, and then retrieves the key in redis when the next request comes, and then verifies whether the key has been repeatedly submitted within a certain period of time.
The second kill system, based on the single-thread feature of redis, prevents database "explosion".
6. The latest list
Redis's LPUSH command builds List.
7. Ranking
Who gets the highest score and who ranks high. Command: ZADD (ordered set, sorted set).
These are the details of where redis is generally used, please pay more attention to other related articles!