Skip to content

Commit 5dc7a9e

Browse files
committed
Merge pull request sebleier#87 from sebleier/unstable
Unstable
2 parents ff014f3 + 079e912 commit 5dc7a9e

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ clean:
2121

2222
.PHONY: test
2323
test: install_requirements
24-
PYTHONPATH=$(PYTHONPATH): django-admin.py test --settings=tests.settings -s
24+
PYTHONPATH=$(PYTHONPATH): django-admin.py test tests.testapp.tests.socket_timeout_tests:SocketTimeoutTestCase.test_socket_timeout --settings=tests.settings -s
2525

2626
.PHONY: shell
2727
shell:

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ A Redis cache backend for Django
1919
Changelog
2020
=========
2121

22+
1.4.0
23+
-----
24+
25+
* Adds support for providing a socket timeout on the redis-py client.
26+
2227
1.3.0
2328
-----
2429

redis_cache/backends/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(self, server, params):
5555
self.password = self.get_password()
5656
self.parser_class = self.get_parser_class()
5757
self.pickle_version = self.get_pickle_version()
58+
self.socket_timeout = self.get_socket_timeout()
5859
self.connection_pool_class = self.get_connection_pool_class()
5960
self.connection_pool_class_kwargs = (
6061
self.get_connection_pool_class_kwargs()
@@ -105,6 +106,9 @@ def get_pickle_version(self):
105106
except (ValueError, TypeError):
106107
raise ImproperlyConfigured("pickle version value must be an integer")
107108

109+
def get_socket_timeout(self):
110+
return self.options.get('SOCKET_TIMEOUT', None)
111+
108112
def get_connection_pool_class(self):
109113
pool_class = self.options.get('CONNECTION_POOL_CLASS', 'redis.ConnectionPool')
110114
module_name, class_name = pool_class.rsplit('.', 1)
@@ -153,6 +157,7 @@ def create_client(self, server):
153157
server,
154158
db=self.db,
155159
password=self.password,
160+
socket_timeout=self.socket_timeout,
156161
)
157162
client = redis.Redis(**kwargs)
158163
kwargs.update(

redis_cache/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_connection_pool(
3030
unix_socket_path=None,
3131
connection_pool_class=None,
3232
connection_pool_class_kwargs=None,
33+
socket_timeout=None,
3334
**kwargs
3435
):
3536
connection_identifier = (host, port, db, unix_socket_path)
@@ -48,6 +49,7 @@ def get_connection_pool(
4849
'password': password,
4950
'connection_class': connection_class,
5051
'parser_class': parser_class,
52+
'socket_timeout': socket_timeout,
5153
}
5254
kwargs.update(connection_pool_class_kwargs)
5355

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
url="http://github.com/sebleier/django-redis-cache/",
66
author="Sean Bleier",
77
author_email="[email protected]",
8-
version="1.3.0",
8+
version="1.4.0",
99
packages=["redis_cache", "redis_cache.backends"],
1010
description="Redis Cache Backend for Django",
1111
install_requires=['redis>=2.10.3'],
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
try:
3+
from django.test import override_settings
4+
except ImportError:
5+
from django.test.utils import override_settings
6+
from django.test import TestCase
7+
8+
from redis.exceptions import ConnectionError
9+
from tests.testapp.tests.base_tests import SetupMixin
10+
11+
LOCATION = "127.0.0.1:6382"
12+
13+
14+
@override_settings(
15+
CACHES={
16+
'default': {
17+
'BACKEND': 'redis_cache.RedisCache',
18+
'LOCATION': LOCATION,
19+
'OPTIONS': {
20+
'DB': 15,
21+
'PASSWORD': 'yadayada',
22+
'PARSER_CLASS': 'redis.connection.HiredisParser',
23+
'PICKLE_VERSION': -1,
24+
'SOCKET_TIMEOUT': 0,
25+
},
26+
},
27+
}
28+
)
29+
class SocketTimeoutTestCase(SetupMixin, TestCase):
30+
31+
def tearDown(self):
32+
pass
33+
34+
def test_socket_timeout(self):
35+
self.reset_pool()
36+
cache = self.get_cache()
37+
with self.assertRaises(ConnectionError):
38+
cache.set('aaaaa', 'a')

0 commit comments

Comments
 (0)