我不明白为什么打印不使用python在hmget
中显示redis
的结果
您命名,我已经尝试过。
def newcode(R=r):
cnt = 1
for cnt in range(0,10):
rec=R.hmget('rec-'+str(cnt), 'key' , 'txt')
print(rec)
cnt += 1
这是返回的内容:
Pipeline<ConnectionPool<Connection<host=127.0.0.1,port=6379,db=0>>>
我期望像1 "This is the text"
这样的内容,它将显示存储在哈希中的键和文本值。
答案 0 :(得分:0)
我复制了您的方法,并证明了它的工作原理
import redis
import json
def newcode(R):
for cnt in range(0, 2):
rec = R.hmget('rec-' + str(cnt), 'key', 'txt')
print(rec)
conn = redis.Redis('localhost')
user = {'name': 'username','key': 25,'txt': 'football','response': 5}
meat = {'name': 'username','key': 22,'txt': 'basquetball','response': 5}
conn.hmset("rec-0", user)
conn.hmset("rec-1", meat)
newcode(conn)
,输出为:
[b'25', b'football']
[b'22', b'basquetball']