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
60c5c0f2
Commit
60c5c0f2
authored
Jun 24, 2015
by
Sean Bleier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/mlindemu/django-redis-cache
parents
f795977c
f5554488
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
0 deletions
+65
-0
base.py
redis_cache/backends/base.py
+23
-0
multiple.py
redis_cache/backends/multiple.py
+10
-0
single.py
redis_cache/backends/single.py
+8
-0
base_tests.py
tests/testapp/tests/base_tests.py
+24
-0
No files found.
redis_cache/backends/base.py
View file @
60c5c0f2
...
...
@@ -403,3 +403,26 @@ class BaseRedisCache(BaseCache):
Reinsert cache entries using the current pickle protocol version.
"""
raise
NotImplementedError
def
_persist
(
self
,
client
,
key
,
version
=
None
):
if
client
.
exists
(
key
):
client
.
persist
(
key
)
def
persist
(
self
,
key
):
"""
Remove the timeout on a key. Equivalent to setting a timeout
of None in a set command.
"""
raise
NotImplementedError
def
_expire
(
self
,
client
,
key
,
timeout
,
version
=
None
):
if
client
.
exists
(
key
):
client
.
expire
(
key
,
timeout
)
def
expire
(
self
,
key
,
timeout
):
"""
Set the expire time on a key
Will raise an exception if the key does not exist
"""
raise
NotImplementedError
redis_cache/backends/multiple.py
View file @
60c5c0f2
...
...
@@ -211,3 +211,13 @@ class ShardedRedisCache(BaseRedisCache):
for
client
in
self
.
clients
.
itervalues
():
self
.
_reinsert_keys
(
client
)
print
def
persist
(
self
,
key
,
version
=
None
):
client
=
self
.
get_client
(
key
,
for_write
=
True
)
key
=
self
.
make_key
(
key
,
version
=
version
)
self
.
_persist
(
client
,
key
,
version
)
def
expire
(
self
,
key
,
timeout
,
version
=
None
):
client
=
self
.
get_client
(
key
,
for_write
=
True
)
key
=
self
.
make_key
(
key
,
version
=
version
)
self
.
_expire
(
client
,
key
,
timeout
,
version
)
redis_cache/backends/single.py
View file @
60c5c0f2
...
...
@@ -151,3 +151,11 @@ class RedisCache(BaseRedisCache):
Reinsert cache entries using the current pickle protocol version.
"""
self
.
_reinsert_keys
(
self
.
client
)
def
persist
(
self
,
key
,
version
=
None
):
key
=
self
.
make_key
(
key
,
version
=
version
)
self
.
_persist
(
self
.
client
,
key
,
version
)
def
expire
(
self
,
key
,
timeout
,
version
=
None
):
key
=
self
.
make_key
(
key
,
version
=
version
)
self
.
_expire
(
self
.
client
,
key
,
timeout
,
version
)
tests/testapp/tests/base_tests.py
View file @
60c5c0f2
...
...
@@ -470,3 +470,27 @@ class BaseRedisTestCase(SetupMixin):
"""
ttl
=
self
.
cache
.
ttl
(
'does_not_exist'
)
self
.
assertEqual
(
ttl
,
0
)
def
test_persist_expire_to_persist
(
self
):
self
.
cache
.
set
(
'a'
,
'a'
,
timeout
=
10
)
self
.
cache
.
persist
(
'a'
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
self
.
assertEqual
(
ttl
,
None
)
def
test_expire_no_expiry_to_expire
(
self
):
self
.
cache
.
set
(
'a'
,
'a'
,
timeout
=
None
)
self
.
cache
.
expire
(
'a'
,
10
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
self
.
assertAlmostEqual
(
ttl
,
10
)
def
test_expire_less
(
self
):
self
.
cache
.
set
(
'a'
,
'a'
,
timeout
=
20
)
self
.
cache
.
expire
(
'a'
,
10
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
self
.
assertAlmostEqual
(
ttl
,
10
)
def
test_expire_more
(
self
):
self
.
cache
.
set
(
'a'
,
'a'
,
timeout
=
10
)
self
.
cache
.
expire
(
'a'
,
20
)
ttl
=
self
.
cache
.
ttl
(
'a'
)
self
.
assertAlmostEqual
(
ttl
,
20
)
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