本文为博主原创,未经授权,严禁转载及使用。
本文链接:https://blog.csdn.net/zyooooxie/article/details/112484045
之前写过一篇 使用redis-py来操作redis集群, https://blog.csdn.net/zyooooxie/article/details/123760358 ,这期来分享下 使用redis-py-cluster;
【实际这篇博客推迟发布N个月】
个人博客:https://blog.csdn.net/zyooooxie
【以下所有内容仅为个人项目经历,如有不同,纯属正常】
redis-py-cluster
https://pypi.org/project/redis-py-cluster/
This major version of redis-py-cluster supports redis-py >=3.0.0, <4.0.0.
代码
"""
@blog: https://blog.csdn.net/zyooooxie
@qq: 153132336
@email: zyooooxie@gmail.com
"""
import traceback
from rediscluster import ClusterConnectionPool
from rediscluster import RedisCluster
from xxx_test.user_log import Log
host2 = ''
p1wd = ''
port = 1234
gl_key_name = 'TEST_xie*'
Log.info('------')
gl_real_string = ''
gl_real_hash = ''
gl_real_list = ''
gl_real_set = ''
gl_no_exist = 'TEST_zyooooxie'
gl_test_str = 'test_str'
gl_test_hash = 'test_hash'
gl_test_list = 'test_list'
gl_test_set = 'test_set'
Log.info('------')
# pip install redis-py-cluster==2.1.3
# https://redis-py-cluster.readthedocs.io/en/2.1.3/index.html
def redis_py_cluster_connect_1():
rc = RedisCluster(startup_nodes=[{
'host': host2, 'port': port}],
decode_responses=True, password=pwd)
Log.info('{}'.format(rc))
Log.info(type(rc))
Log.error('已连接')
return rc
def redis_py_cluster_connect_2():
ccp = ClusterConnectionPool(startup_nodes=[{
'host': host2, 'port': port}],
decode_responses=True, password=pwd)
rc = RedisCluster(connection_pool=ccp)
Log.info('{}'.format(rc))
Log.info(type(rc))
Log.error('已连接')
return rc
def redis_py_cluster_connect_3():
rc = RedisCluster(host=host2, port=port,
decode_responses=True, password=pwd)
Log.info('{}'.format(rc))
Log.info(type(rc))
Log.error('已连接')
return rc
"""
@blog: https://blog.csdn.net/zyooooxie
@qq: 153132336
@email: zyooooxie@gmail.com
"""
def cluster_commands(rc: RedisCluster):
Log.info(rc.cluster_info())
Log.info(rc.cluster_slots(