feature/ip优化
This commit is contained in:
parent
169996cc8a
commit
0bbbfa3c1e
@ -90,7 +90,7 @@ func (h *HuaChenIpClient) GetIpInfo(ip string) (res *ApiResult, err error) {
|
|||||||
return &apiResult, nil
|
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))
|
getCache, err := h.cache.Get(ctx, h.ipKey(ip))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "获取缓存失败,ip:%s", ip)
|
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信息转换为JSON,ip:%s", ip)
|
return nil, errors.Wrapf(err, "无法将IP信息转换为JSON,ip:%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 {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "缓存ip:%s信息失败,", ip)
|
return nil, errors.Wrapf(err, "缓存ip:%s信息失败,", ip)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user