tooz/examples/hashring.py
Julien Danjou e29ca79ed9 Add a hashring implementation
This is a consistent hash ring implementation based on the one that can
be found in Nova, Ironic, Ceilometer and Aodh.

Change-Id: I5d2f4efcd354a187747fa645482db2029a1a14b7
2016-12-07 23:40:35 +01:00

16 lines
523 B
Python

from tooz import hashring
hashring = hashring.HashRing({'node1', 'node2', 'node3'})
# Returns set(['node2'])
nodes_for_foo = hashring[b'foo']
# Returns set(['node2', 'node3'])
nodes_for_foo_with_replicas = hashring.get_nodes(b'foo',
replicas=2)
# Returns set(['node1', 'node3'])
nodes_for_foo_with_replicas = hashring.get_nodes(b'foo',
replicas=2,
ignore_nodes={'node2'})