ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
### 1 修改缓存配置文件cache.php ~~~ return [ // 驱动方式 'type' => 'complex', // 默认 'default' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => '', // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, ], // 文件 'file' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => '', // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, ], // redis 'redis' => [ 'type' => 'redis', 'host' => '127.0.0.1', 'port' => '6379', 'password' => 'jiangguowu', // 全局缓存有效期(0为永久有效) 'expire' => 0, // 缓存前缀 'prefix' => '', ], ]; ~~~ ### 2 在控制器中调用 普通的set get方法请参考其他大佬示例 以下是调用redis的原生所有方法 ~~~ public function test() { // 读取redis的配置 $redis = new Redis(config('cache.redis')); // 获取redis句柄 $handler = $redis->handler(); // 左侧压入 $handler->lpush('user', 'hander1'); // 读取全部的数据 $info = $redis->lrange('user', 0, -1); return json($info); } ~~~ PS:如有不明白之处 请多折腾 生命不息 折腾不止