在python3中,关于redis读取数据带有‘b’的问题

在python3中,关于redis读取数据带有‘b’的问题

#encoding=utf-8
from redis import *

#读取数据
d1=input(“您输入的数据是:”)

#连接
r=StrictRedis(host=’localhost’,port=6379)

#写
# pipe=r.pipeline()
# pipe.set(‘r1′,’hello’)
# pipe.set(‘r2′,’world’)
# pipe.execute()

#读
#在python3的前面,有一个’b’代表的是bytes
#用以下方式解决

#注意,有值则进行编码
#法1:
# temp=r.get(‘r1’).decode()
# print(temp)

#法2:
# temp=r.get(‘r2’)
# h1=str(temp,encoding=’utf-8′)
# print(h1)

#如果没有值,则为None
s=r.get(d1)
print(s)
if s==None:
    print(‘yes’)
else:
    print(‘no’)
    temp=s.decode()
    print(temp)
原文:https://blog.csdn.net/mr_muli/article/details/78573156 

    原文作者: 汉诺塔问题
    原文地址: https://blog.csdn.net/bang152101/article/details/88603393
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞