/** * 初始化Redis连接 * * @throws RedisException */ private static function initRedis() { $apf = APF::get_instance(); $config = $apf->get_config('mobile_commsign', 'redis'); //本地redis,测试用 //$config['host'] = '192.168.190.69'; //$config['port'] = '6379'; if (!isset($config['host']) || !isset($config['port'])) { throw new RedisException('Host and port are needed to connect redis server.'); } self::$redis = new Redis(); if (!self::$redis->connect($config['host'], $config['port'])) { throw new RedisException("Failed to connect redis server: {$config['host']}:{$config['port']}"); } self::$redis->setOption(4, 1); // retry when we get no keys back }