Python遍历数据库并获取key的值

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

import redis
import hiredis

pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
r = redis.Redis(connection_pool=pool)

pipe = r.pipeline()
pipe_size = 100000

len = 0
key_list = []
for key in r.scan_iter(match='PREFIX_*', count=100000):
    key_list.append(key)
    pipe.get(key)
    if len < pipe_size:
        len += 1
    else:
        for (k, v) in zip(key_list, pipe.execute()):
            print k, v
        len = 0
        key_list = []

for (k, v) in zip(key_list, pipe.execute()):
    print k, v