import redis
r = redis.Redis(host='localhost',port=6379,db=0)
r.mset({'name':'Bob','age':20})
values = r.mget(['name','age'])
for value in values:
#Redis中的value是bytes数据,python需要使用decode()转换为str或者int类型
print(value.decode('utf-8'))
r.append('name','Smith')
#写入文件的时候需要转换为str
text = r.get('name').decode('utf-8')
with open('text.txt','w') as f:
f.write(text)
#或者以bytes形式写入
'''
text = r.get('name')
with open('text.txt','wb') as f:
f.write(text)
'''