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
0f6a8353
Commit
0f6a8353
authored
May 06, 2014
by
Sean Bleier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds custom 'has_key' implementation using redis's 'exists' command.
parent
0921e2e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
cache.py
redis_cache/cache.py
+7
-0
tests.py
tests/testapp/tests.py
+7
-0
No files found.
redis_cache/cache.py
View file @
0f6a8353
...
...
@@ -333,6 +333,13 @@ class CacheClass(BaseCache):
return
self
.
_client
.
ttl
(
key
)
return
0
def
has_key
(
self
,
key
,
version
=
None
):
"""
Returns True if the key is in the cache and has not expired.
"""
key
=
self
.
make_key
(
key
,
version
=
version
)
return
self
.
_client
.
exists
(
key
)
class
RedisCache
(
CacheClass
):
"""
...
...
tests/testapp/tests.py
View file @
0f6a8353
...
...
@@ -418,6 +418,13 @@ class RedisCacheTests(TestCase):
ttl
=
self
.
cache
.
ttl
(
'does_not_exist'
)
self
.
assertEqual
(
ttl
,
0
)
def
test_has_key_with_no_key
(
self
):
self
.
assertFalse
(
self
.
cache
.
has_key
(
'does_not_exist'
))
def
test_has_key_with_key
(
self
):
self
.
cache
.
set
(
'a'
,
'a'
)
self
.
assertTrue
(
self
.
cache
.
has_key
(
'a'
))
if
__name__
==
'__main__'
:
import
unittest
...
...
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