How to get list of all cached items by key in Laravel 5?

前端 未结 5 869
旧时难觅i
旧时难觅i 2021-02-19 10:01

The Cache class in laravel has methods such as get(\'itemKey\') to retrieve items from the cache, and remember(\'itemKey\', [\'myData1\', \'myData2\']) to save items in the cach

5条回答
  •  故里飘歌
    2021-02-19 10:33

    in \config\database.php make a redis store for the cache

       // store cache in their own redis store ...
        'cache-connection' => [
            'host'               => ...,
            'password'           => ...,
            'port'               => env('REDIS_PORT', 6379),
            'database'           => 2,
            'read_write_timeout' => 60,
            'timeout'            => 6.0,
        ],
    

    in \config\cache.php use this redis database

    'stores' => [
       ...
       'redis' => [
            'driver'     => 'redis',
            'connection' => 'cache-connection',
        ],
    ],
    

    now you can use Redis class to check what is in your cache

    $a = Redis::connection('cache-connection')->keys('*');
    \Log::debug($a);
    

提交回复
热议问题