$options = [
// 缓存类型为File
'type' => 'File',
// 缓存有效期为永久有效
'expire'=> 0,
//缓存前缀
'prefix'=> 'think',
// 指定缓存目录
'path' => APP_PATH.'runtime/cache/',
];
Cache::connect($options);
如果单纯看文档,根本就是一头雾水,只能去看源码了,/think/cache/driver/Redis.php /**
* 构造函数
* @param array $options 缓存参数
* @access public
*/
public function __construct($options = [])
{
if (!extension_loaded('redis')) {
throw new \BadFunctionCallException('not support: redis');
}
if (!empty($options)) {
$this->options = array_merge($this->options, $options);
}
$func = $this->options['persistent'] ? 'pconnect' : 'connect';
$this->handler = new \Redis;
$this->handler->$func($this->options['host'], $this->options['port'], $this->options['timeout']);
if ('' != $this->options['password']) {
$this->handler->auth($this->options['password']);
}
if (0 != $this->options['select']) {
$this->handler->select($this->options['select']);
}
}
所以redis正确配置应该如下// 驱动方式
'type' => 'Redis',
'host' => '127.0.0.1',
'port' => '6379',
'password' => '',
'timeout'=> 3600
最佳答案
