简体   繁体   English

Memcached不保存生成的数据

[英]Memcached does not save generated data

I got the following code which should save the query data to the Memcached if called and store it there for 600ms. 我得到以下代码,该代码应在调用时将查询数据保存到Memcached并将其存储600ms。 But every time i load the page the $response is empty and the var_dump says MISS. 但是每次我加载页面时, $response为空,并且var_dump说MISS。 Any ideas what i'm doing wrong? 任何想法我在做什么错? The Memcached Server is on port 11211 as ps aux | grep memcached Memcached服务器位于端口11211上,为ps aux | grep memcached ps aux | grep memcached tells me. ps aux | grep memcached告诉我。

$memcache = new Memcached();
$memcache->addServer("127.0.0.1", 11211);
$response = $memcache->get("test");
var_dump($response);
if ($response) {
    var_dump('HIT');
    $result = $response;
} else {
   var_dump('MISS');
   $sql = 'SELECT * FROM test WHERE bla BETWEEN "'.esc_sql($start).'" AND "'.esc_sql($end).'" ORDER BY datumbekanntgabe ASC';

   $result = $this->mydb->get_results($sql);
   $memcache->set("test", $result, 0, 600);
}
return $result;

It looks as though it was using 0 as the timeout, in the call... 看起来好像在通话中使用0作为超时...

$memcache->set("test", $result, 0, 600);

In memcache , the third parameter - 0 is a flag used for compression, whilst the fourth is the timeout, in memcached though this flag isn't present, so the call should be memcache中 ,第三个参数-0是用于压缩的flag ,而第四个参数是超时,在memcached中,尽管该标志不存在,所以调用应为

$memcache->set("test", $result, 600);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM