tp5配置Redis格式

浏览:16112 发布日期:2017/07/10 分类:ThinkPHP5专区 关键字: tp5 redis 配置
tp5出来时间也不短了,但官方文档水平实在不敢恭维,文档就缓存的配置如下:$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
最佳答案
评论( 相关
后面还有条评论,点击查看>>