//按照Key值,获取一个服务器ID
intgetServerId(char*key, intserverTotal){
intc, hash = 0;
while(c = *key++) {
hash+= c;
}
returnhash % serverTotal;
}
//服务器列表
node[0] => 192.168.0.1:11211
node[1] => 192.168.0.2:11211
node[2] => 192.168.0.3:11211
//获取key是test的节点ID(服务器ID)
intid = getServerId("test",3);
//得出的结果是1,那么对应的机器就是
node[id] == node[1]