在Debian系统中配置Laravel缓存,你需要遵循以下步骤:
composer create-project --prefer-dist laravel/laravel your_project_name
将your_project_name
替换为你的项目名称。
sudo apt-get update
sudo apt-get install redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-server
composer require predis/predis
.env
文件,找到CACHE_DRIVER
设置,将其更改为redis
:CACHE_DRIVER=redis
接下来,配置Redis连接设置。在.env
文件中,设置以下变量:
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
将REDIS_PASSWORD
设置为你的Redis密码(如果有的话)。
php artisan config:clear
php artisan config:cache
现在,你已经成功地在Debian系统中为Laravel配置了Redis缓存。你可以使用Laravel的缓存功能来存储和检索数据了。例如,你可以使用以下命令将数据存储到缓存中:
Cache::put('key', 'value', $seconds);
要从缓存中检索数据,请使用:
$value = Cache::get('key');
更多关于Laravel缓存的信息,请查阅官方文档:https://laravel.com/docs/cache。