Files
peko-java/python/peko_seize_treasure_user_info.py
liaozetao 003a77e026 补充
2023-10-18 11:13:11 +08:00

53 lines
1.2 KiB
Python

# pip3 install redis
import redis
from concurrent.futures import ThreadPoolExecutor
res = None
def connect():
res = redis.StrictRedis(host='172.22.0.8', port=6379, db=0, password='pc8DphhaXwTe2jyv')
return res
def scan():
# 创建一个包含100条线程的线程池
thread = ThreadPoolExecutor(max_workers=100)
cursor = 0
while True:
tup = res.scan(cursor=cursor, match='peko:seize_treasure:user_info:*', count=1000)
k = tup[0]
v = tup[1]
if isinstance(k, int):
cursor = k
if isinstance(v, list):
# 启动线程执行
try:
handle_keys(v)
except Exception as e:
print("thread submit error.", e)
if cursor == 0:
break
# 关闭线程池
thread.shutdown()
def handle_keys(keys):
try:
for k in keys:
key = k.decode('utf-8')
print(key)
# res.delete(key)
except Exception as e:
print("handle_keys error.", e)
if __name__ == '__main__':
res = connect()
if res is None:
print("redis connect is error.")
else:
print("redis connect is success.")
scan()