Commit 16322a92 authored by 张彦钊's avatar 张彦钊

change

parent 11d21648
import redis import redis
def delete_key(): # def delete_key():
# r = redis.StrictRedis.from_url('redis://:ReDis!GmTx*0aN6@172.16.40.133:6379')
# keys = r.keys("TS:recommend_diary_set:device_id:*")
# sum = 0
# print("diary")
# print(len(keys))
# for i in keys:
# if r.ttl(i) == -1:
# sum = sum +1
# r.delete(i)
# if sum % 1000 == 0:
# print(sum)
#
# sum = 0
# keys = r.keys("TS:recommend_tractate_set:device_id:*")
# print("teizi")
# print(len(keys))
# for i in keys:
# if r.ttl(i) == -1:
# r.delete(i)
# sum = sum + 1
# if sum % 1000 == 0:
# print(sum)
#
# sum = 0
# print("qa")
# print(len(keys))
# keys = r.keys("TS:recommend_answer_set:device_id:*")
# for i in keys:
# if r.ttl(i) == -1:
# r.delete(i)
# sum = sum + 1
# if sum % 1000 == 0:
# print(sum)
def scan_key():
r = redis.StrictRedis.from_url('redis://:ReDis!GmTx*0aN6@172.16.40.133:6379') r = redis.StrictRedis.from_url('redis://:ReDis!GmTx*0aN6@172.16.40.133:6379')
keys = r.keys("TS:recommend_diary_set:device_id:*") cursor = 0
sum = 0 while True:
print("diary") new_cursor,keys_list = r.scan(cursor,"TS:recommend_diary_set:device_id:*",2000)
print(len(keys)) delete_keys = []
for i in keys: for i in keys_list:
if r.ttl(i) == -1: if r.ttl(i) == -1:
sum = sum +1 delete_keys.append(i)
r.delete(i) if len(delete_keys) > 0:
if sum % 1000 == 0: r.delete(*delete_keys)
print(sum) print("删除日记数量")
print(len(delete_keys))
sum = 0 # 循环一遍后结束
keys = r.keys("TS:recommend_tractate_set:device_id:*") if new_cursor == 0:
print("teizi") break
print(len(keys)) cursor = new_cursor
for i in keys:
if r.ttl(i) == -1:
r.delete(i)
sum = sum + 1
if sum % 1000 == 0:
print(sum)
sum = 0
print("qa")
print(len(keys))
keys = r.keys("TS:recommend_answer_set:device_id:*")
for i in keys:
if r.ttl(i) == -1:
r.delete(i)
sum = sum + 1
if sum % 1000 == 0:
print(sum)
if __name__ == "__main__": if __name__ == "__main__":
delete_key() scan_key()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment