python - delete multiple fields for a key in Redis -
i have dictionary follows:
dict1 = {"a":"foo","b":"bar","c":"foobar"}
the keys of dict1 fields of key in redis. want use hdel delete fields in redis. wondering if possible send multiple fields @ once redis.
i thought of creating list of keys dict1 , passing redis.hdel doesn't work , returned false. appretiate help/suggestions.
list1 = [] key = "somerediskey" k in dict1: list1.append(k) data = redis_connection.hdel(key, list1)
the python redis lib accept hdel(name, *keys)
, should do:
data = redis_connection.hdel(key, *list1)
also, don't need create list of keys, can use dict1.keys()
:
key = "somerediskey" data = redis_connection.hdel(key, *dict1.keys())
related docs: http://kushal.fedorapeople.org/redis-py/html/api.html#redis.strictredis.hdel
Comments
Post a Comment