Redis python中HashMap的过期时间?

Redis python中HashMap的过期时间?,python,database,python-2.7,redis,hashmap,Python,Database,Python 2.7,Redis,Hashmap,我想在redis中存储以下哈希映射: "data": { "name": "XYZ", "age": 22, "address": "a-z" } 我希望整个散列映射(使用给定的密钥)能够及时过期,比如说72小时 如何在python中使用ttl/expire函数?以下是如何使用的: redis_client.expire(your_key, time_in_seconds) 请参阅。假设您只想存储这些值,而不想存储文章中显示的顶级字典,那么您可以

我想在redis中存储以下哈希映射:

"data": {
       "name": "XYZ",
       "age": 22,
       "address": "a-z"
}  
我希望整个散列映射(使用给定的密钥)能够及时过期,比如说72小时

如何在python中使用
ttl/expire
函数?

以下是如何使用的:

redis_client.expire(your_key, time_in_seconds)

请参阅。

假设您只想存储这些值,而不想存储文章中显示的顶级字典,那么您可以使用它来设置ttl或在hashmap上设置过期时间

谢谢

下面是我想做的,我想这是对的:

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)

你有密码吗?