Last active
January 11, 2018 16:07
-
-
Save tmpbook/57b2cdf519ca41b70505f51e59ad7736 to your computer and use it in GitHub Desktop.
Delete keys which in a very big file from redis | 从非常大的文件读取 key 然后在 redis 中删除
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import time | |
pool=redis.ConnectionPool(host='redis_hostname', port=6379, db=0) | |
r = redis.StrictRedis(connection_pool=pool) | |
start_time = time.time() | |
SUCCESS_DELETED = 0 | |
with open("/data/rediskeys") as kf: | |
while True: | |
lines = kf.readlines(1024*1024) | |
if not lines: | |
break | |
else: | |
taskkey_list = [i.strip() for i in lines if i.startswith("UCS:TASKKEY")] | |
SUCCESS_DELETED += r.delete(*taskkey_list) | |
print SUCCESS_DELETED | |
end_time = time.time() | |
print end_time - start_time, SUCCESS_DELETED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment