简体   繁体   中英

Expiration of HashMap in Redis python?

I want to store the following hash map in redis:

"data": {
       "name": "XYZ",
       "age": 22,
       "address": "a-z"
}  

I want this whole hash map (with the given key) to expire in time, let's say 72 hours.

How do I use ttl/expire function in python?

Thanks,

Following is what I want to do, I guess it is right:

def put_data(name=hash_name, key=hash_key, value=hash_data):  
    import redis  
    r = Redis.get_connection()  
    ttl = datetime.today() + timedelta(hours=72)  
    r.hset(name=name, key=hash_key, value=hash_data)  
    r.expire(name=hash_name, time=ttl)

This is how:

redis_client.expire(your_key, time_in_seconds)

See the documentation .

假设您只想存储这些值,而不要存储帖子中显示的顶级字典,则可以使用hmset,然后使用expire来设置ttl或expireat来设置哈希图的过期时间

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM