python连接redis集群

记录下
用的是redis-py-cluster 2.1.3版本

from rediscluster import RedisCluster, ClusterConnectionPool

from common.log import logger
 def del_redis_key(host,port, password, pattern):
        nodes = [{"host": host, "port":port}]
        pool = ClusterConnectionPool(startup_nodes=nodes, password=password)
        client = RedisCluster(connection_pool=pool)
        key_list = client.keys(pattern=pattern)
        if len(key_list):
            # 批量删除所有缓存的应用key
            for i in key_list:
                client.delete(i)
                logger.info("clear success...")
        else:
            logger.warn("with no data need to delete...")

你可能感兴趣的:(redis,数据库,缓存,python)