Commit 0f6a8353 authored by Sean Bleier's avatar Sean Bleier

Adds custom 'has_key' implementation using redis's 'exists' command.

parent 0921e2e6
......@@ -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):
"""
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment