hyperf-chat/app/Cache/IpAddressCache.php

30 lines
593 B
PHP
Raw Normal View History

2021-09-12 16:26:28 +08:00
<?php
declare(strict_types=1);
namespace App\Cache;
use App\Cache\Repository\HashRedis;
use App\Helpers\JsonHelper;
use App\Support\IpAddress;
class IpAddressCache extends HashRedis
{
protected $name = 'ip-address';
public function getAddressInfo(string $ip)
{
$result = $this->get($ip);
if (!empty($result)) {
return JsonHelper::decode($result);
}
$result = di()->get(IpAddress::class)->read($ip);
if (!empty($result)) {
$this->add($ip, JsonHelper::encode($result));
}
return $result;
}
}