<code>PHP使用Memcached的扩展addServers使用权重,但是结果还是1:1,权重10:0,请问是什么原因呢? </code>
<code><?php /** * 测试memcache一致性hash * 使用docker运行 * * docker pull memcached * docker stop memcache-01 * docker stop memcache-02 * docker rm memcache-01 * docker rm memcache-02 * docker run --name memcache-01 -p 11201:11211 -d memcached * docker run --name memcache-02 -p 11202:11211 -d memcached */ $mem = new Memcached; $mem->addServers( [ // ['192.168.33.4',11201,10], ['192.168.33.4',11202,0] ] ); //$mem->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); //$mem->setOption(Memcached::OPT_HASH, Memcached::HASH_MD5); for($i=0;$i<10000;$i++){ $key = md5(uniqid($i.'_')); $mem->add($key,'1'); } </code>
<code>PHP使用Memcached的扩展addServers使用权重,但是结果还是1:1,权重10:0,请问是什么原因呢? </code>
<code><?php /** * 测试memcache一致性hash * 使用docker运行 * * docker pull memcached * docker stop memcache-01 * docker stop memcache-02 * docker rm memcache-01 * docker rm memcache-02 * docker run --name memcache-01 -p 11201:11211 -d memcached * docker run --name memcache-02 -p 11202:11211 -d memcached */ $mem = new Memcached; $mem->addServers( [ // ['192.168.33.4',11201,10], ['192.168.33.4',11202,0] ] ); //$mem->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); //$mem->setOption(Memcached::OPT_HASH, Memcached::HASH_MD5); for($i=0;$i<10000;$i++){ $key = md5(uniqid($i.'_')); $mem->add($key,'1'); } </code>
Conclusion:
1 weight is only effective when using consistent hashing
2 OPT_LIBKETAMA_COMPATIBLE must be used for consistent hashing
*
Question: Two parameters must be effective at the same time, why do they need to be 2?