hyperf-chat/app/Cache/IpAddressCache.php

30 lines
591 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;
2022-01-22 20:08:19 +08:00
use App\Helper\JsonHelper;
2021-09-12 16:26:28 +08:00
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);
}
2021-09-12 21:15:38 +08:00
$result = di()->get(IpAddress::class)->get($ip);
2021-09-12 16:26:28 +08:00
if (!empty($result)) {
$this->add($ip, JsonHelper::encode($result));
}
return $result;
}
}