新增查看redis内容接口
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped

This commit is contained in:
litianxiang
2026-01-12 11:51:37 +08:00
parent 19346c2eb7
commit df99e3ac76
2 changed files with 67 additions and 0 deletions

View File

@@ -91,6 +91,21 @@ class Redis(object):
r = cls._get_r()
r.expire(name, expire_in_seconds)
@classmethod
def scan_keys(cls, pattern="*"):
"""
扫描匹配模式的key
"""
r = cls._get_r()
keys = []
cursor = 0
while True:
cursor, partial_keys = r.scan(cursor, match=pattern, count=1000)
keys.extend(partial_keys)
if cursor == 0:
break
return [key.decode('utf-8') if isinstance(key, bytes) else key for key in keys]
if __name__ == '__main__':
redis_client = Redis()