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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化