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

来源:互联网 发布:智能算法优化 编辑:程序博客网 时间:2024/06/07 18:36

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

#encoding=utf-8from 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)#如果没有值,则为Nones=r.get(d1)print(s)if s==None:    print('yes')else:    print('no')    temp=s.decode()    print(temp)
阅读全文
0 0