0

I'm trying to save a JSON representation (json_encode) of $_SESSION in Cakephp into Redis using Predis library.

Here is the $_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" } } }  

After 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"}}}

Relevant code setting value to redis:

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

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

When I checked on redis after calling set, only this parts is saved:

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

The rest of the JSON data is cut-off/not saved to redis. What might be the problem with this? Is there something I miss during setting the JSON to redis.

j0k
  • 22,600
  • 28
  • 79
  • 90
James
  • 726
  • 2
  • 7
  • 20
  • try saving a string literal that you posted, not getting it from session, but just hard code it. does this happen then? does this happen when you do it from the command line (`redis-cli`)? Is the code that READS from the key correct? – akonsu May 13 '13 at 05:35
  • @akonsu Works fine when I hardcoded the json string in redis-cli. – James May 13 '13 at 16:09
  • what happens when you write a hard coded string in your program? – akonsu May 13 '13 at 18:32
  • If I hardcoded the string, it is save properly. – James May 14 '13 at 06:53

0 Answers0