I'm going through the documentation and I'm a little confused as to how memcache does internal load-balancing if multiple servers are specified. For example:
import memcache
mc.set_servers(['127.0.0.1:11211','127.0.0.1:11212',])
mc.set("some_key", "Some value")
print mc.get("some_key")
Will the setting and retrieval of key "some_key" always hit the same server? Will the setting and retrieval of alternate keys, such as "some_key_2" or "some_key_3," automatically be distributed amongst the pool of servers? What happens if a server is added or deleted?
Similarly, what happens with get_multi:
import memcache
mc.set_servers(['127.0.0.1:11211','127.0.0.1:11212',])
mc.set_multi({42: 'adams', 46 : 'and of me'})
print mc.get_multi([46, 42])
Will this automatically set and retrieve each key from the right server? Is it necessary to write a wrapper class?
Thanks.
memcached places keys on servers based on a hash of the key. As long as your server setup doesn't change, then a given key will always land on a given server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With