python有一个python模块--hash_ring,即python中的一致性hash,使用起来也挺简单。
可以参考下官方例子:https://pypi.python.org/pypi/hash_ring/
1 Basic example of usage (for managing memcached instances): 2 3 memcache_servers = ['192.168.0.246:11212', 4 '192.168.0.247:11212', 5 '192.168.0.249:11212'] 6 7 ring = HashRing(memcache_servers) 8 server = ring.get_node('my_key') 9 Example using weights: 10 11 memcache_servers = ['192.168.0.246:11212', 12 '192.168.0.247:11212', 13 '192.168.0.249:11212'] 14 weights = { 15 '192.168.0.246:11212': 1, 16 '192.168.0.247:11212': 2, 17 '192.168.0.249:11212': 1 18 } 19 20 ring = HashRing(memcache_servers, weights) 21 server = ring.get_node('my_key')