本地測試 ,先搞個 redis,併到文件夾下使用命令 Redis-server redis.conf 開啓 redis 服務
修改配置文件
config/cache.php
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
這裏的connection對應config/database中redis的默認主機default配置。
config/database.php
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
2. 測試
寫個路由 控制器 postman 測試
$key = '3333';
if (Cache::has($key)){ //首先查尋cache如果找到
$values = Cache::get($key); //直接讀取cache
dd($values);
}else{ //如果cache裏面沒有
$value = '4444';
Cache::put($key,$value,500);
}
dd(Cache::get($key));
3. 打開 RedisDesktopManager 瞅瞅,默認在 db0 :)