You might be able to use this: http://amix.dk/blog/post/19370
It encapsulates the python-memcache client class, so keys are allocated using sequential hashing.
EDIT - I am digging the source code for python-memcached 1.4.5, and it looks like it can actually support sequential hashing. Relevant Code:
from binascii import crc32 # zlib version is not cross-platform def cmemcache_hash(key): return((((crc32(key) & 0xffffffff) >> 16) & 0x7fff) or 1) serverHashFunction = cmemcache_hash -- SNIP -- def _get_server(self, key): if isinstance(key, tuple): serverhash, key = key else: serverhash = serverHashFunction(key) for i in range(Client._SERVER_RETRIES): server = self.buckets[serverhash % len(self.buckets)] if server.connect(): #print "(using server %s)" % server, return server, key serverhash = serverHashFunction(str(serverhash) + str(i)) return None, None
Based on this code, it looks like it implements an algorithm if cmemcache_hash not a meaningful name and is not a real algorithm. (now resigned cmemcache does serial hashing)
But I think the OP refers to more "robust" sequential hashing, for example. libketama . I donβt think there is a solution there to solve this problem, it looks like you need to roll up your sleeves, compile / install a more advanced memcached lib, for example pylibmc, and write a custom Django backend that uses this instead of python-memcached.
Anyway, in any case, some reassignment of keys will happen when you add / remove buckets to the pool (even with libketama, which is less than with other algorithms)
source share