python redis del keys

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python redis del keys相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import redis

pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
rds = redis.Redis(connection_pool=pool)
pipe = rds.pipeline(transaction=False)

f = open('del_keys.txt', 'w')
for key in rds.scan_iter(match='name*', count=10000):
    # do something with keys
    f.write(key + '\n')


start_time = time.time()
SUCCESS_DELETED = 0

with open('del_keys.txt') as kf:
    while True:
        lines = kf.readlines(1024 * 1024)
        if not lines:
            break
        else:
            taskkey_list = [i.strip() for i in lines]
            SUCCESS_DELETED += rds.delete(*taskkey_list)
        print SUCCESS_DELETED
end_time = time.time()
print end_time - start_time, SUCCESS_DELETED

以上是关于python redis del keys的主要内容,如果未能解决你的问题,请参考以下文章

redis------del命令

Redis中设置过期实践key

Redis中设置过期实践key

php redis 怎么删除hash,而不是只删除了单个或多个域

redis --------- 使用命令(每天一个)

在Redis中设置了过期时间的Key,需要注意哪些问题?