python redis集群操作 redis集群删除查找 简单使用

1. 首先安装啊

pip install redis-py-cluster

2. 开始使用集群操作咯

RedisConf.nodelist = [{'host':'10.2**.1**.**', 'port':'6379'}, {'host':'10.**5.*2.**2', 'port':'6379'}]

from redisclusterimport RedisCluster

# redis集群操作

class SxRedis:

"""

    使用举例:    print(f"检查返回值:{SxRedis().connect().get('IM:ACCOUNT:RED_PAPER_ORDER:594233041325531137:red_13b8242875966000')}")

"""

    def __init__(self):

self.conn_list = RedisConf.nodelist# 连接列表

        self.sxredis =self.connect()

def connect(self):

"""

        连接redis集群

        :return: object

"""

        try:

# 使用密码连接redis集群

            redisconn = RedisCluster(startup_nodes=self.conn_list, decode_responses=True, password='sdjsx')

return redisconn

except Exception as e:

print("错误,连接redis 集群失败")

raise e

# 来看看使用举例

if __name__ =='__main__':

pass

    print(f"检查返回值:{SxRedis().connect().get('ipush_invalid_token_619699241471844353')}")

# print(f"检查返回值:{SxRedis().connect()..hgetall('IM:ACCOUNT:RED_PAPER_ORDER:530868770131025921')}")

    # print(f"检查返回值:{SxRedis().connect().delete('ipush_invalid_token_619699241471844353')}")


『『需自动化项目源码\交流学习添加v:ct-xiaozhou

免费提供的。行业变迁,多个好友多点可能性。非机构』』

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容