简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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