Expire key seconds
ForKeySet the survival time whenKeyExpired (the survival time is0Is automatically deleted.
In redisKeyIt is called volatile ).
You can use the del command to delete the entire lifecycle.KeyOr overwrite by the set and GetSet commands. This means that if a command only modifies (Alter)KeyInstead of using a newKeyValue to replace it, so the survival time will not be changed.
For exampleKeyExecute the incr command, perform the lpush command on a list, or execute the hset command on a hash table.KeyThe time of its survival.
On the other hand, if you use RenameKeyAfter the name is changedKeyThe same as before.
Another possibility of the RENAME Command is to try to putKeyChanged to another one with a time-to-liveAnother_keyIn this case, the oldAnother_key(And its survival time) will be deleted, and then the oldKeyWill Be RenamedAnother_key, So the newAnother_keyAnd the originalKeySame.
You can run the persist command without deletingKeyTo removeKeyTime to survive, letKeyBecome a "persistent" (persistent) again)Key.
Update survival time
You canKeyExecute the expire command to replace the old life time with the new life time.
Precision of expiration time
In redis 2.4, the expiration time is within one second-that is, even ifKeyIt has expired, but it may still be accessed within one second after it expires. In the new redis 2.6 version, the latency is reduced to within 1 millisecond.
Redis> set mykey "hello"
OK
Redis> expire mykey 10
(integer) 1
Redis> TTL mykey
(integer) 10
Redis> set mykey "Hello World"
OK
Redis> TTL mykey
(integer) -1