Redis key expire

Source: Internet
Author: User

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.