Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<your prefix>'
# ... other options

Expand Down
28 changes: 11 additions & 17 deletions flask_cache_redis_cluster/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 11 17:27:53 2017

@author: richard
"""
from werkzeug.contrib.cache import (BaseCache,
Expand All @@ -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)


Expand All @@ -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
Expand Down