feature/ip优化

This commit is contained in:
吕翠丽 2025-06-17 17:03:31 +08:00
parent 169996cc8a
commit 0bbbfa3c1e

View File

@ -90,7 +90,7 @@ func (h *HuaChenIpClient) GetIpInfo(ip string) (res *ApiResult, err error) {
return &apiResult, nil
}
func (h *HuaChenIpClient) GetIpInfoFormCache(ctx context.Context, ip string) (res *ApiResult, err error) {
func (h *HuaChenIpClient) GetIpInfoFormCache(ctx context.Context, ip string, ttl time.Duration) (res *ApiResult, err error) {
getCache, err := h.cache.Get(ctx, h.ipKey(ip))
if err != nil {
return nil, errors.Wrapf(err, "获取缓存失败ip:%s", ip)
@ -108,7 +108,7 @@ func (h *HuaChenIpClient) GetIpInfoFormCache(ctx context.Context, ip string) (re
return nil, errors.Wrapf(err, "无法将IP信息转换为JSONip:%s", ip)
}
err = h.cache.Set(ctx, h.ipKey(ip), string(infoJson), 24*time.Hour)
err = h.cache.Set(ctx, h.ipKey(ip), string(infoJson), ttl)
if err != nil {
return nil, errors.Wrapf(err, "缓存ip:%s信息失败", ip)
}