Python operation Redis Settings key expiration time

Source: Internet
Author: User

For an already existing key, we can set its expiration time, after that time, when you visit again, key will not exist

There are two ways to set the expiration time, one is to specify how long the key will survive from the current time, the time unit has two, one is the second, the other is the millisecond

The second way is to specify the key to expire at a certain time, which needs to specify the date of the year and seconds, if you specify this time is earlier than the current time, then this key will immediately expire

Now, we now add two keys to Redis, Ex1 and EX2, respectively.

Then set their expiration time in two different ways

#Coding=utf-8" "Created on 2015-9-8 @author:" "  ImportRedisImportdatetimeImportTime Pool=redis. ConnectionPool (host='192.168.1.126', port=6379,db=0) R= Redis. Strictredis (connection_pool=pool) Extime= Datetime.datetime (2015,9,8,15,19,10)  PrintR.expire ('Ex1', 10)  PrintExtime.strftime ('%y-%m-%d%h:%m:%s%f')    PrintR.expireat ('EX2', Extime)

The expire function sets the expiration time to 10 seconds. After 10 seconds, the EX1 will expire.

Expireat set a specific time, September 8, 15 15:19 10 seconds, after this time, EX2 will expire

Returns true if the set expiration time succeeds, otherwise false

Python operation Redis Settings key expiration time

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.