Python连接redis

Posted Hank

tags:

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

import redis
 
pool = redis.ConnectionPool(host='localhost', port=6379,encoding="UTF-8",decode_responses=True)
r = redis.Redis(connection_pool=pool)
result = r.keys("*")

#遍历所有元素
for res in result:
    print(res)

#查看长度
print(len(result)) 

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