python 3.x - redis-py and hgetall behavior -
i played around flask microframework, , wanted cache stats in redis. let's have dict:
mydict = {} mydict["test"] = "test11" i saved redis with
redis.hmset("test:key", mydict) however after restore
stored = redis.hgetall("test:key") print(str(stored)) i see weird {b'test': b'test11'} stored.get("test") gives me none
mydict str method result looks fine {'test': 'test11'}. so, why binary marker added restored data? checked in redis-cli , don't see explicit b markers there. wrong hgetall?
this intended behavior. default, strings coming out of redis don't decoded. have couple options:
- decode data yourself.
- create client instance
decode_responsesargument, e.g.,strictredis(decode_responses=true). decode strings come redis based oncharsetargument (which defaults utf-8). you're sure every response redis has string data want decoded utf-8. if you're using same client instance binary data such pickled object, shouldn't use option. in case, i'd suggest using separate client instance binary data.
source: https://github.com/andymccurdy/redis-py/issues/463#issuecomment-41229918
Comments
Post a Comment