Search code examples
phplaravelcachingredislumen

Redis Laravel - strlen() expects parameter 1 to be string, array given


I am trying to cache data in Redis but getting following error:

ErrorException: strlen() expects parameter 1 to be string, array given /home/mktplacemiddleware/demo/vendor/predis/predis/src/Connection/StreamConnection.php:390

Following is the code i am trying:

Redis::set('CacheTest', $finalProduct); //$finalProduct is an Array

I am using:

  1. redis version 5.5
  2. predis version 1.1
  3. php version 7.1
  4. laravel Lumen 5.7

Any help will be appreciated. Thanks


Solution

  • You need to store a data in serialize or json try like this:

    Redis::set('CacheTest', json_encode($finalProduct)); //$finalProduct is an Array
    

    and get value you need to decode value

    $data = Redis::get('CacheTest');
    dd(json_decode($data))