Commit 4833215c authored by Sean Bleier's avatar Sean Bleier

Fixing issue #48 where the backend was improperly casting string integers.

parent b4308765
......@@ -209,15 +209,12 @@ class CacheClass(BaseCache):
key = self.make_key(key, version=version)
if timeout is None:
timeout = self.default_timeout
try:
value = float(value)
# If you lose precision from the typecast to str, then pickle value
if int(value) != value:
raise TypeError
except (ValueError, TypeError):
# If ``value`` is not an int, then pickle it
if not isinstance(value, int):
result = self._set(key, pickle.dumps(value), int(timeout), client, _add_only)
else:
result = self._set(key, int(value), int(timeout), client, _add_only)
result = self._set(key, value, int(timeout), client, _add_only)
# result is a boolean
return result
......
......@@ -345,7 +345,7 @@ class RedisCacheTests(TestCase):
def test_string_float_caching(self):
self.cache.set('a', '1.1')
a = self.cache.get('a')
self.assertEqual(a, 1.1)
self.assertEqual(a, '1.1')
def test_multiple_connection_pool_connections(self):
pool._connection_pools = {}
......@@ -356,6 +356,12 @@ class RedisCacheTests(TestCase):
c3 = get_cache('redis_cache.cache://127.0.0.1:6379?db=15')
self.assertEqual(len(pool._connection_pools), 2)
def test_setting_string_integer_retrieves_string(self):
self.assertTrue(self.cache.set("foo", "1"))
self.assertEqual(self.cache.get("foo"), "1")
if __name__ == '__main__':
unittest.main()
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