新增查看redis内容接口
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user