Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions django_elasticache/cluster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
utils for discovery cluster
"""
from distutils.version import StrictVersion
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
import re
from telnetlib import Telnet

Expand Down Expand Up @@ -35,7 +35,7 @@ def get_cluster_info(host, port, ignore_cluster_errors=False):
if len(version_list) not in [2, 3] or version_list[0] != b'VERSION':
raise WrongProtocolData('version', res)
version = version_list[1]
if StrictVersion(smart_text(version)) >= StrictVersion('1.4.14'):
if StrictVersion(smart_str(version)) >= StrictVersion('1.4.14'):
cmd = b'config get cluster\n'
else:
cmd = b'get AmazonElastiCache:cluster\n'
Expand All @@ -50,8 +50,8 @@ def get_cluster_info(host, port, ignore_cluster_errors=False):
return {
'version': version,
'nodes': [
'{0}:{1}'.format(smart_text(host),
smart_text(port))
'{0}:{1}'.format(smart_str(host),
smart_str(port))
]
}

Expand All @@ -67,8 +67,8 @@ def get_cluster_info(host, port, ignore_cluster_errors=False):
try:
for node in ls[2].split(b' '):
host, ip, port = node.split(b'|')
nodes.append('{0}:{1}'.format(smart_text(ip or host),
smart_text(port)))
nodes.append('{0}:{1}'.format(smart_str(ip or host),
smart_str(port)))
except ValueError:
raise WrongProtocolData(cmd, res)
return {
Expand Down
9 changes: 6 additions & 3 deletions django_elasticache/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import socket
from functools import wraps
from django.core.cache import InvalidCacheBackendError
from django.core.cache.backends.memcached import PyLibMCCache
from django.core.cache.backends.memcached import BaseMemcachedCache
from threading import local
from .cluster_utils import get_cluster_info


Expand All @@ -22,14 +23,16 @@ def wrapper(self, *args, **kwds):
return wrapper


class ElastiCache(PyLibMCCache):
class ElastiCache(BaseMemcachedCache):
"""
backend for Amazon ElastiCache (memcached) with auto discovery mode
it used pylibmc in binary mode
"""
def __init__(self, server, params):
self._local = local()
self.update_params(params)
super(ElastiCache, self).__init__(server, params)
import pylibmc
super(ElastiCache, self).__init__(server, params, library=pylibmc, value_not_found_exception=pylibmc.NotFound)
if len(self._servers) > 1:
raise InvalidCacheBackendError(
'ElastiCache should be configured with only one server '
Expand Down
2 changes: 1 addition & 1 deletion tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_no_configuration_protocol_support_with_errors_ignored(Telnet):
call(b'version\n'),
call(b'config get cluster\n'),
])
eq_(info['version'], '1.4.34')
eq_(info['version'], b'1.4.34')
eq_(info['nodes'], ['test:0'])


Expand Down