gpt4 book ai didi

python - 不明白为什么print不显示hmget的结果

转载 作者:可可西里 更新时间:2023-11-01 11:23:29 26 4
gpt4 key购买 nike

我不明白为什么 print 不显示 redis 使用 python 的 hmget 结果

你说出来,我试过了。

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" 它将显示存储在散列中的键和文本值。

最佳答案

我复制了你的方法,我证明了它并且工作正常

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']

关于python - 不明白为什么print不显示hmget的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56350573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com