How to store and retrieve a dictionary with redis

前端 未结 11 1301
遇见更好的自我
遇见更好的自我 2020-12-07 10:20
# I have the dictionary my_dict
my_dict = {
    \'var1\' : 5
    \'var2\' : 9
}
r = redis.StrictRedis()

How would I store my_dict and retrieve it w

11条回答
  •  半阙折子戏
    2020-12-07 10:47

    HMSET is deprecated. You can now use HSET with a dictionary as follows:

    import redis
    r = redis.Redis('localhost')
    
    key = "hashexample" 
    queue_entry = { 
        "version":"1.2.3", 
        "tag":"main", 
        "status":"CREATED",  
        "timeout":"30"
        }
    r.hset(key,None,None,queue_entry)
    

提交回复
热议问题