我正在尝试在PHP中测试memcached客户端的multi_get
功能,我知道
array Memcache::get ( array $keys [, array &$flags ] )
可用。
00000001 <?php
00000002 function rand01()
00000003 { // auxiliary function
00000004 // returns random number with flat distribution from 0 to 1
00000005 return (float)rand()/(float)getrandmax();
00000006 }
00000007 ini_set('display_errors', 1);
00000008 $mc=new Memcached();
00000009 $mc->setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);
00000010 $mc->setOption(Memcached::OPT_REMOVE_FAILED_SERVERS,true);
00000011 echo "return value of addServer<br>";
00000012 var_dump($mc->addServer("mc1",11211));
00000013 var_dump($mc->addServer("mc2",11211));
00000014 var_dump($mc->addServer("mc3",11211));
00000015 echo "<br>";
00000016 $mc->set('00010111222',"testval");
00000017 $mc->set('00010333444',"testval");
00000018 echo "<br>";
00000019 var_dump($mc->get(array('00010111222', '00010333444')));
00000020 var_dump($mc->getResultCode());
00000023 ?>
但它给了我以下输出:
return value of addServer
bool(true) bool(true) bool(true)
Warning: Memcached::get() expects parameter 1 to be string, array given in /var/www/html/memcache.php on line 19
NULL int(0)
这意味着服务器已成功添加,但第19行中的get()
会给出一个数组参数警告,返回的对象为NULL。返回代码为0表示查询成功,并且密钥存在于memcached中,因为我在第16行和第17行设置它们。有什么我做错了或者这是PHP :: Memcache中的错误吗?
答案 0 :(得分:1)
这是Memcache
与Memcached
问题。
Memcached::get
只接受一个字符串作为第一个参数。
http://php.net/manual/en/memcached.get.php
Memcache::get
是接受字符串或数组的方法。
http://php.net/manual/en/memcache.get.php
您可以完成与循环数组相同的结果,并为每个值调用Memcached::get($key)
。