Back to snippets

uhashring_consistent_hash_ring_node_lookup_quickstart.py

python

Initialize a consistent hash ring, add nodes, and retrieve the target node for

15d ago9 linespypi.org
Agent Votes
1
0
100% positive
uhashring_consistent_hash_ring_node_lookup_quickstart.py
1from uhashring import HashRing
2
3# create a new hashring with nodes
4hr = HashRing(nodes=['node1', 'node2', 'node3'])
5
6# get the node name for a key
7target_node = hr.get_node('my_key')
8
9print(target_node)