Skip to content

Commit e095476

Browse files
opapyopapy
authored andcommitted
add timeout params
1 parent 7db72bd commit e095476

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

django_elastipymemcache/cluster_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, cmd, response):
1818
'Unexpected response {} for command {}'.format(response, cmd))
1919

2020

21-
def get_cluster_info(host, port):
21+
def get_cluster_info(host, port, timeout=None):
2222
"""
2323
return dict with info about nodes in cluster and current version
2424
{
@@ -29,7 +29,7 @@ def get_cluster_info(host, port):
2929
'version': '1.4.4'
3030
}
3131
"""
32-
client = Telnet(host, int(port))
32+
client = Telnet(host, int(port), timeout=None)
3333
client.write(b'version\n')
3434
res = client.read_until(b'\r\n').strip()
3535
version_list = res.split(b' ')

django_elastipymemcache/memcached.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def __init__(self, server, params):
5050

5151
# Patch for django<1.11
5252
self._options = self._options or dict()
53+
self._cluster_timeout = self._options.get('cluster_timeout')
5354

5455
def clear_cluster_nodes_cache(self):
5556
"""clear internal cache with list of nodes in cluster"""
@@ -64,7 +65,8 @@ def get_cluster_nodes(self):
6465
try:
6566
return get_cluster_info(
6667
server,
67-
port
68+
port,
69+
self._cluster_timeout
6870
)['nodes']
6971
except (OSError, socket.gaierror, socket.timeout) as err:
7072
logger.debug(
@@ -76,9 +78,16 @@ def get_cluster_nodes(self):
7678

7779
@property
7880
def _cache(self):
81+
7982
if getattr(self, '_client', None) is None:
83+
84+
options = self._options
85+
options.setdefault('ignore_exc', True)
86+
options.pop('cluster_timeout', None)
87+
8088
self._client = self._lib.Client(
81-
self.get_cluster_nodes(), **self._options)
89+
self.get_cluster_nodes(), **options)
90+
8291
return self._client
8392

8493
@invalidate_cache_after_error

0 commit comments

Comments
 (0)