joelcox / codeigniter-redis

A CodeIgniter library to interact with Redis
MIT License
240 stars 142 forks source link

Set json string as value #41

Closed jonathanwiesel closed 11 years ago

jonathanwiesel commented 11 years ago

I'm trying the following

$value = json_encode($jsonArrayed); $response = $redis->command('set test ' .$value);

But I get bad syntax error. I've also tried with

$value = '\''.json_encode($jsonArrayed).'\''; $value = '\''.addslashes(json_encode($jsonArrayed)).'\'';

But no luck.

Any idea how to set a json string as a value?

danhunsaker commented 11 years ago

Generally speaking, your string should be quoted in the command() string, so $redis->command('set test "' . $value . '"'); would be your function call.

That said, using command() is not the preferred method of using CI-Redis - instead, use $redis->set('test', $value); and the class will take care of all the escaping and other such tricks on your behalf.

danhunsaker commented 11 years ago

(Also, it should be $this->redis->set(...) instead of $redis->set(...), but I'm guessing you know that, working with CI...)

jonathanwiesel commented 11 years ago

Thank you very much, dumb of me, I should have tried using the set function in the first place, worked perfectly.

About the use of $redis->... instead of $this->redis->... was because I implemented a constructor in the library and was using the $redis variable for the object:

$redis = new CI_Redis();
jonathanwiesel commented 11 years ago

I noticed that setting a json as a value went good.

However when I try to get it, the response becomes truncated (no fixed size), one with more than 3500 characters came good but other with 2800 was truncated.

Looking at the database through the terminal I can see that the values are indeed complete so the truncation process may be happening in the parser that receives the 'get' call back to CodeIgniter.

danhunsaker commented 11 years ago

See issues #39 and #40...