Skip to content

Commit 7fee4da

Browse files
author
opapy
committed
add ignore_cluster_errors params
1 parent e986e4a commit 7fee4da

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Your cache backend should look something like this::
5252
'OPTIONS': {
5353
'cluster_timeout': 1, # its used when get cluster info
5454
'ignore_exc': True, # pymemcache Client params
55+
'ignore_cluster_errors': True, # ignore get cluster info error
5556
}
5657
}
5758
}

django_elastipymemcache/cluster_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, cmd, response):
1919
'Unexpected response {} for command {}'.format(response, cmd))
2020

2121

22-
def get_cluster_info(host, port, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
22+
def get_cluster_info(host, port, ignore_cluster_errors=False, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
2323
"""
2424
return dict with info about nodes in cluster and current version
2525
{
@@ -48,6 +48,14 @@ def get_cluster_info(host, port, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
4848
])
4949
client.close()
5050

51+
if res == b'ERROR\r\n' and ignore_cluster_errors:
52+
return {
53+
'version': version,
54+
'nodes': [
55+
(smart_text(host), int(port))
56+
]
57+
}
58+
5159
ls = list(filter(None, re.compile(br'\r?\n').split(res)))
5260
if len(ls) != 4:
5361
raise WrongProtocolData(cmd, res)

django_elastipymemcache/memcached.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def __init__(self, server, params):
7070
self._options = self._options or dict()
7171
self._cluster_timeout = self._options.get(
7272
'cluster_timeout', socket._GLOBAL_DEFAULT_TIMEOUT)
73+
self._ignore_cluster_errors = self._options.get(
74+
'ignore_cluster_errors', False)
7375

7476
def clear_cluster_nodes_cache(self):
7577
"""clear internal cache with list of nodes in cluster"""
@@ -85,6 +87,7 @@ def get_cluster_nodes(self):
8587
return get_cluster_info(
8688
server,
8789
port,
90+
self._ignore_cluster_errors,
8891
self._cluster_timeout
8992
)['nodes']
9093
except (OSError, socket.gaierror, socket.timeout) as err:
@@ -105,6 +108,7 @@ def _cache(self):
105108
options['deserializer'] = deserialize_pickle
106109
options.setdefault('ignore_exc', True)
107110
options.pop('cluster_timeout', None)
111+
options.pop('ignore_cluster_errors', None)
108112

109113
self._client = self._lib.Client(
110114
self.get_cluster_nodes(), **options)

0 commit comments

Comments
 (0)