Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
 def __init__(self, hosts):
     BaseRedisRouter.__init__(self, hosts)
     self._hashring = HashRing(hosts.values())
Пример #6
0
 def __init__(self, hosts):
     BaseRedisRouter.__init__(self, hosts)
     self._hashring = HashRing(hosts.values())