memcache客户端“一致性hash算法”设置 Memcache 修改php.ini添加: [Memcache] Memcache.allow_failover = 1 Memcache.hash_strategy =consistent Memcache.hash_function =crc32 ini_set方法: Ini_set(‘memcache.hash_strategy',' consistent '); Ini_set(‘memcache.hash_function','crc32'); Memcached $mem = new memcached(); $mem->addServers(array(array('10.8.8.32',11300,100),array('10.8.8.32',11301,0))); $mem->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); $mem->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC); for ($i=0;$i<10;$i++){ $key = "item_$i"; $arr = $mem->getServerByKey($key); echo ($key.":\t".$arr['port']."\n"); } print_r($mem->getServerList()); (责任编辑:IT) |