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 {
|
if len(keys) > 0 {
|
||||||
metaMap := make(map[string]*models.HostMeta)
|
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 {
|
for _, value := range vals {
|
||||||
var meta models.HostMeta
|
var meta models.HostMeta
|
||||||
if value == nil {
|
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))
|
keys = append(keys, models.WrapIdent(targets[i].Ident))
|
||||||
num++
|
num++
|
||||||
if num == 100 {
|
if num == 100 {
|
||||||
vals, err := storage.MGet(context.Background(), tc.redis, keys)
|
vals := storage.MGet(context.Background(), tc.redis, keys)
|
||||||
if err != nil {
|
|
||||||
logger.Warningf("keys:%v get host meta err:%v", keys, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range vals {
|
for _, value := range vals {
|
||||||
var meta models.HostMeta
|
var meta models.HostMeta
|
||||||
if value == nil {
|
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)
|
vals := storage.MGet(context.Background(), tc.redis, keys)
|
||||||
if err != nil {
|
|
||||||
logger.Warningf("keys:%v get host meta err:%v", keys, err)
|
|
||||||
}
|
|
||||||
for _, value := range vals {
|
for _, value := range vals {
|
||||||
var meta models.HostMeta
|
var meta models.HostMeta
|
||||||
if value == nil {
|
if value == nil {
|
||||||
|
|
|
@ -113,17 +113,13 @@ func NewRedis(cfg RedisConfig) (Redis, error) {
|
||||||
return redisClient, nil
|
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
|
var vals [][]byte
|
||||||
pipe := r.Pipeline()
|
pipe := r.Pipeline()
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
pipe.Get(ctx, key)
|
pipe.Get(ctx, key)
|
||||||
}
|
}
|
||||||
cmds, err := pipe.Exec(ctx)
|
cmds, _ := pipe.Exec(ctx)
|
||||||
if err != nil {
|
|
||||||
logger.Errorf("failed to exec pipeline: %s", err)
|
|
||||||
return vals, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
cmd := cmds[i]
|
cmd := cmds[i]
|
||||||
|
@ -135,7 +131,7 @@ func MGet(ctx context.Context, r Redis, keys []string) ([][]byte, error) {
|
||||||
vals = append(vals, val)
|
vals = append(vals, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return vals, err
|
return vals
|
||||||
}
|
}
|
||||||
|
|
||||||
func MSet(ctx context.Context, r Redis, m map[string]interface{}) error {
|
func MSet(ctx context.Context, r Redis, m map[string]interface{}) error {
|
||||||
|
|
Loading…
Reference in New Issue