在config.php配置文件下找到缓存设置,将原来的文件缓存修改为redis缓存,也可以改为多种类型的缓存:
// ◆---------------------------------------------------------------------- // | 缓存设置 // ◆---------------------------------------------------------------------- /* 'cache' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => CACHE_PATH, // 缓存前缀 'prefix' => '', // 缓存有效期 0表示永久缓存 'expire' => 0, ],*/ 'cache' => [ // 使用复合缓存类型 'type' => 'complex', // 默认使用的缓存 'default' => [ // 驱动方式 'type' => 'File', // 缓存保存目录 'path' => CACHE_PATH, ], // 文件缓存 'file' => [ // 驱动方式 'type' => 'file', // 设置不同的缓存保存目录 'path' => RUNTIME_PATH . 'file/', ], // redis缓存 'redis' => [ // 驱动方式 'type' => 'redis', // 服务器地址 'host' => '12⑦0.0.1', // 本地环境先开启redis服务端 redis-service.exe 'port' => '6379', ], ],
这样就可以使用redis来缓存数据了.用法如下:
\think\Cache::store('redis')->handler()->hMSet('test', array('k1'=>123));
/** * 返回句柄对象,可执行其它高级方法 * * @access public * @return object */ public function handler() { return $this->handler; }
注意: 不过在window下测试redis, 还要开启它服务端才行 redis-service.exe
以上就是土嘎嘎小编大虾米为大家整理的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!