小编典典

Redis扫描命令匹配选项在Python中不起作用

redis

我使用python redis通过使用match选项来匹配某些信息吗?但这不起作用。

 import redis
 import REDIS

 class UserCache(object):
    def __init__(self):
       self.rds = self._connectRds()

    def _connectRds(self):
        _db = REDIS['usercache']
        pool = redis.ConnectionPool(host=_db['HOST'], port= _db['PORT'], db=_db['DB'])
        rds = redis.Redis(connection_pool=pool) 
        return rds

 cache = UserCahce()
 cache.rds.execute("scan", "0", match="userinfo_*")

似乎match选项在scan命令中确实起作用。

在[68]中:cache.rds.execute_command(“ scan”,“ 0”,match =“ userinfo_ *”)Out
[68]:[‘28’,[‘user_dev_20199116’,’devinfo_af85d776fcc9dbc56e3cca16594e1c9ec36fecd10000000001’,’devinfo_dd552211ce86ce
user_dev_2’ , ‘userinfo_20130243’,
‘session_r4XXdvzJ28VuPMoWWU4cnsNv7NEAAAAAAQ ==’,
‘devinfo_35372afae1de3dbf6a213f659c2814c7b1767f2400013436cc’,
‘session_3IaTKySREBKjMTAi1puQSwzO20wAAAAAAQ ==’,
‘session_3VUiEdG5eoJcQWqq88Ys6M5GYYIAAAAAAg ==’, ‘user_dev_20130243’]]


阅读 361

收藏
2020-06-20

共1个答案

小编典典

尝试这样的SCAN命令:

r = Redis(....) #redis url
for user in r.scan_iter(match='userinfo_*'):
  print(user)
2020-06-20