PHP函数查看redis 版本号

$redis_ext_refc = new ReflectionExtension('redis');
var_dump($redis_ext_refc->getVersion());

参考:

public function addServer($host = '127.0.0.1', $port = 6379, $dbIndex = 0, $weight = 1) {
		$redis = new Redis();
        $rhost = $host . ':' . $port;
		$connection_string = $rhost . '/' . $dbIndex;

        $redis_ext_refc = new ReflectionExtension('redis');
        if (version_compare($redis_ext_refc->getVersion(), '2.1.0') <= 0) {
            $bret = $redis->pconnect($host, $port, 0);
        } else {
            $bret = $redis->pconnect($host, $port, 0, $connection_string);
        }

        if ($bret) {
			// $redis->select($dbIndex); // redis-proxy and high redis not support this anymore
            $this->_hash->addTarget($rhost);
            $this->_pool[$rhost] = $redis;
            return true;
        }
		unset($redis);
        return false;
    }

posted @ 2022-01-26 18:11  码农编程进阶笔记  阅读(226)  评论(0编辑  收藏  举报
返回顶部 有事您Q我