dounue1965
2016-11-19 04:23
浏览 69
已采纳

Memcache ::不使用键数组

I am trying to test the multi_get functionality of memcached client in PHP, and I know that

array Memcache::get ( array $keys [, array &$flags ] )

is available.

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 ?>

But it gives me the following output:

   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)

Which means that the servers are successfully added, but get() in line 19 gives a warning for parameter being an array and the returned object is NULL. The return code is 0 which means that query was successful, and keys are present in memcached since I am setting them in line 16 and 17. Is there something I am doing wrong or is this a bug in PHP::Memcache?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试用PHP测试memcached客户端的 multi_get 功能,我知道

 数组Memcache :: get(array $ keys [,array&amp; $ flags])
   
 
 

是可用的。

  00000001&lt;?php 
00000002 function rand01()
 
00000003 {//辅助函数
00000004 //返回平面分布从0到1的随机数
 
 
00000005 return(  float)rand()/(float)getrandmax(); 
 n00000006} 
 n00000007 ini_set('display_errors',1); 
 n00000008 $ mc = new Memcached(); 
 n00000009 $ mc-&gt; setOption(Memcached :: OPT_DISTRIBUTION  ,Memcached :: DISTRIBUTION_CONSISTENT); 
 
00000010 $ mc-&gt; setOption(Memcached :: OPT_REMOVE_FAILED_SERVERS,true); 
 n00000011 echo“addServer的返回值&lt; br&gt;”; 
 
00000012 var_dump($ mc-&gt; addServer(“mc1  “,11211)); 
 
00000013 var_dump($ mc-&gt; addServer(”mc2“,11211)); 
 n00000014 var_dump($ mc-&gt; addServer(”mc3“,11211)); 
 
00000015 echo”&lt;  br&gt;“;; 
 
00000016 $ mc-&gt; set('00010111222',”testval“); 
 
00000017 $ mc-&gt; set('00010333444',”testval“); 
 
00000018 echo”&lt; br&gt;“;  
00000019 var_dump($ mc-&gt; get(array('00010111222','00010333444'))); 
 n00000020  var_dump($ mc-&gt; getResultCode()); 
00000023?&gt; 
   
 
 

但是它给了我以下输出:

 返回addServer的值
 bool(true)bool(true)bool(true)
警告:Memcached :: get()期望参数1为字符串,数组在/ var / www / html中给出 第19行上的/memcache.php 
 NULL int(0)
   
 
 

这意味着服务器已成功添加,但 get()第19行给出一个警告,参数是一个数组,返回的对象是NULL。 返回代码为0表示查询成功,并且密钥存在于memcached中,因为我在第16行和第17行设置它们。有什么我做错了或者这是PHP :: Memcache中的错误吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongsi2317 2016-11-19 06:34
    最佳回答

    This is a Memcache vs. Memcached issue.

    Memcached::get accepts only a string as the first argument.

    http://php.net/manual/en/memcached.get.php

    Memcache::get is the method that accepts a string or an array.

    http://php.net/manual/en/memcache.get.php

    You can accomplish the same result as looping through the array and calling Memcached::get($key) for each value.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题