Browse Source

update: redis support for kms check

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

45
models/kmsCheck.php

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