Expiration policy for Redis

Source: Internet
Author: User

EXPIREKeyseconds

Available since 1.0.0.

Time Complexity: O (1)


Sets an expiration time for the specified key. When the expiration time expires, the key will be deleted automatically. If you use the DEL command to remove this key, either use the SET command or the Getset command to reset the key value. The expiration time will be cleared. Use persist to convert this key to a persistent key, or to clear the expiration time.

If you use Rename to rename a key, the expiration time of the key association will be converted to the expiration time of the new key.

You can use expire to update the expiration time of a key


The Expiration time information for key is stored as a Unix timestamp. This means that even if the Redis instance is not running, the expiration time will slowly decrease. For example, if you set a key with a TTL of 1000 seconds, then set the current time of the computer to 2000 seconds in the future, then the key will expire immediately instead of waiting for 1000 seconds before expiring.



How Redis expires Keys

There are two types of Redis key expiration policies: passive and active.

If a client tries to access a key and discovers that the key is obsolete, this is the active expiration of key.

However, if some key is not accessed by the client, these keys will expire anyway. Redis randomly tests some keys that set the expiration time, and if it expires, delete the keys.


Specifically, Redis will do the following 10 times per second:

    1. Test 20 keys with expiration time set

    2. Delete keys that have been found to have expired

    3. If you find that the extra 25 keys have expired, start from the beginning of the first step.







Reference Documentation:

Http://redis.io/commands/expire


This article is from the Linux SA John blog, so be sure to keep this source http://john88wang.blog.51cto.com/2165294/1629149

Expiration policy for Redis

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.