Memcache + Mysqli Couldn't fetch mysqli_result


Memcache + Mysqli Couldn't fetch mysqli_result

我正试图为我正在使用memcache的项目添加一些速度性能。然而,我有一个问题与以下

    public function sql_query($query){
    $memcache = new Memcache;
    $memcache->connect('localhost', 11211) or die ("Could not connect");
    $memkey = md5($query);
    $get_result = $memcache->get($memkey);
    if ($get_result){
        return $get_result;
    } else {
        $q = $this->mysqli->query($query);
        $memcache->set($memkey, $q, false, 120) or die ("Failed to save data at the server");
        if ($this->mysqli->error){
          App::Error($this->mysqli->error);
        }
        return $q;
    }
}

它当然是把一些东西放入memcached,但当我把它拉出来并使用它时,我得到这个错误,如果它不是从缓存。

"Warning: mysqli_result::fetch_assoc(): Couldn't fetch mysqli_result"

我错过了什么吗?我确信我以前以类似的方式使用过memcache,没有任何问题。

您不能将所有的数据类型存储到memcached(和其他数据存储)中,其中最经常不起作用的是资源文档,例如数据库链接或结果标识符。

您存储了这样的值,但在另一个请求中又将其取出。但是,由于数据库已经处于另一种状态,因此该资源不再工作。你会得到错误。

相反,您需要存储查询的结果数据,这是可以放入memcache的静态数据。