matterkkila/pykestrel — Issue #1: Server Selection does not follow the Kestrel Spec
Author: ericmoritz
Created: 2011-12-01 21:32:27+00:00
State: open

Servers are selected using python-memcached's _get_server(self, key) method. This method selects a server using the following way:

crc32(key) % len(self.buckets)

The [Kestrel guide](https://github.com/robey/kestrel/blob/master/docs/guide.md) says the following:

Clients have a list of all servers in the cluster, and pick one at random for each operation

Here's some code I wrote for _get_server() (sorry cut and paste is faster than a pull request):

def _get_server(self, key):
if type(key) == types.TupleType:
serverhash, key = key
else:
serverhash = random.randint(0, len(self.buckets))

for i in range(memcache.Client._SERVER_RETRIES):
server = self.buckets[serverhash % len(self.buckets)]
if server.connect():
return server, key
serverhash = random.randint(0, len(self.buckets))
return None, None