I have started to work with laravel. It is quite interesting to work. I have started to use the features of laravel. I have started to use
redis by install redis server in my system and change the configuration for redis in
app/config/database.php file. The redis is working fine for the single variables by using
$redis = Redis::connection(); $redis->set('name', 'Test');
and i could able to get the value by using
But i want to set the array by using
set function. If i try do that getting the following error
strlen() expects parameter 1 to be string, array given
I have tried by using following codes.
$redis->set('name', array(5, 10)); $values = $redis->lrange('names', array(5, 10));
and if i use
$values = $redis->command('lrange', array(5, 10));
getting the following error
'command' is not a registered Redis command
Can any one explain me the problem and is that possible with redis?…we can set the array values using
This has been answered in the comments but to make the answer clearer for people visiting in the future.
Redis is language agnostic so it won’t recognise any datatype specific to PHP or any other language. The easiest way would be to
json_encode the data on set then
json_decode on get.
Example to store data using
$redis = Redis::connection(); $redis->set('user_details', json_encode(array('first_name' => 'Alex', 'last_name' => 'Richards' ) ) );
Example to retrieve data using
$redis = Redis::connection(); $response = $redis->get('user_details'); $response = json_decode($response);