From 3a7df26fa336e40d9a56b0f6bc2dbdc3414186ef Mon Sep 17 00:00:00 2001 From: kimgn Date: Thu, 7 May 2020 10:24:41 +0900 Subject: [PATCH 1/5] for rediscluster 3.5.0 StrictRedisCluster is renamed --- flask_cache_redis_cluster/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flask_cache_redis_cluster/__init__.py b/flask_cache_redis_cluster/__init__.py index d2797ac..27bc99e 100644 --- a/flask_cache_redis_cluster/__init__.py +++ b/flask_cache_redis_cluster/__init__.py @@ -43,13 +43,13 @@ def __init__(self, host='localhost', port=6379, password=None, 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, + self._client = RedisCluster(host=host, port=port, password=password, **kwargs) From 25ea68a4e40084898945e6843df4c22e9788c991 Mon Sep 17 00:00:00 2001 From: daedamee <61485613+daedamee@users.noreply.github.com> Date: Thu, 7 May 2020 10:49:46 +0900 Subject: [PATCH 2/5] Update __init__.py modify comment. rediscluster's StrictRedisCluster is modified. Now it is RedisCluster --- flask_cache_redis_cluster/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flask_cache_redis_cluster/__init__.py b/flask_cache_redis_cluster/__init__.py index 27bc99e..a38c083 100644 --- a/flask_cache_redis_cluster/__init__.py +++ b/flask_cache_redis_cluster/__init__.py @@ -31,11 +31,11 @@ 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, From 8edfedb07c44cd32d23a2afd1f5948a2797f7225 Mon Sep 17 00:00:00 2001 From: kimgn Date: Thu, 7 May 2020 21:39:30 +0900 Subject: [PATCH 3/5] 20200507: usage changed : cluster list cache on --- flask_cache_redis_cluster/__init__.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/flask_cache_redis_cluster/__init__.py b/flask_cache_redis_cluster/__init__.py index 27bc99e..91024ad 100644 --- a/flask_cache_redis_cluster/__init__.py +++ b/flask_cache_redis_cluster/__init__.py @@ -11,13 +11,8 @@ 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 @@ -39,7 +34,7 @@ class RedisClusterCache(RedisCache): """ def __init__(self, host='localhost', port=6379, password=None, - default_timeout=300, key_prefix=None, **kwargs): + 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: @@ -49,9 +44,7 @@ def __init__(self, host='localhost', port=6379, password=None, if kwargs.get('decode_responses', None): raise ValueError('decode_responses is not supported by ' 'RedisClusterCache.') - self._client = RedisCluster(host=host, - port=port, - password=password, + self._client = RedisCluster(startup_nodes=startup_nodes, **kwargs) else: self._client = host From 13b295f1055078eb6431235cbe26bf60798ec24b Mon Sep 17 00:00:00 2001 From: kimgn Date: Thu, 7 May 2020 21:42:18 +0900 Subject: [PATCH 4/5] 20200507 : usage example added --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index befd122..975d663 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,7 @@ app = Flask(__name__) class Config(object): CACHE_TYPE = 'flask_cache_redis_cluster.rediscluster' - CACHE_REDIS_HOST = 'redis' - CACHE_REDIS_PORT = 6379 + CACHE_REDIS_NODES = [{"host": "127.0.0.1", "port": "6379"},{"host": "127.0.0.1", "port": "6380"},{"host": "127.0.0.1", "port": "6381"},{"host": "127.0.0.1", "port": "6382"},{"host": "127.0.0.1", "port": "6383"},{"host": "127.0.0.1", "port": "6384"},] CACHE_KEY_PREFIX = '' # ... other options From fc97b078458b41936c319a4c75b893ff5b10a0f4 Mon Sep 17 00:00:00 2001 From: daedamee <61485613+daedamee@users.noreply.github.com> Date: Wed, 17 Jun 2020 18:06:24 +0900 Subject: [PATCH 5/5] Update __init__.py --- flask_cache_redis_cluster/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flask_cache_redis_cluster/__init__.py b/flask_cache_redis_cluster/__init__.py index f26d015..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, @@ -16,7 +15,10 @@ def rediscluster(app, config, args, kwargs): 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) @@ -28,12 +30,11 @@ class RedisClusterCache(RedisCache): server or an object resembling an instance of a ``rediscluster.RedisCluster`` class. Note: Python Redis API already takes care of encoding unicode strings on - Any additional keyword arguments will be passed to ``rediscluster.RedisCluster``. """ - def __init__(self, host='localhost', port=6379, password=None, + 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):