1.首先通過 Composer 安裝 predis/predis 包:
composer require predis/predis
2.配置redis 配置檔案config/database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
.env 檔案配置
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
測試:
//引入包
use Illuminate\Support\Facades\Redis;
//存入redis
Redis::set('key','value');
//取出
$value = Redis::get('key');
dd($value); //輸出value
完成,只是記錄如何使用redis,有錯望指出!!
本作品採用《CC 協議》,轉載必須註明作者和本文連結