From 63dd3ac3a42ea0c77f676b84147975be9510ba19 Mon Sep 17 00:00:00 2001 From: idan Date: Thu, 9 May 2013 09:52:37 +0300 Subject: [PATCH] Make CacheKey derive directly from str --- redis_cache/cache.py | 21 ++------------------- tests/testapp/tests.py | 6 ++++++ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/redis_cache/cache.py b/redis_cache/cache.py index c469b45c..98f5220a 100644 --- a/redis_cache/cache.py +++ b/redis_cache/cache.py @@ -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): diff --git a/tests/testapp/tests.py b/tests/testapp/tests.py index 48fb6944..3f2687a5 100644 --- a/tests/testapp/tests.py +++ b/tests/testapp/tests.py @@ -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