This commit is contained in:
2021-12-02 15:52:49 +08:00
parent 9a6575b438
commit 3538393620
+6 -5
View File
@@ -25,7 +25,7 @@ class RpcManager
public function tableInit() public function tableInit()
{ {
$this->table = new Table((int)Config::get('rpc.total', 10)); $this->table = new Table((int)Config::get('rpc.total', 10));
$this->table->column('content', Table::TYPE_STRING); $this->table->column('name', Table::TYPE_STRING);
$this->table->create(); $this->table->create();
} }
@@ -43,10 +43,11 @@ class RpcManager
return; return;
} }
$body = json_decode($lists->getBody(), true); $body = json_decode($lists->getBody(), true);
$file = storage('.rpc.clients.' . md5($serviceName), 'rpc');
if (!empty($body) && is_array($body)) { if (!empty($body) && is_array($body)) {
$this->table->set($serviceName, ['content' => json_encode(array_column($body, 'Service'))]); file_put_contents($file, json_encode(array_column($body, 'Service')), LOCK_EX);
} else { } else {
$this->table->set($serviceName, ['content' => json_encode([])]); file_put_contents($file, json_encode([]), LOCK_EX);
} }
} }
@@ -70,10 +71,10 @@ class RpcManager
public function getServices($serviceName): array public function getServices($serviceName): array
{ {
$file = storage('.rpc.clients.' . md5($serviceName), 'rpc'); $file = storage('.rpc.clients.' . md5($serviceName), 'rpc');
if (!$this->table->exist($file)) { if (!file_exists($file)) {
return []; return [];
} }
$content = json_decode($this->table->get($serviceName), true); $content = json_decode(file_get_contents($file), true);
if (empty($content) || !is_array($content)) { if (empty($content) || !is_array($content)) {
return []; return [];
} }