Redis scan command match option does not work in Python

前端 未结 2 1543
太阳男子
太阳男子 2021-01-04 18:20

I use python redis to match some infomation by using match option? but it doesn\'t work.

 import redis
 import REDIS

 class UserCache(object):
    def __ini         


        
相关标签:
2条回答
  • 2021-01-04 18:58

    hscan seems much quicker than scan, better use hscan, only if you are sure about the key, if you need to search all keys then use scan

    for name in r.hscan_iter('live_AP_460000','name'):
       print(name) #for a single child key
    
    for hash in r.hscan_iter('live_AP_460000'):
       print(hash) #for all child keys
    

    hscan is quicker than scan, only if you are searching for a correct key, else to fetch all keys with some similar pattern, go for scan. For reference. How to search a key pattern in redis hash?

    0 讨论(0)
  • 2021-01-04 19:02

    Try the SCAN command like this :

    r = Redis(....) #redis url
    for user in r.scan_iter(match='userinfo_*'):
      print(user)
    
    0 讨论(0)
提交回复
热议问题