Redis expiration Policy, redis expired
I. redis keys have six expiration policies
1. noeviction: Once the memory is full, an error is returned.
2. allkeys-lru: Perform LRU on all keys
3. volatile-lru: Only LRU is performed on expired keys (default)
4. allkeys-random: Randomly removes a key.
5. volatile-random: Randomly removes an expired key.
6. volatile-ttl: Delete the expired key
According to the official website, the LRU used by redis is not a real LRU algorithm, and the accuracy is not high. LRU of redis3.0 maintains a candidate pool, which improves performance.
Ii. Set and view memory and expiration policies
1. Set the memory size of the Instance (-h $ host is not required for local execution, and the Unit is B)
Redis-cli-h $ host-p $ port config set maxmemory 1024
2. Obtain the memory size of the instance.
Redis-cli-h $ host-p $ port config get maxmemory
3. Set an expiration Policy
Redis-cli-h $ host-p $ port config set maxmemory-policy volatile-lru
4. view the expiration Policy
Redis-cli-h $ host-p $ port config get maxmemory-policy
Note: volatile-lru has been tested. If a key with an expiration time is set, LRU is executed and can be inserted. If no key with an expiration time is set, an error is returned.