新增python脚本
This commit is contained in:
75
python/peko_mid_autumn_jackpot_user_record.py
Normal file
75
python/peko_mid_autumn_jackpot_user_record.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# pip3 install redis
|
||||||
|
|
||||||
|
import redis
|
||||||
|
import json
|
||||||
|
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)
|
||||||
|
result = 0
|
||||||
|
cursor = 0
|
||||||
|
while True:
|
||||||
|
tup = res.scan(cursor=cursor, match='ym_mid_autumn_jackpot_user_record', count=1000)
|
||||||
|
#if not isinstance(tup, dict):
|
||||||
|
#print(tup)
|
||||||
|
k = tup[0]
|
||||||
|
v = tup[1]
|
||||||
|
# print("k = " + str(k) + ", v = " + str(v))
|
||||||
|
if isinstance(k, int):
|
||||||
|
cursor = k
|
||||||
|
if isinstance(v, list):
|
||||||
|
# print("list...")
|
||||||
|
# 启动线程执行
|
||||||
|
try:
|
||||||
|
handle_keys(v)
|
||||||
|
except Exception as e:
|
||||||
|
print("thread submit error.", e)
|
||||||
|
# print("cursor = " + str(cursor))
|
||||||
|
if cursor == 0:
|
||||||
|
break
|
||||||
|
# 关闭线程池
|
||||||
|
thread.shutdown()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def handle_keys(keys):
|
||||||
|
try:
|
||||||
|
for k in keys:
|
||||||
|
key = k.decode('utf-8')
|
||||||
|
hash_keys = res.hkeys(key)
|
||||||
|
for f in hash_keys:
|
||||||
|
field = f.decode('utf-8')
|
||||||
|
field_list = json.loads(field)
|
||||||
|
# print("field_list : " + str(field_list))
|
||||||
|
uid = field_list[1]
|
||||||
|
try:
|
||||||
|
if res.hexists(key, field) != 0:
|
||||||
|
m = res.hget(key, field)
|
||||||
|
member = m.decode('utf-8')
|
||||||
|
member_json = json.loads(member)
|
||||||
|
for member_key in member_json:
|
||||||
|
if isinstance(member_json[member_key], list):
|
||||||
|
print(str(uid) + "," + str(member_key) + "," + str(member_json[member_key][1]))
|
||||||
|
# print("field : " + field + ", member : " + member)
|
||||||
|
except Exception as e:
|
||||||
|
print("hget " + key + " " + field + " is error.", e)
|
||||||
|
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.")
|
||||||
|
result = scan()
|
||||||
|
print("result = " + str(result))
|
Reference in New Issue
Block a user