One - One Code All

Blog Content

python3读取redis返回数据带有b的问题

Python Nosql   2018-05-20 17:53:12

通过python读取 redis 的值发现返回的值带有字母 b


解决方法

redis中我们存进去的是字符串类型的数据,取出来却是字节类型的。

这是由于python3的与redis交互的驱动的问题.


解决方法:

1. 对取出来的内容decode一下: var.decode()

2. 在连接数据库的时候加上decode_responses=True:redis(host=‘localhost’, port=6379, db=0,decode_responses=True)



上一篇:mac安装pycurl报错Curl is configured to use SSL
下一篇:django自动生成routers路由、自定义action

The minute you think of giving up, think of the reason why you held on so long.