From 1482a63b4795f38697a61eb8daf578c16eca052a Mon Sep 17 00:00:00 2001 From: daedamee <61485613+daedamee@users.noreply.github.com> Date: Wed, 17 Jun 2020 18:05:13 +0900 Subject: [PATCH] Update __init__.py --- flask_cache_redis_cluster/__init__.py | 28 +++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/flask_cache_redis_cluster/__init__.py b/flask_cache_redis_cluster/__init__.py index d2797ac..ff55ee6 100644 --- a/flask_cache_redis_cluster/__init__.py +++ b/flask_cache_redis_cluster/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- """ Created on Wed Jan 11 17:27:53 2017 - @author: richard """ from werkzeug.contrib.cache import (BaseCache, @@ -11,17 +10,15 @@ def rediscluster(app, config, args, kwargs): kwargs.update(dict( - host=config.get('CACHE_REDIS_HOST', 'localhost'), - port=config.get('CACHE_REDIS_PORT', 6379), + startup_nodes=config.get('CACHE_REDIS_NODES', [{"host": "127.0.0.1", "port": "6379"}]), )) - password = config.get('CACHE_REDIS_PASSWORD') - if password: - kwargs['password'] = password - key_prefix = config.get('CACHE_KEY_PREFIX') if key_prefix: kwargs['key_prefix'] = key_prefix - + password = config.get('PASSWORD') + if password: + kwargs['password'] = password + print(kwargs, args) return RedisClusterCache(*args, **kwargs) @@ -31,27 +28,24 @@ class RedisClusterCache(RedisCache): """Uses the Redis key-value store as a cache backend. The first argument can be either a string denoting address of the Redis server or an object resembling an instance of a - ``rediscluster.StrictRedisCluster`` class. + ``rediscluster.RedisCluster`` class. Note: Python Redis API already takes care of encoding unicode strings on - Any additional keyword arguments will be passed to - ``rediscluster.StrictRedisCluster``. + ``rediscluster.RedisCluster``. """ - def __init__(self, host='localhost', port=6379, password=None, - default_timeout=300, key_prefix=None, **kwargs): + def __init__(self, host='localhost', port=6379, + default_timeout=300, key_prefix=None,startup_nodes=[{"host": "127.0.0.1", "port": "6379"}], **kwargs): BaseCache.__init__(self, default_timeout) if isinstance(host, string_types): try: - from rediscluster import StrictRedisCluster + from rediscluster import RedisCluster except ImportError: raise RuntimeError('no redis cluster module found') if kwargs.get('decode_responses', None): raise ValueError('decode_responses is not supported by ' 'RedisClusterCache.') - self._client = StrictRedisCluster(host=host, - port=port, - password=password, + self._client = RedisCluster(startup_nodes=startup_nodes, **kwargs) else: self._client = host