python3 redis 返回字节(bytes)而不是字符串(string)

前端之家收集整理的这篇文章主要介绍了python3 redis 返回字节(bytes)而不是字符串(string)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近项目更新到python3,redis版本也更新到3.4.1,使用redis的keys,smemers等命令,发现返回的数据都是字节(bytes)。

解决方法

直接使用StrictRedis

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

如果使用池进行连接,则需要在ConnectionPool上进行设置,否则返回的数据还是字节数据

pool = redis.ConnectionPool(host='localhost',port=6379, password=REDIS_PWD, decode_responses=True)


猜你在找的Redis相关文章