jaysonsantos / python-binary-memcached

A pure python module (thread safe) to access memcached via it's binary protocol with SASL auth support.
MIT License
165 stars 57 forks source link

DistributedClient hashing is not consistent #236

Closed MiguelCarranza closed 4 years ago

MiguelCarranza commented 4 years ago

When initializing more than one DistributedClient with the same servers, the hashing for the keys is not consistent. Each client will potentially yield a different server for the same key.

The problem seems to be that when creating the HashRing, it uses the Protocol class:

 self._ring = HashRing(self._servers)

Steps to reproduce:

from bmemcached import DistributedClient

client = DistributedClient('localhost:11211,localhost:11212,localhost:11213'.split(','))
client.set('the_key', '1234556') # Server with port 11213

client = DistributedClient('localhost:11211,localhost:11212,localhost:11213'.split(','))
client.set('the_key', '1234556') # Server with port 11211

When using HashRing directly with the server strings, it works as expected

from uhashring import HashRing
hr = HashRing('localhost:11211,localhost:11212,localhost:11213'.split(','))
hr.get_node('the_key') # localhost:11213

from uhashring import HashRing
hr = HashRing('localhost:11211,localhost:11212,localhost:11213'.split(','))
hr.get_node('the_key') # localhost:11213