One, the Redis key has six kinds of expiration policy
1. Noeviction: Returns error once memory is full
2, ALLKEYS-LRU: All the key to the LRU
3, VOLATILE-LRU: only to set the expired key for LRU (the default way)
4, Allkeys-random: Randomly remove a key
5, Volatile-random: To set the expiration of the key to random culling a
6, Volatile-ttl: Delete the expiring key
According to the official website, the LRU used by Redis is not a real LRU algorithm, and the accuracy is not high. The redis3.0 version of LRU will maintain a candidate pool, which will perform better.
ii. settings and viewing of some memory and expiration policies
1, set the memory size of the instance (local execution can not use-h $host, the unit is B)
Redis-cli-h $host-P $port config set maxmemory 1024
2. Get the memory size of the instance
Redis-cli-h $host-P $port config get maxmemory
3. Set Expiration policy
Redis-cli-h $host-P $port config set maxmemory-policy volatile-lru
4. View Expiration policy
Redis-cli-h $host-P $port config get maxmemory-policy
Description: After testing the Volatile-lru, it is true that if there is a key that has an expiration time set, the LRU will be executed and the insertion can continue. If you don't have a key with expiration time set, you will get an error.
Redis Expiration Policy