gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:56:31 25 4
gpt4 key购买 nike

我使用 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 命令中确实有效。

In [68]: cache.rds.execute_command("scan", "0", match="userinfo_*") Out[68]: ['28', ['user_dev_20199116', 'devinfo_af85d776fcc9dbc56e3cca16594e1c9ec36fecd10000000001', 'devinfo_dd552211d1b97a825c416aaaf3c62ce8ce4661820000000002', 'user_dev_2', 'userinfo_20130243', 'session_r4XXdvzJ28VuPMoWWU4cnsNv7NEAAAAAAQ==', 'devinfo_35372afae1de3dbf6a213f659c2814c7b1767f2400013436cc', 'session_3IaTKySREBKjMTAi1puQSwzO20wAAAAAAQ==', 'session_3VUiEdG5eoJcQWqq88Ys6M5GYYIAAAAAAg==', 'user_dev_20130243']]

最佳答案

像这样尝试 SCAN 命令:

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

关于python - Redis 扫描命令匹配选项在 Python 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25970315/

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