-
-
Save pcdinh/5457581 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import binascii | |
import md5 | |
s0 = redis.Redis(port=6379) | |
s1 = redis.Redis(port=6380) | |
s2 = redis.Redis(port=6381) | |
s3 = redis.Redis(port=6382) | |
servers = [s0, s1, s2, s3] | |
def sharded_get(key): | |
i = binascii.crc32(key) % len(servers) | |
client = servers[i] | |
print "key: %s - index: %d - servers: %s" % (key, i, servers[i]) | |
return client.get(key) | |
sharded_get('test') | |
sharded_get('test1') | |
sharded_get('test10') | |
sharded_get('test100') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment