What is the principle of redis expiration?

set a key-value pair in redis and expire after 1000 seconds

set test "nnn"

expire test 1000
After

, change the system time to this time tomorrow, using the following command:

ttl test
-2
The result of

is-2.

excuse me: what is the impact of modifying system time on redis cache?

Mar.11,2021

redis triggers expiration conditions. There are two types:

  • internally query expired key based on system time
  • when actively querying this key, it will detect whether it has expired

redis expiration time is the timestamp after the current time + expiration time is settled, that is, the expiration time. Therefore, the change of system time will affect the expiration time of redis.


official documentation: https://redis.io/commands/exp.


 //client.set24client.set
 client.set(args, data, 'EX', 24 * 60 * 60, (error, param) => {
  });

 client.del(args, args);//client.del

redis official documentation is available.

Menu