consistent-hash
Implements consistent hashing that can be used when the number of server nodes can increase or decrease.The algorithm that is used for consistent hashing is the same as libketama <https://github.com/RJ/ketama>
Usage
It’s so easy to use^_^:
from consistent_hash import ConsistentHash
# You can construct consistent hash with the below three ways
con_hash = ConsistentHash({'192.168.0.101:11212':1, '192.168.0.102:11212':2, '192.168.0.103:11212':1})
# Or
con_hash = ConsistentHash(['192.168.0.101:11212', '192.168.0.102:11212', '192.168.0.103:11212']))
# Or
con_hash = ConsistentHash('192.168.0.101:11212')
# Add servers to hash ring
con_hash.add_nodes({'192.168.0.104:11212':1})
# Get a server via the key of object
server = con_hash.get_node('my_key')
# Delete the server from hash ring, you don't need to indicate weights
con_hash.del_nodes(['192.168.0.102:11212', '192.168.0.104:11212'])
Unit test
Firstly, install nose which extends unittest to make testing easier:
pip install nose
Then, run tests:
# Option -s any stdout output will be printed immediately # and -v be more verbose nosetests -s -v
More information about nose <https://nose.readthedocs.org/en/latest/>
Metadata
Release files for consistent_hash 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| consistent_hash-1.0.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| consistent_hash-1.0-py2.7.egg | Legacy Egg format | - | - | Details |
Total release size: 10.5 kB
Release files / consistent_hash-1.0.tar.gz
| Download URL | consistent_hash-1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9f88eff086680918b458b62994fbf07ef97736771f1e9f3b05855547636a7ac
|
|
BLAKE2b-256 checksum How to use checksums |
26bec87797f4c4d941486747997608c425d5a47e9fcc3da27759fd00488b0e2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / consistent_hash-1.0-py2.7.egg
| Download URL | consistent_hash-1.0-py2.7.egg |
|---|---|
| Size | 6.8 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
adc3bf7cba13dd2cabe50c5d4507d9a8a3ff2610b6801e88acf73d158946658d
|
|
BLAKE2b-256 checksum How to use checksums |
d4f49dfe91d8b7585e0b08c3ec11f7387bc996c6a721b7d3cd5cc9402436a80b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |