Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed the _multi API calls

  • Loading branch information...
commit a6406eb2982e39ab86fd439159519d4e6341497d 1 parent d4bf33b
@tarekziade tarekziade authored
Showing with 30 additions and 5 deletions.
  1. +12 −5 memcachepool/cache.py
  2. +18 −0 memcachepool/tests/test_cache.py
View
17 memcachepool/cache.py
@@ -73,15 +73,21 @@ def get_many(self, keys, version=None):
return {}
new_keys = map(lambda x: self.make_key(x, version=version), keys)
+
+ ret = {}
with self._pool.reserve() as conn:
- ret = conn.get_multi(new_keys)
+ for key in new_keys:
+ res = conn.get(key)
+ if res is None:
+ continue
+ ret[key] = conn.get(key)[0]
if ret:
res = {}
m = dict(zip(new_keys, keys))
for k, v in ret.items():
- res[m[k]] = serialize(v)
+ res[m[k]] = unserialize(v)
return res
@@ -130,12 +136,13 @@ def set_many(self, data, timeout=0, version=None):
safe_data[key] = serialize(value)
with self._pool.reserve() as conn:
- conn.set_multi(safe_data, self._get_memcache_timeout(timeout))
+ for key, value in safe_data.items():
+ conn.set(key, value, self._get_memcache_timeout(timeout))
def delete_many(self, keys, version=None):
- l = lambda x: self.make_key(x, version=version)
with self._pool.reserve() as conn:
- conn.delete_multi(map(l, keys))
+ for key in keys:
+ conn.delete(self.make_key(key, version=version))
def clear(self):
with self._pool.reserve() as conn:
View
18 memcachepool/tests/test_cache.py
@@ -17,3 +17,21 @@ def test_pool(self):
# like python-memcached does
cache.set('a', 1)
self.assertEqual(cache.get('a'), 1)
+ cache.delete('a')
+ self.assertEqual(cache.get('a'), None)
+
+ def test_many(self):
+ # make sure all the 'many' APIs work
+ from memcachepool.cache import UMemcacheCache
+
+ # creating the cache class
+ cache = UMemcacheCache('127.0.0.1:11211', {})
+
+ cache.set_many({'a': 1, 'b': 2})
+
+ res = cache.get_many(['a', 'b']).values()
+ self.assertTrue(1 in res)
+ self.assertTrue(2 in res)
+
+ cache.delete_many(['a', 'b'])
+ self.assertEqual(cache.get_many(['a', 'b']), {})
Please sign in to comment.
Something went wrong with that request. Please try again.