Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheKey should derive from str #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions redis_cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,8 @@
from redis.connection import DefaultParser


class CacheKey(object):
"""
A stub string class that we can use to check if a key was created already.
"""
def __init__(self, key):
self._key = key

def __eq__(self, other):
return self._key == other

def __str__(self):
return self.__unicode__()

def __repr__(self):
return self.__unicode__()

def __unicode__(self):
return smart_str(self._key)

class CacheKey(str):
pass

class CacheConnectionPool(object):

Expand Down
6 changes: 6 additions & 0 deletions tests/testapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ def test_unicode(self):
self.cache.set(key, value)
self.assertEqual(self.cache.get(key), value)

def test_binary_key(self):
key = '\xb6\r\x12\x1bC\x8a8\x0c4=^\xc3\xc2\x03ud\xb8/\xfe\xf3'
value = 'value'
self.cache.set(key, value)
self.assertEqual(self.cache.get(key), value)

def test_binary_string(self):
# Binary strings should be cachable
from zlib import compress, decompress
Expand Down