Python获取Redis所有Key以及内容的方法
时间:2020-11-16 12:05:38|栏目:Python代码|点击: 次
一、获取所有Key
# -*- encoding: UTF-8 -*- __author__ = "Sky" import redis pool=redis.ConnectionPool(host='127.0.0.1',port=6379,db=0) r = redis.StrictRedis(connection_pool=pool) keys = r.keys() print type(keys) print keys
运行结果:
<type 'list'> ['fad', '1', '2']
二、获取所有内容
import redis 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 = [] print r.pipeline() keys = r.keys() for key in keys: 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
运行结果:
fad fda 1 e 2 f
上一篇:python bottle框架支持jquery ajax的RESTful风格的PUT和DELETE方法
栏 目:Python代码
本文标题:Python获取Redis所有Key以及内容的方法
本文地址:http://www.codeinn.net/misctech/23183.html