fix: redis get nil
This commit is contained in:
parent
a0c635b830
commit
dc26bb78d8
|
@ -65,7 +65,7 @@ func (rt *Router) targetGets(c *gin.Context) {
|
|||
|
||||
if len(keys) > 0 {
|
||||
metaMap := make(map[string]*models.HostMeta)
|
||||
vals, _ := storage.MGet(context.Background(), rt.Redis, keys)
|
||||
vals := storage.MGet(context.Background(), rt.Redis, keys)
|
||||
for _, value := range vals {
|
||||
var meta models.HostMeta
|
||||
if value == nil {
|
||||
|
|
|
@ -177,12 +177,7 @@ func (tc *TargetCacheType) GetHostMetas(targets []*models.Target) map[string]*mo
|
|||
keys = append(keys, models.WrapIdent(targets[i].Ident))
|
||||
num++
|
||||
if num == 100 {
|
||||
vals, err := storage.MGet(context.Background(), tc.redis, keys)
|
||||
if err != nil {
|
||||
logger.Warningf("keys:%v get host meta err:%v", keys, err)
|
||||
continue
|
||||
}
|
||||
|
||||
vals := storage.MGet(context.Background(), tc.redis, keys)
|
||||
for _, value := range vals {
|
||||
var meta models.HostMeta
|
||||
if value == nil {
|
||||
|
@ -202,10 +197,7 @@ func (tc *TargetCacheType) GetHostMetas(targets []*models.Target) map[string]*mo
|
|||
}
|
||||
}
|
||||
|
||||
vals, err := storage.MGet(context.Background(), tc.redis, keys)
|
||||
if err != nil {
|
||||
logger.Warningf("keys:%v get host meta err:%v", keys, err)
|
||||
}
|
||||
vals := storage.MGet(context.Background(), tc.redis, keys)
|
||||
for _, value := range vals {
|
||||
var meta models.HostMeta
|
||||
if value == nil {
|
||||
|
|
|
@ -113,17 +113,13 @@ func NewRedis(cfg RedisConfig) (Redis, error) {
|
|||
return redisClient, nil
|
||||
}
|
||||
|
||||
func MGet(ctx context.Context, r Redis, keys []string) ([][]byte, error) {
|
||||
func MGet(ctx context.Context, r Redis, keys []string) [][]byte {
|
||||
var vals [][]byte
|
||||
pipe := r.Pipeline()
|
||||
for _, key := range keys {
|
||||
pipe.Get(ctx, key)
|
||||
}
|
||||
cmds, err := pipe.Exec(ctx)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to exec pipeline: %s", err)
|
||||
return vals, err
|
||||
}
|
||||
cmds, _ := pipe.Exec(ctx)
|
||||
|
||||
for i, key := range keys {
|
||||
cmd := cmds[i]
|
||||
|
@ -135,7 +131,7 @@ func MGet(ctx context.Context, r Redis, keys []string) ([][]byte, error) {
|
|||
vals = append(vals, val)
|
||||
}
|
||||
|
||||
return vals, err
|
||||
return vals
|
||||
}
|
||||
|
||||
func MSet(ctx context.Context, r Redis, m map[string]interface{}) error {
|
||||
|
|
Loading…
Reference in New Issue