-
-
Save wolkym/4f458c1f54d6b3dd2a3b2374da275346 to your computer and use it in GitHub Desktop.
Save Python dict to Redis hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dict_to_redis_hset(r, hkey, dict_to_store): | |
""" | |
Saves `dict_to_store` dict into Redis hash, where `hkey` is key of hash. | |
>>> import redis | |
>>> r = redis.StrictRedis(host='localhost') | |
>>> d = {'a':1, 'b':7, 'foo':'bar'} | |
>>> dict_to_redis_hset(r, 'test', d) | |
True | |
>>> r.hgetall('test') | |
{'a':1, 'b':7, 'foo':'bar'} | |
""" | |
return all([r.hset(hkey, k, v) for k, v in dict_to_store.items()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment