Predis不保存JSON字符串的部分内容

时间:2013-05-11 21:03:56

标签: json redis predis

我正在尝试使用Predis库将Cakephp中的$ _SESSION的JSON表示(json_encode)保存到Redis中。

这是$ _SESSION raw:

{ ["Config"]=> array(3) { ["userAgent"]=> string(32) "ebbd08f362083e95a8eb3bd1d4712648" ["time"]=> int(1368391599) ["countdown"]=> int(10) } ["Auth"]=> array(1) { ["User"]=> array(24) { ["id"]=> string(2) "93" ["user_group_id"]=> string(1) "1" ["first_name"]=> string(5) "James" ["about"]=> NULL ["phone"]=> NULL ["img_path"]=> string(28) "93_1368161032_1368161032.jpg" ["score"]=> string(4) "0.00" ["active"]=> string(1) "0" ["created"]=> NULL ["modified"]=> string(19) "2013-03-13 04:14:36" ["fbid"]=> string(1) "0" ["twid"]=> NULL ["location"]=> string(0) "" ["hometown"]=> string(0) "" ["iteneraries"]=> string(1) "2" ["place_visited"]=> string(1) "0" ["reviews"]=> string(1) "0" ["isName"]=> bool(false) ["isAddress"]=> bool(false) ["invite_code"]=> string(7) "SK47SLE" } } }  

在json_decode之后:

{"Config":{"userAgent":"ebbd08f362083e95a8eb3bd1d4712648","time":1368391599,"countdown":10},"Auth":{"User":{"id":"93","user_group_id":"1","first_name":"James","about":null,"phone":null,"img_path":"93_1368161032_1368161032.jpg","score":"0.00","active":"0","created":null,"modified":"2013-03-13 04:14:36","fbid":"0","twid":null,"location":"","hometown":"","iteneraries":"2","place_visited":"0","reviews":"0","isName":false,"isAddress":false,"invite_code":"SK47SLE"}}}

redis的相关代码设置值:

public function write($id, $data) {
    $tmp = $_SESSION;
    session_decode($data);

    $tmp_data = json_encode($_SESSION);
    $_SESSION = $tmp;
    $this->_client->set($id, $tmp_data);
}

当我在调用set后检查redis时,只保存了这些部分:

 {"Config":{"userAgent":"ebbd08f362083e95a8eb3bd1d4712648","time":1368391599,"countdown":10}}

其余的JSON数据被截断/不保存到redis。这可能是什么问题?在将JSON设置为redis时,我有什么想念。

0 个答案:

没有答案