Redis is a high-performance key-value database. It is completely open source and free. Moreover, redis is a NOSQL type database. It is a database created to solve a series of problems such as high concurrency, high expansion, and big data storage. The solution is a non-relational database.
Function:
Caching is the most common application scenario of Redis, so it is mainly used This is because Redis has excellent read and write performance. And it has gradually replaced memcached and become the preferred server-side cache component. Moreover, Redis supports transactions internally, which can effectively ensure data consistency when used. (Recommended learning: Redis video tutorial)
ranking, it is very troublesome to do this using traditional relational databases (mysql oracle, etc.) , and it can be easily done using the SortSet (ordered set) data structure of Redis;
Calculator/Speed Limiter, using the atomic auto-increment operation in Redis, we can count Similar to the number of user likes, user visits, etc., if MySQL is used for such operations, frequent reading and writing will bring considerable pressure; a typical usage scenario of the speed limiter is to limit the frequency of a user accessing a certain API. Commonly used ones are to prevent users from unnecessary pressure caused by crazy clicking during rush buying;
Friend Relationship uses some commands of collection, such as intersection, union, difference set, etc. It can easily handle functions such as mutual friends and common hobbies;
Simple message queue, in addition to Redis's own publish/subscribe mode, we can also use List to implement a queue mechanism. For example: requirements such as arrival notification and email sending do not require high reliability, but will bring a lot of DB pressure. You can use List to complete asynchronous decoupling;
Session Sharing, taking PHP as an example, the default Session is saved in the server file. 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, regardless of the user The corresponding Session information can be obtained on that machine.
Some frequently accessed data. If the frequently accessed data is placed in a relational database, the cost of each query will be very high. However, if it is placed in redis, because redis is Can be accessed very efficiently in memory
The above is the detailed content of What functions require the use of redis. For more information, please follow other related articles on the PHP Chinese website!