In addition to being used as cache data, Redis can also do these
Redis should be one of the most popular NoSQL databases at the moment. Redis is typically used as a cache component for caching data. However, in addition to caching data, there are many things that redis can do. Here are some examples for your reference. 1. Latest list
For example, the latest news list on the News list page, if the total number is large, try not to use Select a from a limit 10, try Redis's Lpush command to build the list, in order to plug it in. But what if the memory is cleared out. Also simple, query not to store key words, with MySQL query and initialize a list to Redis is good. 2. Leaderboard Application
The Redis data type that is used to implement this feature is the ordered set of Redis Zset. Zset is an extension of the set type that has a sequential property that is more than the original type, which automatically adjusts the order value each time the data is inserted, ensuring that the value values are sequentially arranged in a sequential order.
We assume that it is a game XP leaderboard, and that the main implementation idea is:
1, in a new player to participate in the game, in the Redis Zset in a new record (record content to see the specific needs) score 0
2, when the player's experience value changes, modify the player's score value
3. Use Redis's Zrevrange method to get Leaderboard 3, counter application
Redis commands are atomic, and you can easily use INCR, DECR commands for atomic operations to build a counting system. Because of the single thread, concurrency issues can be avoided, guaranteed to be error-prone, and 100% millisecond performance.
For example, in a Web application, if you want to know the user's daily clicks in a year, just use the user ID and the relevant date information as the key, and perform a self-increment action every time the user clicks the page. 4, Data discharge weight
Redis set is a good choice when you need to store a list of data, and you do not want duplicate data, and set provides an important interface to determine whether a member is within a set set.
Implementation scenarios:
The internal implementation of set is a value that is always null hashmap, which is actually calculated by hashing the way to fast weight, which is also set to provide a judge whether a member is within the cause of the collection. 5. Real-time anti-spam system
Anti-spam systems are usually keyword-based, using Redis storage relations, can use the high performance of Redis, provide stable and accurate real-time monitoring function for monitoring system, typical cases such as mail system, commenting system, etc. 6, can publish, subscribe to the real-time message system
The pub/sub system in Redis can build real-time messaging systems, such as many real-time chat applications built using Pub/sub.
Design ideas:
The server sends the message (with the title, content), the title in accordance with certain rules to the Redis, while the title (with the least amount of information) pushed to the client, the customer click on the title, to get the corresponding content to read.
If not read, you can prompt how many unread, Redis can quickly count
Clean up the cache for a certain amount of time
Technical implementation:
Requires Redis database, client websocket, server-side WebSocket 7, queue application
Queues are widely used in the current program, such as log push, task processing, and so on. Queues are usually implemented using HTTP SQS, but they can also be implemented using the Redis list type.
Examples are as follows: