1. Separation of hot and cold data, do not put all the data in the Redis
Although Redis supports persistence, the data storage for Redis is all in memory and costly. It is recommended to store only high-frequency thermal data in Redis "QPS greater than 5000", for low-frequency cold data can use disk-based storage such as MYSQL/ELASTICSEARCH/MONGODB, not only to save the memory cost, and the small amount of data in the operation faster, Higher efficiency. 2. Different business data to be stored separately
Do not place irrelevant business data in a Redis instance, and suggest new business requests for a new, separate instance. Because Redis is single-threaded, isolated storage reduces the impact of different business interactions, increases request responsiveness, and avoids the excessive expansion of individual instance memory data, which can be restored faster in the event of an exception. 3. Specification of key format
The right key for easy viewing, statistics, and troubleshooting.
Like what:
Gateway |
Gw |
Platform Name |
platform abbreviation |
"Platform abbreviation" + ":" + "project name" + ":" + "business meaning"
Example: GW:TRADE:USERID
GW is a new gateway, trade is a trading item and UserID is the business ID.
":"-as a key delimiter, convenient for client tools as a catalog rating 4. Stored key Be sure to set the timeout time
If the app locates Redis for cache caching, you must set the timeout for the stored key. Because if not set, these keys will always take up memory not released, resulting in a great waste, and over time will lead to more memory consumption until the server memory limit is reached. In addition, the timeout length of key must be based on the business evaluation, not the longer the better. (Some business requires key to be valid for long term.) You can set the time-out period for each write, allowing the timeout to be postponed. )
public Boolean Set (final byte [] key, final byte [] value, final long liveTime ) { return redistemplate.execute (new rediscallback< Boolean> () { public Boolean Doinredis ( Redisconnection connection) throws DataAccessException { Connection.set (key, value); if (livetime > 0) { Connection.expire (key, Livetime); } |