Commit 5dc7a9e1 authored by Sean Bleier's avatar Sean Bleier

Merge pull request #87 from sebleier/unstable

Unstable
parents ff014f34 079e9126
......@@ -21,7 +21,7 @@ clean:
.PHONY: test
test: install_requirements
PYTHONPATH=$(PYTHONPATH): django-admin.py test --settings=tests.settings -s
PYTHONPATH=$(PYTHONPATH): django-admin.py test tests.testapp.tests.socket_timeout_tests:SocketTimeoutTestCase.test_socket_timeout --settings=tests.settings -s
.PHONY: shell
shell:
......
......@@ -19,6 +19,11 @@ A Redis cache backend for Django
Changelog
=========
1.4.0
-----
* Adds support for providing a socket timeout on the redis-py client.
1.3.0
-----
......
......@@ -55,6 +55,7 @@ class BaseRedisCache(BaseCache):
self.password = self.get_password()
self.parser_class = self.get_parser_class()
self.pickle_version = self.get_pickle_version()
self.socket_timeout = self.get_socket_timeout()
self.connection_pool_class = self.get_connection_pool_class()
self.connection_pool_class_kwargs = (
self.get_connection_pool_class_kwargs()
......@@ -105,6 +106,9 @@ class BaseRedisCache(BaseCache):
except (ValueError, TypeError):
raise ImproperlyConfigured("pickle version value must be an integer")
def get_socket_timeout(self):
return self.options.get('SOCKET_TIMEOUT', None)
def get_connection_pool_class(self):
pool_class = self.options.get('CONNECTION_POOL_CLASS', 'redis.ConnectionPool')
module_name, class_name = pool_class.rsplit('.', 1)
......@@ -153,6 +157,7 @@ class BaseRedisCache(BaseCache):
server,
db=self.db,
password=self.password,
socket_timeout=self.socket_timeout,
)
client = redis.Redis(**kwargs)
kwargs.update(
......
......@@ -30,6 +30,7 @@ class CacheConnectionPool(object):
unix_socket_path=None,
connection_pool_class=None,
connection_pool_class_kwargs=None,
socket_timeout=None,
**kwargs
):
connection_identifier = (host, port, db, unix_socket_path)
......@@ -48,6 +49,7 @@ class CacheConnectionPool(object):
'password': password,
'connection_class': connection_class,
'parser_class': parser_class,
'socket_timeout': socket_timeout,
}
kwargs.update(connection_pool_class_kwargs)
......
......@@ -5,7 +5,7 @@ setup(
url="http://github.com/sebleier/django-redis-cache/",
author="Sean Bleier",
author_email="sebleier@gmail.com",
version="1.3.0",
version="1.4.0",
packages=["redis_cache", "redis_cache.backends"],
description="Redis Cache Backend for Django",
install_requires=['redis>=2.10.3'],
......
# -*- coding: utf-8 -*-
try:
from django.test import override_settings
except ImportError:
from django.test.utils import override_settings
from django.test import TestCase
from redis.exceptions import ConnectionError
from tests.testapp.tests.base_tests import SetupMixin
LOCATION = "127.0.0.1:6382"
@override_settings(
CACHES={
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': LOCATION,
'OPTIONS': {
'DB': 15,
'PASSWORD': 'yadayada',
'PARSER_CLASS': 'redis.connection.HiredisParser',
'PICKLE_VERSION': -1,
'SOCKET_TIMEOUT': 0,
},
},
}
)
class SocketTimeoutTestCase(SetupMixin, TestCase):
def tearDown(self):
pass
def test_socket_timeout(self):
self.reset_pool()
cache = self.get_cache()
with self.assertRaises(ConnectionError):
cache.set('aaaaa', 'a')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment