1. Before implementing the cache ordering function, you must understand the rationality of this function. Think about it, since it can be sorted in the database, why put the sorting function in the cache? Here's a brief summary of two reasons: first, sorting increases the load on the database, it is difficult to support high concurrency, and second, sorting in the cache does not encounter table locking issues. Redis happens to provide sorting capabilities, allowing us to easily implement cache ordering.
2.
Application of Redis to read and write data, while using the queue processor timing to write data to MySQL.
3.
When Redis starts, go to MySQL to read all the table key values into Redis, when you write data to Redis, the Redis primary key is increased and read, and if the MySQL update fails, you need to clear the cache and synchronize the Redis primary key in a timely manner.
This process, mainly in real-time to read and write Redis, and MySQL data through the queue asynchronous processing, to alleviate the MySQL pressure, but this method is mainly based on high concurrency, and Redis's highly available cluster architecture is relatively more complex, generally not recommended.
4.
Redis Configuration
As a cache server, if you do not limit memory, it is very likely that the entire server memory consumption, can be set in the Redis configuration file:
# Limit up to 1.5GB memory MaxMemory 1536MB
If the memory reaches the specified upper limit and adds more cache content to the Redis, the policy for cleaning up the content needs to be set:
# Set the policy to clean up the data corresponding to the least used key Maxmemory-policy ALLKEYS-LRU
Simple implementation of the sorting function in the Redis cache