A consistent hash implementation in python
Project description
Consistent Hashing
Consistent hashing is used in distributed systems to efficiently distribute data among multiple nodes while minimizing reorganization when nodes are added or removed.It maps both data and nodes onto a common hash space (typically a circle), where each node is responsible for the data that falls within its range on the circle.
Features
- This library use md5 from hashlib. Get the string value (hex digest) and convert it into a string
- Two maps are maintained by this library a. Map to identify the hash of nodes adding to the ring b. Map to identify which keys are part of what nodes
Usage
consistent_hashing_impl = ConsistentHashingImpl()
consistent_hashing_impl.add_node("node1")
consistent_hashing_impl.add_node("node2")
consistent_hashing_impl.add_node("node3")
print("Key will be stored in node :%s" % consistent_hashing_impl.get_node_for_data("python"))
print("Key will be stored in node :%s" % consistent_hashing_impl.get_node_for_data("Java"))
The above code will generate the following output
2024-07-09 00:01:34,035: Generating hash for key: node1
2024-07-09 00:01:34,035: Generating hash for key: node2
2024-07-09 00:01:34,035: Generating hash for key: node3
2024-07-09 00:01:34,035: Generating hash for key: python
Key will be stored in node :node2
2024-07-09 00:01:34,035: Generating hash for key: Java
Key will be stored in node :node1
Installation
pip install py-consistent-hash==1.0.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_consistent_hash-1.0.1.tar.gz.
File metadata
- Download URL: py_consistent_hash-1.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c53979004b06d4945aba632d55becc3e02d8f60c8143250ef59afc34809bc6c6
|
|
| MD5 |
1d71be40c3a16596984b61a6475aec57
|
|
| BLAKE2b-256 |
679086a9043ea155226f815b4e583575459aea9b8e9bc38bbdcfbe718f1e497e
|
File details
Details for the file py_consistent_hash-1.0.1-py3-none-any.whl.
File metadata
- Download URL: py_consistent_hash-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69f79a6bc390b3b0daff86fc991d806bfc934afb1f2277d5e302ae7d86c976e5
|
|
| MD5 |
d3a919405aa5bfb5439b3b1222e0a191
|
|
| BLAKE2b-256 |
dbe2c51041c3247d6c432440aa4adf62cf66d231e91d0086832d5eff3fdbbd25
|