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'

我做错什么了?

最佳答案

Maybe…
Pool=redis.connectionpool(host=“localhost”,Port=6379,DB=0,decode=-responses=true)
R=REDIS.STRICTREDIS(Connection+UU Pool=POOL,charset=“UTF-8”)

关于python - 如何将charset应用于Redis ConnectionPool?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52830492/

10-14 03:18