/** * 如果redis没有创建则进行创建 * @throws \Exception */ private static function create() { foreach (C('redis') as $key => $node) { $redis = new \Redis(); // redis连接 if ($redis->connect($node['host'], $node['port'], $node['timeout'])) { // 是否需要验证 !$node['password'] or $redis->auth($node['password']); // 增加节点 Consistent::addNode("redis{$key}", $redis); // 删除临时对象 unset($redis); } else { throw new \RedisException("Redis Connection Error: {$node['ip']}"); } } self::$instance = TRUE; }
/** * 获取redis * @param string $key 适配器名称,默认master * @return \Driver\Redis */ protected final function getRedis($key = 'master') { return Redis::getInstance($this->driver['redis'][$redis]); }