修改env
增加REDIS_CLIENT字段值为predis,修改REDIS_HOST为redis服务器ip
1 2 3 4 |
REDIS_CLIENT=predis REDIS_HOST=192.168.2.1 REDIS_PASSWORD=null REDIS_PORT=6379 |
安装predis
cd到laravel根目录运行
1 |
docker run --rm -it -v "$(pwd):/app" composer/composer require predis/predis --ignore-platform-reqs |
在controller中增加测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
namespace App\Http\Controllers; ... use Illuminate\Support\Facades\Redis; ... class predisController extends Controller { ... public function index() { ... $value = Redis::set('bar', 'baz'); $value = Redis::get('bar'); die($value); ... } } |
将controller加入routes
1 |
Route::get('/predis', [App\Http\Controllers\predisController::class, 'index']) |
访问/predis
返回baz
成功
There are no comments yet