Home > Article > Backend Development > What can redis do?
Redis can be used for caching, which is very effective in improving server performance; redis can also be used for rankings, which can be easily achieved using the SortSet data structure of Redis; redis can also be used as a "calculator/speed limiter", etc. .
What can redis do?
1. Caching, there is no doubt that this is the most well-known usage scenario of Redis today. It is very effective in improving server performance;
2. Ranking list. If you use a traditional relational database to do this, it will be very troublesome, but using the SortSet data structure of Redis can be very convenient;
3. Calculator/speed limiter, using the atomic auto-increment operation in Redis, we can count the number of user likes, user visits, etc. If MySQL is used for such operations, frequent reading and writing will cause This brings considerable pressure; a typical usage scenario of the speed limiter is to limit the frequency of a certain user accessing a certain API. It is commonly used during rush sales to prevent users from unnecessary pressure caused by crazy clicking;
Note : The rate limiter is also a way to implement request current limiting.
4. Friend relationship, using some commands of collection, such as intersection, union, difference set, etc. It can easily handle functions such as mutual friends and common hobbies;
5. Simple message queue, in addition to Redis's own publish/subscribe mode, we can also use List to implement a queue mechanism, such as: arrival of goods Requirements such as notifications and email sending do not require high reliability, but will bring a lot of DB pressure. List can be used to complete asynchronous decoupling;
6. Session sharing, the default Session is saved in In the server's file, that is, the current server, if it is a cluster service, the same user may land on different machines, which will cause users to log in frequently; after using Redis to save the Session, the user can obtain it no matter which machine he lands on. to the corresponding Session information.
The above is the detailed content of What can redis do?. For more information, please follow other related articles on the PHP Chinese website!