Python3 redis returns bytes (bytes) instead of strings (string)

created at 07-15-2021 views: 20


Recently, my project was updated to python3, and the redis version was also updated to 3.4.1. Using redis keys, smemers and other commands, I found that the returned data is all bytes.


Use StrictRedis directly

conn = StrictRedis(host='localhost', port=6379, db=0,decode_responses=True)

If you use the pool to connect, you need to set it on the ConnectionPool, otherwise the returned data is still byte data

pool = redis.ConnectionPool(host='localhost',port=6379, password=REDIS_PWD, decode_responses=True)
created at:07-15-2021
edited at: 07-15-2021: