在项目根目录使用composer 安装redis扩展包
composer require marlon/thinkphp-redis
进入config/cache.php 配置添加redis缓存
<?php // +---------------------------------------------------------------------- // | 缓存设置 // +---------------------------------------------------------------------- return [ // 默认缓存驱动 'default' => env('cache.driver', 'file'), // 缓存连接方式配置 'stores' => [ 'file' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => '', // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, // 缓存标签前缀 'tag_prefix' => 'tag:', // 序列化机制 例如 ['serialize', 'unserialize'] 'serialize' => [], ], // 更多的缓存连接 // redis缓存 'redis' => [ // 驱动方式 'type' => 'redis', // 服务器地址(具体看你在哪里搭建好的redis服务器) 'host' => '127.0.0.1', // 端口号 'port' => '6379', // 密码 'password' => "", // 默认缓存时间 'timeout' => 3600 ], ], ]; ?>
Thinkphp6中使用redis列表缓存
use think\facade\Cache; $redis=Cache::store('redis')->handler(); $redis->lpush($tel,$username); $redis->lpush($tel,$password); $redis->lpush($tel,$tel);
Thinkphp6中使用redis缓存
Cache::store('redis')->set('username','nihao'); dump(Cache::store('redis')->get('username'));
Thinkphp6中使用redis获取数据库中所有的key
$keyData=$redis->keys('*');
使用foreach 将获取数据库中所有的key中的值放入数组中
foreach ($keyData as $val) { $da = $redis->lrange($val, 0, -1); $arr[] = $da; } dd($arr)
有问题请联系作者QQ:4505399(备注:vb盒子)