在池中使用多个Memcache服务器 [英] Using multiple memcache servers in a pool
问题描述
我正在阅读文档,如果指定了多台服务器,则对于内存缓存如何进行内部负载平衡感到有些困惑.例如:
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")
键"some_key"的设置和检索是否总是在同一台服务器上进行?备用键(例如"some_key_2"或"some_key_3")的设置和检索是否会自动分配到服务器池中?如果添加或删除服务器会发生什么?
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?
类似地,get_multi会发生什么:
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?
谢谢.
推荐答案
memcached基于密钥的哈希将密钥放置在服务器上.只要您的服务器设置不变,那么给定的密钥将始终落在给定的服务器上.
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.
这篇关于在池中使用多个Memcache服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!