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
86cc01ae
Commit
86cc01ae
authored
Aug 26, 2016
by
Sean Bleier
Committed by
GitHub
Aug 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #119 from timgraham/trove
Drop support for Django < 1.8 and related cleanups
parents
a073a3ee
88cd5824
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
41 additions
and
129 deletions
+41
-129
.travis.yml
.travis.yml
+1
-4
README.rst
README.rst
+5
-0
base.py
redis_cache/backends/base.py
+3
-2
multiple.py
redis_cache/backends/multiple.py
+2
-1
single.py
redis_cache/backends/single.py
+2
-2
compat.py
redis_cache/compat.py
+0
-44
serializers.py
redis_cache/serializers.py
+4
-4
sharder.py
redis_cache/sharder.py
+4
-4
utils.py
redis_cache/utils.py
+9
-18
requirements-dev.txt
requirements-dev.txt
+0
-1
setup.py
setup.py
+2
-2
base_tests.py
tests/testapp/tests/base_tests.py
+3
-15
compressor_tests.py
tests/testapp/tests/compressor_tests.py
+1
-6
master_slave_tests.py
tests/testapp/tests/master_slave_tests.py
+1
-5
serializers_tests.py
tests/testapp/tests/serializers_tests.py
+1
-6
socket_tests.py
tests/testapp/tests/socket_tests.py
+1
-5
socket_timeout_tests.py
tests/testapp/tests/socket_timeout_tests.py
+1
-5
tcp_tests.py
tests/testapp/tests/tcp_tests.py
+1
-5
No files found.
.travis.yml
View file @
86cc01ae
language
:
python
language
:
python
python
:
python
:
-
"
2.7"
-
"
2.7"
-
"
3.2"
-
"
3.3"
-
"
3.3"
-
"
3.4"
-
"
3.4"
-
"
3.5"
env
:
env
:
-
DJANGO_VERSION=1.5
-
DJANGO_VERSION=1.6
-
DJANGO_VERSION=1.7
-
DJANGO_VERSION=1.8
-
DJANGO_VERSION=1.8
# command to run tests
# command to run tests
install
:
./install_redis.sh
install
:
./install_redis.sh
...
...
README.rst
View file @
86cc01ae
...
@@ -21,6 +21,11 @@ Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/.
...
@@ -21,6 +21,11 @@ Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/.
Changelog
Changelog
=========
=========
1.7.0
-----
* Drops support for Django < 1.8 and Python 3.2.
1.5.0
1.5.0
-----
-----
...
...
redis_cache/backends/base.py
View file @
86cc01ae
from
django.core.cache.backends.base
import
BaseCache
,
InvalidCacheBackendError
from
django.core.cache.backends.base
import
(
BaseCache
,
DEFAULT_TIMEOUT
,
InvalidCacheBackendError
,
)
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
try
:
try
:
...
@@ -10,7 +12,6 @@ except ImportError:
...
@@ -10,7 +12,6 @@ except ImportError:
from
redis.connection
import
DefaultParser
from
redis.connection
import
DefaultParser
from
redis_cache.compat
import
DEFAULT_TIMEOUT
from
redis_cache.connection
import
pool
from
redis_cache.connection
import
pool
from
redis_cache.utils
import
(
from
redis_cache.utils
import
(
CacheKey
,
get_servers
,
parse_connection_kwargs
,
import_class
CacheKey
,
get_servers
,
parse_connection_kwargs
,
import_class
...
...
redis_cache/backends/multiple.py
View file @
86cc01ae
from
collections
import
defaultdict
from
collections
import
defaultdict
from
django.core.cache.backends.base
import
DEFAULT_TIMEOUT
from
redis_cache.backends.base
import
BaseRedisCache
from
redis_cache.backends.base
import
BaseRedisCache
from
redis_cache.compat
import
DEFAULT_TIMEOUT
from
redis_cache.sharder
import
HashRing
from
redis_cache.sharder
import
HashRing
...
...
redis_cache/backends/single.py
View file @
86cc01ae
from
redis_cache.compat
import
DEFAULT_TIMEOUT
try
:
try
:
import
cPickle
as
pickle
import
cPickle
as
pickle
except
ImportError
:
except
ImportError
:
import
pickle
import
pickle
import
random
import
random
from
django.core.cache.backends.base
import
DEFAULT_TIMEOUT
from
redis_cache.backends.base
import
BaseRedisCache
from
redis_cache.backends.base
import
BaseRedisCache
...
...
redis_cache/compat.py
deleted
100644 → 0
View file @
a073a3ee
import
sys
import
django
PY3
=
(
sys
.
version_info
>=
(
3
,))
try
:
# Django 1.5+
from
django.utils.encoding
import
smart_text
,
smart_bytes
except
ImportError
:
# older Django, thus definitely Python 2
from
django.utils.encoding
import
smart_unicode
,
smart_str
smart_text
=
smart_unicode
smart_bytes
=
smart_str
if
PY3
:
bytes_type
=
bytes
from
urllib.parse
import
parse_qs
,
urlparse
else
:
bytes_type
=
str
from
urlparse
import
parse_qs
,
urlparse
if
django
.
VERSION
[:
2
]
>=
(
1
,
6
):
from
django.core.cache.backends.base
import
DEFAULT_TIMEOUT
as
DJANGO_DEFAULT_TIMEOUT
DEFAULT_TIMEOUT
=
DJANGO_DEFAULT_TIMEOUT
else
:
DEFAULT_TIMEOUT
=
None
def
python_2_unicode_compatible
(
klass
):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.
To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.
Backported from Django 1.5+.
"""
if
not
PY3
:
klass
.
__unicode__
=
klass
.
__str__
klass
.
__str__
=
lambda
self
:
self
.
__unicode__
()
.
encode
(
'utf-8'
)
return
klass
redis_cache/serializers.py
View file @
86cc01ae
...
@@ -15,7 +15,7 @@ try:
...
@@ -15,7 +15,7 @@ try:
except
ImportError
:
except
ImportError
:
pass
pass
from
redis_cache.compat
import
smart_bytes
,
smart
_text
from
django.utils.encoding
import
force_bytes
,
force
_text
class
BaseSerializer
(
object
):
class
BaseSerializer
(
object
):
...
@@ -39,7 +39,7 @@ class PickleSerializer(object):
...
@@ -39,7 +39,7 @@ class PickleSerializer(object):
return
pickle
.
dumps
(
value
,
self
.
pickle_version
)
return
pickle
.
dumps
(
value
,
self
.
pickle_version
)
def
deserialize
(
self
,
value
):
def
deserialize
(
self
,
value
):
return
pickle
.
loads
(
smart
_bytes
(
value
))
return
pickle
.
loads
(
force
_bytes
(
value
))
class
JSONSerializer
(
BaseSerializer
):
class
JSONSerializer
(
BaseSerializer
):
...
@@ -48,10 +48,10 @@ class JSONSerializer(BaseSerializer):
...
@@ -48,10 +48,10 @@ class JSONSerializer(BaseSerializer):
super
(
JSONSerializer
,
self
)
.
__init__
(
**
kwargs
)
super
(
JSONSerializer
,
self
)
.
__init__
(
**
kwargs
)
def
serialize
(
self
,
value
):
def
serialize
(
self
,
value
):
return
smart
_bytes
(
json
.
dumps
(
value
))
return
force
_bytes
(
json
.
dumps
(
value
))
def
deserialize
(
self
,
value
):
def
deserialize
(
self
,
value
):
return
json
.
loads
(
smart
_text
(
value
))
return
json
.
loads
(
force
_text
(
value
))
class
MSGPackSerializer
(
BaseSerializer
):
class
MSGPackSerializer
(
BaseSerializer
):
...
...
redis_cache/sharder.py
View file @
86cc01ae
from
bisect
import
insort
,
bisect
from
bisect
import
insort
,
bisect
import
hashlib
import
hashlib
from
redis_cache.compat
import
smart
_text
from
django.utils.encoding
import
force
_text
DIGITS
=
8
DIGITS
=
8
...
@@ -17,8 +17,8 @@ class Node(object):
...
@@ -17,8 +17,8 @@ class Node(object):
self
.
_node
=
node
self
.
_node
=
node
self
.
_i
=
i
self
.
_i
=
i
key
=
"{0}:{1}"
.
format
(
key
=
"{0}:{1}"
.
format
(
smart
_text
(
i
),
force
_text
(
i
),
smart
_text
(
self
.
_node
),
force
_text
(
self
.
_node
),
)
)
self
.
_position
=
get_slot
(
key
)
self
.
_position
=
get_slot
(
key
)
...
@@ -52,5 +52,5 @@ class HashRing(object):
...
@@ -52,5 +52,5 @@ class HashRing(object):
del
self
.
_nodes
[
n
-
i
-
1
]
del
self
.
_nodes
[
n
-
i
-
1
]
def
get_node
(
self
,
key
):
def
get_node
(
self
,
key
):
i
=
bisect
(
self
.
_nodes
,
get_slot
(
smart
_text
(
key
)))
-
1
i
=
bisect
(
self
.
_nodes
,
get_slot
(
force
_text
(
key
)))
-
1
return
self
.
_nodes
[
i
]
.
_node
return
self
.
_nodes
[
i
]
.
_node
redis_cache/utils.py
View file @
86cc01ae
import
importlib
import
warnings
import
warnings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
redis.connection
import
SSLConnection
from
django.utils
import
six
from
django.utils.encoding
import
force_text
,
python_2_unicode_compatible
from
redis_cache.compat
import
(
from
django.utils.six.moves.urllib.parse
import
parse_qs
,
urlparse
smart_text
,
python_2_unicode_compatible
,
parse_qs
,
urlparse
)
try
:
from
redis.connection
import
SSLConnection
import
importlib
except
ImportError
:
from
django.utils
import
importlib
try
:
basestring
except
NameError
:
basestring
=
str
@
python_2_unicode_compatible
@
python_2_unicode_compatible
...
@@ -30,20 +21,20 @@ class CacheKey(object):
...
@@ -30,20 +21,20 @@ class CacheKey(object):
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
self
.
_versioned_key
==
other
return
self
.
_versioned_key
==
other
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
smart
_text
(
self
.
_versioned_key
)
return
force
_text
(
self
.
_versioned_key
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
self
.
_versioned_key
)
return
hash
(
self
.
_versioned_key
)
__repr__
=
__str__
=
__unicode__
__repr__
=
__str__
def
get_servers
(
location
):
def
get_servers
(
location
):
"""Returns a list of servers given the server argument passed in from
"""Returns a list of servers given the server argument passed in from
Django.
Django.
"""
"""
if
isinstance
(
location
,
basestring
):
if
isinstance
(
location
,
six
.
string_types
):
servers
=
location
.
split
(
','
)
servers
=
location
.
split
(
','
)
elif
hasattr
(
location
,
'__iter__'
):
elif
hasattr
(
location
,
'__iter__'
):
servers
=
location
servers
=
location
...
...
requirements-dev.txt
View file @
86cc01ae
hiredis==0.2.0
hiredis==0.2.0
django-nose==1.4
django-nose==1.4
nose==1.3.6
nose==1.3.6
unittest2==1.0.1
msgpack-python==0.4.6
msgpack-python==0.4.6
pyyaml==3.11
pyyaml==3.11
setup.py
View file @
86cc01ae
...
@@ -11,15 +11,15 @@ setup(
...
@@ -11,15 +11,15 @@ setup(
install_requires
=
[
'redis>=2.10.3'
],
install_requires
=
[
'redis>=2.10.3'
],
classifiers
=
[
classifiers
=
[
"Programming Language :: Python"
,
"Programming Language :: Python"
,
"Programming Language :: Python :: 2.6"
,
"Programming Language :: Python :: 2.7"
,
"Programming Language :: Python :: 2.7"
,
"Programming Language :: Python :: 3.2"
,
"Programming Language :: Python :: 3.3"
,
"Programming Language :: Python :: 3.3"
,
"Programming Language :: Python :: 3.4"
,
"Programming Language :: Python :: 3.4"
,
"Programming Language :: Python :: 3.5"
,
"Operating System :: OS Independent"
,
"Operating System :: OS Independent"
,
"Topic :: Software Development :: Libraries"
,
"Topic :: Software Development :: Libraries"
,
"Topic :: Utilities"
,
"Topic :: Utilities"
,
"Environment :: Web Environment"
,
"Environment :: Web Environment"
,
"Framework :: Django"
,
"Framework :: Django"
,
"Framework :: Django :: 1.8"
,
],
],
)
)
tests/testapp/tests/base_tests.py
View file @
86cc01ae
...
@@ -4,14 +4,8 @@ from __future__ import unicode_literals
...
@@ -4,14 +4,8 @@ from __future__ import unicode_literals
from
hashlib
import
sha1
from
hashlib
import
sha1
import
os
import
os
import
subprocess
import
subprocess
import
sys
import
time
import
time
if
sys
.
version_info
<
(
2
,
7
):
import
unittest2
as
unittest
else
:
import
unittest
try
:
try
:
import
cPickle
as
pickle
import
cPickle
as
pickle
...
@@ -20,17 +14,13 @@ except ImportError:
...
@@ -20,17 +14,13 @@ except ImportError:
from
django.core.cache
import
get_cache
from
django.core.cache
import
get_cache
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
django.test
import
TestCase
from
django.test
import
TestCase
,
override_settings
try
:
from
django.utils.encoding
import
force_bytes
from
django.test
import
override_settings
except
ImportError
:
from
django.test.utils
import
override_settings
import
redis
import
redis
from
tests.testapp.models
import
Poll
,
expensive_calculation
from
tests.testapp.models
import
Poll
,
expensive_calculation
from
redis_cache.cache
import
RedisCache
,
pool
from
redis_cache.cache
import
RedisCache
,
pool
from
redis_cache.compat
import
DEFAULT_TIMEOUT
,
smart_bytes
from
redis_cache.utils
import
get_servers
,
parse_connection_kwargs
from
redis_cache.utils
import
get_servers
,
parse_connection_kwargs
...
@@ -299,7 +289,6 @@ class BaseRedisTestCase(SetupMixin):
...
@@ -299,7 +289,6 @@ class BaseRedisTestCase(SetupMixin):
self
.
assertEqual
(
self
.
cache
.
get
(
"expire2"
),
"newvalue"
)
self
.
assertEqual
(
self
.
cache
.
get
(
"expire2"
),
"newvalue"
)
self
.
assertEqual
(
"expire3"
in
self
.
cache
,
False
)
self
.
assertEqual
(
"expire3"
in
self
.
cache
,
False
)
@
unittest
.
skipIf
(
DEFAULT_TIMEOUT
is
None
,
"Version of django doesn't support indefinite timeouts."
)
def
test_set_expiration_timeout_None
(
self
):
def
test_set_expiration_timeout_None
(
self
):
key
,
value
=
'key'
,
'value'
key
,
value
=
'key'
,
'value'
self
.
cache
.
set
(
key
,
value
,
timeout
=
None
)
self
.
cache
.
set
(
key
,
value
,
timeout
=
None
)
...
@@ -479,7 +468,7 @@ class BaseRedisTestCase(SetupMixin):
...
@@ -479,7 +468,7 @@ class BaseRedisTestCase(SetupMixin):
def
test_reinsert_keys
(
self
):
def
test_reinsert_keys
(
self
):
self
.
cache
.
_pickle_version
=
0
self
.
cache
.
_pickle_version
=
0
for
i
in
range
(
2000
):
for
i
in
range
(
2000
):
s
=
sha1
(
smart
_bytes
(
i
))
.
hexdigest
()
s
=
sha1
(
force
_bytes
(
i
))
.
hexdigest
()
self
.
cache
.
set
(
s
,
self
.
cache
)
self
.
cache
.
set
(
s
,
self
.
cache
)
self
.
cache
.
_pickle_version
=
-
1
self
.
cache
.
_pickle_version
=
-
1
self
.
cache
.
reinsert_keys
()
self
.
cache
.
reinsert_keys
()
...
@@ -563,7 +552,6 @@ class BaseRedisTestCase(SetupMixin):
...
@@ -563,7 +552,6 @@ class BaseRedisTestCase(SetupMixin):
ttl
=
self
.
cache
.
ttl
(
'a'
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
self
.
assertAlmostEqual
(
ttl
,
10
)
self
.
assertAlmostEqual
(
ttl
,
10
)
@
unittest
.
skipIf
(
DEFAULT_TIMEOUT
is
None
,
"Version of django doesn't support indefinite timeouts."
)
def
test_ttl_no_expiry
(
self
):
def
test_ttl_no_expiry
(
self
):
self
.
cache
.
set
(
'a'
,
'a'
,
timeout
=
None
)
self
.
cache
.
set
(
'a'
,
'a'
,
timeout
=
None
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
...
...
tests/testapp/tests/compressor_tests.py
View file @
86cc01ae
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
try
:
from
django.test
import
TestCase
,
override_settings
from
django.test
import
override_settings
except
ImportError
:
from
django.test.utils
import
override_settings
from
django.test
import
TestCase
from
tests.testapp.tests.base_tests
import
BaseRedisTestCase
from
tests.testapp.tests.base_tests
import
BaseRedisTestCase
...
...
tests/testapp/tests/master_slave_tests.py
View file @
86cc01ae
import
time
import
time
from
django.test
import
TestCase
from
django.test
import
TestCase
,
override_settings
try
:
from
django.test
import
override_settings
except
ImportError
:
from
django.test.utils
import
override_settings
from
redis_cache.connection
import
pool
from
redis_cache.connection
import
pool
...
...
tests/testapp/tests/serializers_tests.py
View file @
86cc01ae
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.test
import
TestCase
from
django.test
import
TestCase
,
override_settings
try
:
from
django.test
import
override_settings
except
ImportError
:
from
django.test.utils
import
override_settings
from
tests.testapp.tests.base_tests
import
SetupMixin
from
tests.testapp.tests.base_tests
import
SetupMixin
...
@@ -171,4 +167,3 @@ class MSGPackSerializerTestCase(BaseSerializerTestCase):
...
@@ -171,4 +167,3 @@ class MSGPackSerializerTestCase(BaseSerializerTestCase):
class
YAMLSerializerTestCase
(
BaseSerializerTestCase
):
class
YAMLSerializerTestCase
(
BaseSerializerTestCase
):
converts_tuple_to_list
=
False
converts_tuple_to_list
=
False
serializes_objects
=
True
serializes_objects
=
True
tests/testapp/tests/socket_tests.py
View file @
86cc01ae
...
@@ -3,11 +3,7 @@ from collections import Counter
...
@@ -3,11 +3,7 @@ from collections import Counter
from
tests.testapp.tests.base_tests
import
BaseRedisTestCase
from
tests.testapp.tests.base_tests
import
BaseRedisTestCase
from
tests.testapp.tests.multi_server_tests
import
MultiServerTests
from
tests.testapp.tests.multi_server_tests
import
MultiServerTests
try
:
from
django.test
import
TestCase
,
override_settings
from
django.test
import
override_settings
except
ImportError
:
from
django.test.utils
import
override_settings
from
django.test
import
TestCase
LOCATION
=
"unix://:yadayada@/tmp/redis0.sock?db=15"
LOCATION
=
"unix://:yadayada@/tmp/redis0.sock?db=15"
...
...
tests/testapp/tests/socket_timeout_tests.py
View file @
86cc01ae
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
try
:
from
django.test
import
TestCase
,
override_settings
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
redis.exceptions
import
ConnectionError
from
tests.testapp.tests.base_tests
import
SetupMixin
from
tests.testapp.tests.base_tests
import
SetupMixin
...
...
tests/testapp/tests/tcp_tests.py
View file @
86cc01ae
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
tests.testapp.tests.base_tests
import
BaseRedisTestCase
from
tests.testapp.tests.base_tests
import
BaseRedisTestCase
from
tests.testapp.tests.multi_server_tests
import
MultiServerTests
from
tests.testapp.tests.multi_server_tests
import
MultiServerTests
try
:
from
django.test
import
TestCase
,
override_settings
from
django.test
import
override_settings
except
ImportError
:
from
django.test.utils
import
override_settings
from
django.test
import
TestCase
from
redis_cache.cache
import
ImproperlyConfigured
from
redis_cache.cache
import
ImproperlyConfigured
from
redis.connection
import
UnixDomainSocketConnection
from
redis.connection
import
UnixDomainSocketConnection
...
...
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