我目前正在使用Redis缓存我的数据库结果。我所做的是将db结果放入一个数组并序列化该数组,然后将它们作为值添加到Redis缓存中的键中。
$res = $this->db->query($qry);
foreach($res->result() as $row) {
$curArr[] = $row;
}
$this->redis->set($key, serialize($curArr));但是,每当我对缓存进行反序列化时,它都会在偏移量中返回错误。
$cache_result = $this->redis->get($key);
$curArr = unserialize($cache_result);
Message: unserialize(): Error at offset 8193 of 8701 bytes当我检查$cache_result时,字符串的长度是8702,8194处的字符是';‘。该部分的字符串片段是‘TEST3’;s:7‘。在$cache_result中也出现了该字符串片段的各种情况,但错误只出现在8193中。
非常感谢您的帮助!谢谢!
发布于 2014-06-25 20:30:08
为什么不这样做呢:$res = $this->db->query($qry); foreach($res->result() as $row) { $curArr[] = $row;
`} $this->redis->set($key, json_encode($curArr));` 检索时:
$cache_result = $this->redis->get($key);
$curArr = json_decode($cache_result);
https://stackoverflow.com/questions/17299014
复制相似问题