def test_basic(): nodes = ['node01', 'node02', 'node03', 'node04'] hashring = HashRing(nodes) keys = ['key-%s' % i for i in range(1000)] keys_nodes = [hashring.get_node(k) for k in keys] for node in nodes: assert node in keys_nodes
def test_basic(): nodes = ["node01", "node02", "node03", "node04"] hashring = HashRing(nodes) keys = [u"key-%s" % i for i in range(500)] keys_nodes = [hashring.get_node(k) for k in keys] for node in nodes: assert node in keys_nodes keys = ["key-%s" % i for i in range(500, 1000)] keys_nodes = [hashring.get_node(k) for k in keys] for node in nodes: assert node in keys_nodes
class RedisConsistentHashRouter(BaseRedisRouter): """Use ketama for hash partitioning.""" def __init__(self, hosts): BaseRedisRouter.__init__(self, hosts) self._hashring = HashRing(hosts.values()) def get_host_for_key(self, key): node = self._hashring.get_node(key) if node is None: raise RuntimeError('Can not find a host using consistent hash') return node.host_name
def __init__(self, hosts): BaseRedisRouter.__init__(self, hosts) self._hashring = HashRing(hosts.values())