Last active
November 6, 2019 10:55
-
-
Save AndyHoang/954942e4603c85bc3e18878c0bcbdd7c to your computer and use it in GitHub Desktop.
cacheops redis cluster https://github.com/Suor/django-cacheops/files/3813975/compat_cacheops.zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CacheopsRedisCluster(StrictRedisCluster, CacheopsRedis): | |
get = handle_connection_failure(StrictRedisCluster.get) | |
def __init__(self, *args, **kwargs): | |
init_slot_cache = kwargs.get('init_slot_cache', True) | |
super(CacheopsRedisCluster, self).__init__(*args, **kwargs) | |
# lazy initialize nodes, so that if redis is downed before starting django, everything still fine | |
if not init_slot_cache: | |
self.refresh_table_asap = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSTALLED_APPS = [ | |
'compat_cacheops', | |
#..... | |
] | |
CACHEOPS_REDIS = { | |
'startup_nodes': [your nodes], | |
'skip_full_coverage_check': True, | |
#'ssl': REDIS_SSL, | |
# lazy starting redis client | |
'init_slot_cache': False | |
} | |
CACHEOPS_CLIENT_CLASS = 'xxx.custom_redis_client.CacheopsRedisCluster' | |
def prefix(query): | |
# redis_client.connection_pool.nodes.keyslot('{keyed_slot}:') | |
return '{keyed_slot}' | |
CACHEOPS_PREFIX = prefix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment