Skip to main content

About hash_ring

Implements consistent hashing that can be used when the number of server nodes can increase or decrease (like in memcached). The hashing ring is built using the same algorithm as libketama.

Consistent hashing is a scheme that provides a hash table functionality in a way that the adding or removing of one slot does not significantly change the mapping of keys to slots.

More about hash_ring can be read in a blog post (that explains the idea in greater details):

More information about consistent hashing can be read in these articles:

There is also a wrapper MemcacheRing that extends python-memcache to use consistent hashing for key distribution.

Example

Basic example of usage (for managing memcached instances):

memcache_servers = ['192.168.0.246:11212',
                    '192.168.0.247:11212',
                    '192.168.0.249:11212']

ring = HashRing(memcache_servers)
server = ring.get_node('my_key')

Example using weights:

memcache_servers = ['192.168.0.246:11212',
                    '192.168.0.247:11212',
                    '192.168.0.249:11212']
weights = {
    '192.168.0.246:11212': 1,
    '192.168.0.247:11212': 2,
    '192.168.0.249:11212': 1
}

ring = HashRing(memcache_servers, weights)
server = ring.get_node('my_key')

How to use MemcacheRing:

from hash_ring import MemcacheRing
mc = MemcacheRing(['127.0.0.1:11212'])
mc.set('hello', 'world')
print mc.get('hello')

The code should be clean and simple. Feel free to concat the author if you detect bugs.

Metadata

Release files for hash_ring 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hash_ring 1.2
File Size Uploaded Provenance Actions
hash_ring-1.2.tar.gz 3.9 kB Without provenance Details for hash_ring-1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hash_ring 1.2
File Interpreter ABI Platform Actions
hash_ring-1.2-py2.5.egg Legacy Egg format - - Details for hash_ring-1.2-py2.5.egg

Total release size: 16.6 kB

Release files / hash_ring-1.2.tar.gz

Download URL hash_ring-1.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c156121630c1cc5411ca91fad625e1ccaa7a51dd347ead6a8bda06bf556da9f5
BLAKE2b-256 checksum
How to use checksums
ba548b7bfaab16040a39faffaf699a5b61d9d8f386b0bedc134175b382323d7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / hash_ring-1.2-py2.5.egg

Download URL hash_ring-1.2-py2.5.egg
Size 12.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
ef48043edba210794568004cefec1d5f23261eab49ba86f70a833e6b262d119d
BLAKE2b-256 checksum
How to use checksums
9eeda39738b91643a38b221ed45cfc417223aaa01d23939e1da0515f83a34a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for hash_ring 1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page