|
@ -21,7 +21,7 @@ func getUrl(key, hashKey string) *dto.Result { |
|
|
// 1. 从 Redis 获取 URL
|
|
|
// 1. 从 Redis 获取 URL
|
|
|
redisUrl, err := g.Redis().Do(ctx, "HGET", key, hashKey) |
|
|
redisUrl, err := g.Redis().Do(ctx, "HGET", key, hashKey) |
|
|
if err == nil && redisUrl.String() != "" { |
|
|
if err == nil && redisUrl.String() != "" { |
|
|
g.Log().Infof(ctx, "从 Redis 获取到 URL: %s", redisUrl.String()) |
|
|
|
|
|
|
|
|
//g.Log().Infof(ctx, "从 Redis 获取到 URL: %s", redisUrl.String())
|
|
|
return dto.SuccessWithData(redisUrl.String()) |
|
|
return dto.SuccessWithData(redisUrl.String()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -34,16 +34,16 @@ func getUrl(key, hashKey string) *dto.Result { |
|
|
|
|
|
|
|
|
// 3. 将 URL 存入 Redis
|
|
|
// 3. 将 URL 存入 Redis
|
|
|
if _, err = g.Redis().Do(ctx, "HSET", key, hashKey, url); err != nil { |
|
|
if _, err = g.Redis().Do(ctx, "HSET", key, hashKey, url); err != nil { |
|
|
g.Log().Warningf(ctx, "将数据存入 Redis 失败: %v", err) |
|
|
|
|
|
|
|
|
//g.Log().Warningf(ctx, "将数据存入 Redis 失败: %v", err)
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
g.Log().Infof(ctx, "将 URL 存入 Redis: %s", url) |
|
|
|
|
|
|
|
|
//g.Log().Infof(ctx, "将 URL 存入 Redis: %s", url)
|
|
|
return dto.SuccessWithData(url) |
|
|
return dto.SuccessWithData(url) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 查询数据库中的 URL
|
|
|
// 查询数据库中的 URL
|
|
|
func selectBaseUrl(hashKey string) *dto.Result { |
|
|
func selectBaseUrl(hashKey string) *dto.Result { |
|
|
ctx := gctx.New() |
|
|
|
|
|
|
|
|
//ctx := gctx.New()
|
|
|
|
|
|
|
|
|
// 查询数据库
|
|
|
// 查询数据库
|
|
|
value, err := g.DB("cms").Model("env").Where("`key` = ?", hashKey).Value("value") |
|
|
value, err := g.DB("cms").Model("env").Where("`key` = ?", hashKey).Value("value") |
|
@ -53,7 +53,7 @@ func selectBaseUrl(hashKey string) *dto.Result { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if value.IsNil() || value.String() == "" { |
|
|
if value.IsNil() || value.String() == "" { |
|
|
g.Log().Errorf(ctx, "未找到对应数据, key: %s", hashKey) |
|
|
|
|
|
|
|
|
//g.Log().Errorf(ctx, "未找到对应数据, key: %s", hashKey)
|
|
|
return dto.Error("未找到对应数据") |
|
|
return dto.Error("未找到对应数据") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|