Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (56 sloc) 2.74 KB
Metadata-Version: 1.0
Name: hash_ring
Version: 1.2
Summary: Implements consistent hashing in Python (using md5 as hashing function).
Author: Amir Salihefendic
License: BSD
Description: 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):
* Consistent hashing implemented simply in python <>
More information about consistent hashing can be read in these articles:
* Web Caching with Consistent Hashing <>
* Consistent hashing and random trees <>
There is also a wrapper MemcacheRing that extends python-memcache to use consistent hashing
for key distribution.
Basic example of usage (for managing memcached instances)::
memcache_servers = ['',
ring = HashRing(memcache_servers)
server = ring.get_node('my_key')
Example using weights::
memcache_servers = ['',
weights = {
'': 1,
'': 2,
'': 1
ring = HashRing(memcache_servers, weights)
server = ring.get_node('my_key')
How to use MemcacheRing::
from hash_ring import MemcacheRing
mc = MemcacheRing([''])
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.
Keywords: memcached hashing hash consistent
Platform: Any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Jump to Line
Something went wrong with that request. Please try again.