think\Cache::connect PHP Method

connect() public static method

连接缓存
public static connect ( array $options = [], boolean | string $name = false ) : Driver
$options array 配置数组
$name boolean | string 缓存连接标识 true 强制重新连接
return think\cache\Driver
    public static function connect(array $options = [], $name = false)
    {
        $type = !empty($options['type']) ? $options['type'] : 'File';
        if (false === $name) {
            $name = md5(serialize($options));
        }
        if (true === $name || !isset(self::$instance[$name])) {
            $class = false !== strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
            // 记录初始化信息
            App::$debug && Log::record('[ CACHE ] INIT ' . $type, 'info');
            if (true === $name) {
                return new $class($options);
            } else {
                self::$instance[$name] = new $class($options);
            }
        }
        self::$handler = self::$instance[$name];
        return self::$handler;
    }

Usage Example

コード例 #1
0
ファイル: redisTest.php プロジェクト: Tong12/think
 protected function setUp()
 {
     if (!extension_loaded("redis")) {
         $this->markTestSkipped("Redis没有安装,已跳过测试!");
     }
     \think\Cache::connect(array('type' => 'redis', 'expire' => 2));
 }
All Usage Examples Of think\Cache::connect