python|python 提取redis中所有的keys 和数据

  1. # -*- encoding: UTF-8 -*-
  2. __author__ = "Sky"
  3. import redis
  4. pool=redis.ConnectionPool(host='127.0.0.1',port=6379,db=0)
  5. r = redis.StrictRedis(connection_pool=pool)
  6. keys = r.keys()
  7. print type(keys)
  8. print keys

  1. # -*- encoding: UTF-8 -*-
  2. __author__ = "Sky"
  3. import redis
  4. pool=redis.ConnectionPool(host='127.0.0.1',port=6379,db=0)
  5. r = redis.StrictRedis(connection_pool=pool)
  6. keys = r.keys()
  7. print type(keys)
  8. print keys

【python|python 提取redis中所有的keys 和数据】 运行结果:

['fad', '1', '2']

二、获取所有内容

[python] view plain copy

  1. import redis
  2. pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
  3. r = redis.Redis(connection_pool=pool)
  4. pipe = r.pipeline()
  5. pipe_size = 100000
  6. len = 0
  7. key_list = []
  8. print r.pipeline()
  9. keys = r.keys()
  10. for key in keys:
  11. key_list.append(key)
  12. pipe.get(key)
  13. if len < pipe_size:
  14. len += 1
  15. else:
  16. for (k, v) in zip(key_list, pipe.execute()):
  17. print k, v
  18. len = 0
  19. key_list = []
  20. for (k, v) in zip(key_list, pipe.execute()):
  21. print k, v

  1. import redis
  2. pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
  3. r = redis.Redis(connection_pool=pool)
  4. pipe = r.pipeline()
  5. pipe_size = 100000
  6. len = 0
  7. key_list = []
  8. print r.pipeline()
  9. keys = r.keys()
  10. for key in keys:
  11. key_list.append(key)
  12. pipe.get(key)
  13. if len < pipe_size:
  14. len += 1
  15. else:
  16. for (k, v) in zip(key_list, pipe.execute()):
  17. print k, v
  18. len = 0
  19. key_list = []
  20. for (k, v) in zip(key_list, pipe.execute()):
  21. print k, v

    推荐阅读