Redis连接池中的字符集有问题(希望使用字符串,而不是字节)。你知道吗
如果我像这样连接到Redis:
r = redis.StrictRedis(host="localhost", port=6379, charset="utf-8", decode_responses=True)
r.set('foo', ['eggs', 'spam'])
r.set('awa', 'ororor')
print(r)
print(r['foo'])
print(r['awa'])
一切正常:
StrictRedis<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>
['eggs', 'spam']
ororor
但是,如果我尝试使用ConnectionPool:
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.StrictRedis(connection_pool=pool, charset="utf-8", decode_responses=True)
r.set('foo', ['eggs', 'spam'])
r.set('awa', 'ororor')
print(r)
print(r['foo'])
print(r['awa'])
我得到字节:
StrictRedis<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>
b"['eggs', 'spam']"
b'ororor'
我做错什么了?你知道吗
也许。。 池=redis.ConnectionPool(host='localhost',port=6379,db=0,decode\u responses=True) r=雷迪斯。雷迪斯(connection_pool=pool,charset=“utf-8”)
相关问题 更多 >
编程相关推荐