Thinkphp6中使用redis列表缓存
2022-11-24 11:10:29
223
{{single.collect_count}}
  •  在项目根目录使用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中的值放入数组中
$arr = [];foreach ($keyData as $val) {$da = $redis->lrange($val, 0, -1);$arr[] = $da;}dd($arr);

 

 

 

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}