Skip to content

Instantly share code, notes, and snippets.

@AndyHoang
Last active November 6, 2019 10:55
Show Gist options
  • Save AndyHoang/954942e4603c85bc3e18878c0bcbdd7c to your computer and use it in GitHub Desktop.
Save AndyHoang/954942e4603c85bc3e18878c0bcbdd7c to your computer and use it in GitHub Desktop.
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
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