Clandestined Rendezvous Hashing

1.1.0 · maintenance · verified Sat Apr 11

Clandestined is a Python library that implements rendezvous hashing, also known as highest random weight (HRW) hashing. It provides a distributed algorithm for choosing a node from a set of available nodes, ensuring that a minimal number of mappings change when nodes are added or removed. It's built upon the murmur3 hash function. The current version is 1.1.0, and the project's release cadence has been infrequent since its last update in 2016.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `RendezvousHash` with a set of nodes, find the responsible node for a given key, and dynamically add or remove nodes while maintaining consistent hashing properties.

from clandestined import RendezvousHash

# Initialize with a list of node IDs
rh = RendezvousHash(['node-a', 'node-b', 'node-c'])

# Find the appropriate node for a given key
key_to_hash = 'user_session_123'
assigned_node = rh.find_node(key_to_hash)
print(f"Key '{key_to_hash}' assigned to: {assigned_node}")

# Add a new node
rh.add_node('node-d')
new_assigned_node = rh.find_node(key_to_hash)
print(f"After adding node-d, key '{key_to_hash}' assigned to: {new_assigned_node}")

# Remove a node
rh.remove_node('node-a')
final_assigned_node = rh.find_node(key_to_hash)
print(f"After removing node-a, key '{key_to_hash}' assigned to: {final_assigned_node}")

view raw JSON →