ConsistentHashr
A small module to do easy consistent hashing.
Usage
hashr = ConsistentHashr.new()
hashr.add_server(“s1”, “server1”) hashr.add_server(“s2”, “server2”) hashr.add_server(“s3”, “server3”) hashr.add_server(“s4”, “server4”) hashr.add_server(“s5”, “server5”)
hashr.get(key) # Should return the same key consistently when new servers are added.
Implementation
Based on “Mike Perham’s”:www.mikeperham.com/ “code”:www.mikeperham.com/2009/01/14/consistent-hashing-in-memcache-client/ and tests. I thought this layer didn’t belong to any specific client, this is why I extracted it.
Greatly inspired by “Tom White’s consistent hashing explaination”:weblogs.java.net/blog/tomwhite/archive/2007/11/consistent_hash.html.