Browse Source

update: redis support for kms check

master
Dnomd343 3 years ago
parent
commit
e5e0c4950f
  1. 29
      models/kmsCheck.php

29
models/kmsCheck.php

@ -20,27 +20,32 @@ class kmsCheck {
public function kmsStatus($host, $port) {
$server = $host . ':' . $port;
$redis = new redisCache('kms');
$info = $redis->getData($server); // 查询缓存数据
if (!$info) { // 缓存未命中
$url = $this->api . 'check?host=' . $host . '&port=' . $port;
$content = json_decode(file_get_contents($url), true); // 请求上游接口
switch ($content['status']) {
$info = json_decode(file_get_contents($url), true); // 请求上游接口
$info['server'] = $server;
switch ($info['status']) {
case 'ok':
return array(
'status' => 'ok',
'online' => true,
'server' => $server
);
$info['online'] = true;
break;
case 'error':
return array(
'status' => 'ok',
'online' => false,
'server' => $server
);
$info['online'] = false;
break;
default:
return array(
'status' => 'error',
'message' => 'Server error'
);
}
$info['status'] = 'ok';
unset($info['message']);
$redis->setData($server, json_encode($info), 300); // 缓存5min
} else { // 缓存命中
$info = json_decode($info, true); // 使用缓存数据
}
return $info;
}
}

Loading…
Cancel
Save