(v) Expiration key (1) Expiration key setting, getting and deleting expiration time

Source: Internet
Author: User

Set Expiration

By default, the key is no time to live, that is, never expires, unless the memory is emptied.

The key set has a very easy time to live, too 4 Span style= "font-size:14px;font-family: ' The song Body '; > command set (optional): expire pexpire pexpireat expire and pexpire

Set in seconds, set AAA This key expires after 1 seconds,1 seconds later to obtain the AAA This key is returned empty.

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/83/F5/wKioL1eB7QCjr6PPAAA_7WoHjeA590.jpg-wh_500x0-wm_3 -wmp_4-s_2290075509.jpg "title=" 1.jpg "alt=" Wkiol1eb7qcjr6ppaaa_7wohjea590.jpg-wh_50 "/>

set in milliseconds, set the BBB this key to expire after ten milliseconds.

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/83/F6/wKiom1eB7QmB-BH-AABPwTa0DEk928.jpg-wh_500x0-wm_3 -wmp_4-s_4170721841.jpg "title=" 2.jpg "alt=" Wkiom1eb7qmb-bh-aabpwta0dek928.jpg-wh_50 "/>

Command Description
Expirekey #s will be KEY the time to live is set to # seconds
PEXPIRE Key #ms key #
EXPIREA Tkey timestamp key unix
Pexpireatkey Timestamp will be KEY the time to live is set to UNIX Timestamp , in milliseconds

the above 4 commands are only different in terms of units and manifestations, but in fact the execution of EXPIRE,Pexpire, and expireat commands will eventually be used pexpireat to practice.

such as using EXPIRE to set the lifetime of the KEY is N seconds, then the background is how to run it:

    • it will call the Pexpire command converts N seconds to M milliseconds

    • then get the current UNIX time units are also milliseconds

    • the current UNIX time plus M milliseconds passed to pexpreat

The key is set to expire time, this time is saved in a dictionary, is also the key value structure, the key is a pointer, pointing to the real key, and the value of this is a long integer type UNIX time.


Gets the expiration time of the key

How do I see how much time it takes to live a key? You can use the TTL key to get (shown in seconds), such as:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/83/F5/wKioL1eB7i_CKZGhAACYEYNvgh0020.jpg-wh_500x0-wm_3 -wmp_4-s_2130158381.jpg "title=" 3.jpg "alt=" Wkiol1eb7i_ckzghaacyeynvgh0020.jpg-wh_50 "/>

Another command is Pttl key, which is shown in milliseconds.


The expiration time of the purge key

can use the PERSIST command removes the expiration time of a key, such as:

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/F6/wKiom1eB7jrBgUeSAABsa7F2kSA394.jpg-wh_500x0-wm_3 -wmp_4-s_395642179.jpg "title=" 4.jpg "alt=" Wkiom1eb7jrbguesaabsa7f2ksa394.jpg-wh_50 "/>


Description of the return value for the expiration time

through You can get the integer return value of a key

Value Description
-2 Expired and deleted
-1 No expiration time setting, i.e. never expires
>0 Indicates how many seconds or milliseconds the distance expires

This article is from the "Little Demon's Home" blog, so be sure to keep this source http://littledevil.blog.51cto.com/9445436/1813956

(v) Settings for expiration key (1) expiration key, get and delete expiration time

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.