Joke Collection Website - Public benefit messages - Where is redis used?
Where is redis used?
Where is redis used?
Redis application scenarios
● Token generation
● SMS verification code
● Ranking list
< p>● Message QueueThe data structure implementation of list in Redis is a doubly linked list, so it can be very conveniently applied to message queue (producer/consumer model). The producer of the message only needs to put the message into the list through lpush, and the consumer can take out the message through rpop, and the order of the message can be guaranteed. If you need to implement a message queue with priority, you can also choose sorted set. The pub/sub functionality can also be used as a publisher/subscriber model for messages. No matter which method is used, because Redis has a persistence function, there is no need to worry about message loss due to server failure. (Recommended: "Redis Video Tutorial")
If you have high requirements for data consistency, you should use professional systems such as RocketMQ.
Since redis adds data to the queue by returning the number of the added element in the queue, it can be used to determine the number of users accessing this kind of business
The queue can not only add concurrency The request becomes serial, and can also be used as a queue or stack
Distributed lock
To verify the repeated requests of the front end, it can be filtered through redis
Instant kill The system, based on the single-threaded feature of redis, prevents database "explosion"
Global incremental ID generation, similar to "flash kill"
Counters
Such as statistical clicks Number applications. Due to the single thread, concurrency problems can be avoided, error-free guaranteed, and 100% millisecond-level performance!
The counting function should be one of the most suitable usage scenarios for Redis, because its high-frequency read and write characteristics can fully utilize the efficiency of Redis as an in-memory database. In the Redis data structure, string, hash and sorted set all provide the incr method for atomic increment operations.
Example:
If the application needs to display the number of registered users every day, you can use string as the counter, set a key named REGISTERED_COUNT_TODAY, and set it during initialization At the expiration time of 0 am, every time the user registers successfully, use the incr command to increase the key by 1. At the same time, after 0 am every day, the counter will be cleared to zero due to the expiration of the key.
Each Weibo post has four attributes: number of likes, number of comments, number of retweets, and number of views. In this case, it would be better to use hash for counting. Set the key of the counter to weibo:weibo_id, hash The fields are like_number, comment_number, forward_number and view_number. After the corresponding operation, the fields in the hash are incremented through hincrby.
If the application has a post ranking function, select sorted set and set the key of the set to POST_RANK. When a user posts, use zincrby to increase the score of the user id by 1. The sorted set will be re-sorted, and the user's ranking position will be updated in real time.
- Related articles
- 2014 New Year’s Eve SMS
- Where can I change my driver's license in Langfang?
- What will happen before the Bank of Communications credit card is blocked? Can you unseal it?
- Thank you for your congratulations from your outgoing colleagues.
- Mobile sent a text message saying that you can get a mobile phone for free in the business hall. Is it true?/You don't say.
- How to write the notice of storing express delivery fees during the epidemic in convenience stores?
- The news of the Year of the Tiger on the Internet is sent to leaders and related to mahjong, hehe.
- China moved in.
- How to solve the problem that Japanese version of iphone5 can't send short messages?
- The May Day Labor Day holiday is over to express your mood. The holiday is over and you are relieved from work.