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
4833215c
Commit
4833215c
authored
Feb 04, 2013
by
Sean Bleier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing issue #48 where the backend was improperly casting string integers.
parent
b4308765
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
cache.py
redis_cache/cache.py
+4
-7
tests.py
tests/testapp/tests.py
+7
-1
No files found.
redis_cache/cache.py
View file @
4833215c
...
@@ -209,15 +209,12 @@ class CacheClass(BaseCache):
...
@@ -209,15 +209,12 @@ class CacheClass(BaseCache):
key
=
self
.
make_key
(
key
,
version
=
version
)
key
=
self
.
make_key
(
key
,
version
=
version
)
if
timeout
is
None
:
if
timeout
is
None
:
timeout
=
self
.
default_timeout
timeout
=
self
.
default_timeout
try
:
value
=
float
(
value
)
# If ``value`` is not an int, then pickle it
# If you lose precision from the typecast to str, then pickle value
if
not
isinstance
(
value
,
int
):
if
int
(
value
)
!=
value
:
raise
TypeError
except
(
ValueError
,
TypeError
):
result
=
self
.
_set
(
key
,
pickle
.
dumps
(
value
),
int
(
timeout
),
client
,
_add_only
)
result
=
self
.
_set
(
key
,
pickle
.
dumps
(
value
),
int
(
timeout
),
client
,
_add_only
)
else
:
else
:
result
=
self
.
_set
(
key
,
int
(
value
)
,
int
(
timeout
),
client
,
_add_only
)
result
=
self
.
_set
(
key
,
value
,
int
(
timeout
),
client
,
_add_only
)
# result is a boolean
# result is a boolean
return
result
return
result
...
...
tests/testapp/tests.py
View file @
4833215c
...
@@ -345,7 +345,7 @@ class RedisCacheTests(TestCase):
...
@@ -345,7 +345,7 @@ class RedisCacheTests(TestCase):
def
test_string_float_caching
(
self
):
def
test_string_float_caching
(
self
):
self
.
cache
.
set
(
'a'
,
'1.1'
)
self
.
cache
.
set
(
'a'
,
'1.1'
)
a
=
self
.
cache
.
get
(
'a'
)
a
=
self
.
cache
.
get
(
'a'
)
self
.
assertEqual
(
a
,
1.1
)
self
.
assertEqual
(
a
,
'1.1'
)
def
test_multiple_connection_pool_connections
(
self
):
def
test_multiple_connection_pool_connections
(
self
):
pool
.
_connection_pools
=
{}
pool
.
_connection_pools
=
{}
...
@@ -356,6 +356,12 @@ class RedisCacheTests(TestCase):
...
@@ -356,6 +356,12 @@ class RedisCacheTests(TestCase):
c3
=
get_cache
(
'redis_cache.cache://127.0.0.1:6379?db=15'
)
c3
=
get_cache
(
'redis_cache.cache://127.0.0.1:6379?db=15'
)
self
.
assertEqual
(
len
(
pool
.
_connection_pools
),
2
)
self
.
assertEqual
(
len
(
pool
.
_connection_pools
),
2
)
def
test_setting_string_integer_retrieves_string
(
self
):
self
.
assertTrue
(
self
.
cache
.
set
(
"foo"
,
"1"
))
self
.
assertEqual
(
self
.
cache
.
get
(
"foo"
),
"1"
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
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