Python遍历数据库并获取key的值,python历数据库key,import redis


import redisimport hiredispool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)r = redis.Redis(connection_pool=pool)pipe = r.pipeline()pipe_size = 100000len = 0key_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

评论关闭