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
77213d12
Commit
77213d12
authored
Aug 26, 2016
by
Tim Graham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace compat.smart_text()/smart_bytes() with force_text/force_bytes()
parent
f92c0eca
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
22 deletions
+12
-22
compat.py
redis_cache/compat.py
+0
-8
serializers.py
redis_cache/serializers.py
+4
-4
sharder.py
redis_cache/sharder.py
+4
-4
utils.py
redis_cache/utils.py
+2
-4
base_tests.py
tests/testapp/tests/base_tests.py
+2
-2
No files found.
redis_cache/compat.py
deleted
100644 → 0
View file @
f92c0eca
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
redis_cache/serializers.py
View file @
77213d12
...
@@ -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 @
77213d12
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 @
77213d12
...
@@ -3,13 +3,11 @@ import warnings
...
@@ -3,13 +3,11 @@ import warnings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.encoding
import
force_text
,
python_2_unicode_compatible
from
django.utils.six.moves.urllib.parse
import
parse_qs
,
urlparse
from
django.utils.six.moves.urllib.parse
import
parse_qs
,
urlparse
from
redis.connection
import
SSLConnection
from
redis.connection
import
SSLConnection
from
redis_cache.compat
import
smart_text
@
python_2_unicode_compatible
@
python_2_unicode_compatible
class
CacheKey
(
object
):
class
CacheKey
(
object
):
...
@@ -24,7 +22,7 @@ class CacheKey(object):
...
@@ -24,7 +22,7 @@ class CacheKey(object):
return
self
.
_versioned_key
==
other
return
self
.
_versioned_key
==
other
def
__str__
(
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
)
...
...
tests/testapp/tests/base_tests.py
View file @
77213d12
...
@@ -15,12 +15,12 @@ except ImportError:
...
@@ -15,12 +15,12 @@ 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
,
override_settings
from
django.test
import
TestCase
,
override_settings
from
django.utils.encoding
import
force_bytes
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
smart_bytes
from
redis_cache.utils
import
get_servers
,
parse_connection_kwargs
from
redis_cache.utils
import
get_servers
,
parse_connection_kwargs
...
@@ -468,7 +468,7 @@ class BaseRedisTestCase(SetupMixin):
...
@@ -468,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
()
...
...
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