环境
- python3
- Linux
安装redis库
python3 -m pip install redis
脚本
from redis import StrictRedis
if __name__ == "__main__":
try:
conn = StrictRedis(host='localhost', port=6379, password="xxx")
keys = conn.scan_iter()
count = 0
for key in keys:
key = key.decode("utf-8")
if "server-name-xxx:key-desc" in key:
print(key)
print(conn.delete(key))
count += 1
print(count)
except Exception as e:
print(e)