python 查询redis

Posted monkeybron

tags:

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

# encoding: utf-8
import redis
import random
import string
import time
#use scan_iter count redis key
#support key prefix 
#

pool = redis.ConnectionPool(host=‘192.168.50.203‘, port=7001,password=‘A95clrfGuwu‘, db=0)
r = redis.Redis(connection_pool=pool)

def select_redis_key():
    start_time = time.time()
    prefix_key = "AGENT_MEMBER_MSG_UNREAD_"
    result_length = 0
    for key in r.scan_iter(match=‘AGENT_MEMBER_MSG_UNREAD_*‘, count=100):
        result_length += 1
        #print result_length,‘ is ‘,key
    print "normal ways spend time(s) is :", time.time() - start_time
    print "normal way seelect the keys with prefix" ,prefix_key, "count(*) is :", result_length


def main():
    select_redis_key()


if __name__ == ‘__main__‘:
    main()

  

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

Python操作redis

python中使用redis

python 的 redis 库,连接池怎么用

redis python scan_iter 给出不同的键

redis 基本操作-python 使用redis-手机验证接口-发送短信接口

服务器环境配置