application/config.php 中 cache项的设置
'cache' => [
// 驱动方式
'type' => 'complex',
// 缓存前缀
'prefix' => 'pre:',
// 默认使用的缓存
'default' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => CACHE_PATH,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
],
// redis缓存
'redis' => [
// 驱动方式
'type' => 'redis',
// 服务器地址
'host' => $_SERVER['RD_HOST'],
'port' => $_SERVER['RD_PORT'],
'password' => $_SERVER['RD_AUTH'],
'select' =>1,
],
],
application/common/controller/Backend.php
use think\Cache;
class Backend extends Controller
{
public $redis = null;
public function _initialize()
{
$this->redis=Cache::store('redis')->handler(); //获得redis操作句柄
$this->redis->hincrby('mys:action_coun',$_SERVER['DOCUMENT_URI'],1); //访问方法计数
在所有继承这个类的子类下 $this->redis 就可以操作所有redis原生方法了。