Skip to content
This repository was archived by the owner on Dec 8, 2017. It is now read-only.

Commit 8876956

Browse files
committed
add special error for bad address and fix protocol realization
1 parent e0d60de commit 8876956

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

README.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Amazon ElastiCache backend for Django
44
Simple Django cache backend for Amazon ElastiCache (memcached based). It uses
55
`pylibmc <http://github.com/lericson/pylibmc>`_ and setup connection to each
66
node in cluster using
7-
`Auto Discovery <http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html>`_
7+
`auto discovery <http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html>`_
88
function.
99

1010

@@ -35,25 +35,26 @@ Your cache backend should look something like this::
3535

3636
CACHES = {
3737
'default': {
38-
'BACKEND': 'django_elasticache.memcached.ElasctiCache',
38+
'BACKEND': 'django_elasticache.memcached.ElastiCache',
3939
'LOCATION': 'cache-c.drtgf.cfg.use1.cache.amazonaws.com:11211',
4040
}
4141
}
4242

43-
By the first call to cache it connect to cluster (using LOCATION),
44-
get list of all nodes and setup pylibmc client using full
45-
list of nodes. As result your cache will work with all nodes and
43+
By the first call to cache it connects to cluster (using LOCATION param),
44+
gets list of all nodes and setup pylibmc client using full
45+
list of nodes. As result your cache will work with all nodes in cluster and
4646
automatically detect new nodes in cluster. List of nodes are stored in class-level
47-
cached, so any changes in cluster take affect only after restart working process.
47+
cached, so any changes in cluster take affect only after restart of working process.
4848
But if you're using gunicorn or mod_wsgi you usually have max_request settings which
49-
restart process after some count of processed requests.
49+
restart process after some count of processed requests, so auto discovery will work
50+
fine.
5051

51-
Django-elascticache changes default pylibmc params to increase performance.
52+
Django-elasticache changes default pylibmc params to increase performance.
5253

5354

5455
Testing
5556
-------
5657

5758
Run the tests like this::
5859

59-
nosetest
60+
nosetest

django_elasticache/cluster_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_cluster_info(host, port):
3838
else:
3939
cmd = 'get AmazonElastiCache:cluster\n'
4040
client.write(cmd)
41+
client.read_until('\r\n')
4142
res = client.read_until('\r\n').strip()
4243
try:
4344
version = int(res)

django_elasticache/memcached.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Backend for django cache
33
"""
4+
import socket
45
from django.core.cache import InvalidCacheBackendError
56
from django.core.cache.backends.memcached import PyLibMCCache
67
from django.utils.functional import cached_property
@@ -45,7 +46,12 @@ def get_cluster_nodes(self):
4546
return list with all nodes in cluster
4647
"""
4748
server, port = self._servers[0].split(':')
48-
return get_cluster_info(server, port)['nodes']
49+
try:
50+
return get_cluster_info(server, port)['nodes']
51+
except socket.gaierror, err:
52+
raise Exception('Cannot connect to cluster {} ({})'.format(
53+
self._servers[0], err
54+
))
4955

5056
@property
5157
def _cache(self):

tests/test_protocol.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
TEST_PROTOCOL_1 = [
77
'VERSION 1.4.14',
8+
'',
89
'1',
910
'hostname|ip-address|port hostname||port'
1011
]
1112

1213
TEST_PROTOCOL_2 = [
1314
'VERSION 1.4.13',
15+
'',
1416
'1',
1517
'hostname|ip-address|port hostname||port'
1618
]

0 commit comments

Comments
 (0)