Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
Django-Redis-Cache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared
Django-Redis-Cache
Commits
83bdb08e
Commit
83bdb08e
authored
Jul 19, 2015
by
Sean Bleier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for providing a socket timeout to redis-py.
parent
ff014f34
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
1 deletion
+46
-1
Makefile
Makefile
+1
-1
base.py
redis_cache/backends/base.py
+5
-0
connection.py
redis_cache/connection.py
+2
-0
socket_timeout_tests.py
tests/testapp/tests/socket_timeout_tests.py
+38
-0
No files found.
Makefile
View file @
83bdb08e
...
@@ -21,7 +21,7 @@ clean:
...
@@ -21,7 +21,7 @@ clean:
.PHONY
:
test
.PHONY
:
test
test
:
install_requirements
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
.PHONY
:
shell
shell
:
shell
:
...
...
redis_cache/backends/base.py
View file @
83bdb08e
...
@@ -55,6 +55,7 @@ class BaseRedisCache(BaseCache):
...
@@ -55,6 +55,7 @@ class BaseRedisCache(BaseCache):
self
.
password
=
self
.
get_password
()
self
.
password
=
self
.
get_password
()
self
.
parser_class
=
self
.
get_parser_class
()
self
.
parser_class
=
self
.
get_parser_class
()
self
.
pickle_version
=
self
.
get_pickle_version
()
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
=
self
.
get_connection_pool_class
()
self
.
connection_pool_class_kwargs
=
(
self
.
connection_pool_class_kwargs
=
(
self
.
get_connection_pool_class_kwargs
()
self
.
get_connection_pool_class_kwargs
()
...
@@ -105,6 +106,9 @@ class BaseRedisCache(BaseCache):
...
@@ -105,6 +106,9 @@ class BaseRedisCache(BaseCache):
except
(
ValueError
,
TypeError
):
except
(
ValueError
,
TypeError
):
raise
ImproperlyConfigured
(
"pickle version value must be an integer"
)
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
):
def
get_connection_pool_class
(
self
):
pool_class
=
self
.
options
.
get
(
'CONNECTION_POOL_CLASS'
,
'redis.ConnectionPool'
)
pool_class
=
self
.
options
.
get
(
'CONNECTION_POOL_CLASS'
,
'redis.ConnectionPool'
)
module_name
,
class_name
=
pool_class
.
rsplit
(
'.'
,
1
)
module_name
,
class_name
=
pool_class
.
rsplit
(
'.'
,
1
)
...
@@ -153,6 +157,7 @@ class BaseRedisCache(BaseCache):
...
@@ -153,6 +157,7 @@ class BaseRedisCache(BaseCache):
server
,
server
,
db
=
self
.
db
,
db
=
self
.
db
,
password
=
self
.
password
,
password
=
self
.
password
,
socket_timeout
=
self
.
socket_timeout
,
)
)
client
=
redis
.
Redis
(
**
kwargs
)
client
=
redis
.
Redis
(
**
kwargs
)
kwargs
.
update
(
kwargs
.
update
(
...
...
redis_cache/connection.py
View file @
83bdb08e
...
@@ -30,6 +30,7 @@ class CacheConnectionPool(object):
...
@@ -30,6 +30,7 @@ class CacheConnectionPool(object):
unix_socket_path
=
None
,
unix_socket_path
=
None
,
connection_pool_class
=
None
,
connection_pool_class
=
None
,
connection_pool_class_kwargs
=
None
,
connection_pool_class_kwargs
=
None
,
socket_timeout
=
None
,
**
kwargs
**
kwargs
):
):
connection_identifier
=
(
host
,
port
,
db
,
unix_socket_path
)
connection_identifier
=
(
host
,
port
,
db
,
unix_socket_path
)
...
@@ -48,6 +49,7 @@ class CacheConnectionPool(object):
...
@@ -48,6 +49,7 @@ class CacheConnectionPool(object):
'password'
:
password
,
'password'
:
password
,
'connection_class'
:
connection_class
,
'connection_class'
:
connection_class
,
'parser_class'
:
parser_class
,
'parser_class'
:
parser_class
,
'socket_timeout'
:
socket_timeout
,
}
}
kwargs
.
update
(
connection_pool_class_kwargs
)
kwargs
.
update
(
connection_pool_class_kwargs
)
...
...
tests/testapp/tests/socket_timeout_tests.py
0 → 100644
View file @
83bdb08e
# -*- 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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment