简体   繁体   English

不明白为什么打印不显示hmget的结果

[英]Don't understand why print does not display results of hmget

I don't understand why a print does not display results of hmget in redis using python 我不明白为什么打印不能使用python在redis显示hmget结果

You name it, I've tried it. 你说它,我试过了。

def newcode(R=r):
    cnt = 1
    for cnt in range(0,10):
        rec=R.hmget('rec-'+str(cnt), 'key' , 'txt')
        print(rec)
    cnt += 1

Here is what is returned: 这是返回的内容:

Pipeline<ConnectionPool<Connection<host=127.0.0.1,port=6379,db=0>>>

I expected something like: 1 "This is the text" which would display the key and text values stored in the hash. 我期望类似: 1 "This is the text" ,它将显示存储在哈希中的键和文本值。

i copy your method and i prove it and work fine 我复制你的方法,我证明它并且工作正常

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)

and the output was : 输出是:

[b'25', b'football']
[b'22', b'basquetball']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM