MultiGet get multiple values
(ctx context.Context, keys []string, value interface{})
| 330 | |
| 331 | // MultiGet get multiple values |
| 332 | func (c *redisClusterCache) MultiGet(ctx context.Context, keys []string, value interface{}) error { |
| 333 | if len(keys) == 0 { |
| 334 | return nil |
| 335 | } |
| 336 | cacheKeys := make([]string, len(keys)) |
| 337 | for index, key := range keys { |
| 338 | cacheKey, err := BuildCacheKey(c.KeyPrefix, key) |
| 339 | if err != nil { |
| 340 | return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key) |
| 341 | } |
| 342 | cacheKeys[index] = cacheKey |
| 343 | } |
| 344 | values, err := c.client.MGet(ctx, cacheKeys...).Result() |
| 345 | if err != nil { |
| 346 | return fmt.Errorf("c.client.MGet error: %v, keys=%+v", err, cacheKeys) |
| 347 | } |
| 348 | |
| 349 | // Injection into map via reflection |
| 350 | valueMap := reflect.ValueOf(value) |
| 351 | for i, v := range values { |
| 352 | if v == nil { |
| 353 | continue |
| 354 | } |
| 355 | dataBytes := []byte(v.(string)) |
| 356 | if len(dataBytes) == 0 || bytes.Equal(dataBytes, NotFoundPlaceholderBytes) { |
| 357 | continue |
| 358 | } |
| 359 | object := c.newObject() |
| 360 | err = encoding.Unmarshal(c.encoding, dataBytes, object) |
| 361 | if err != nil { |
| 362 | fmt.Printf("unmarshal data error: %+v, cacheKey=%s type=%T\n", err, cacheKeys[i], value) |
| 363 | continue |
| 364 | } |
| 365 | valueMap.SetMapIndex(reflect.ValueOf(cacheKeys[i]), reflect.ValueOf(object)) |
| 366 | } |
| 367 | return nil |
| 368 | } |
| 369 | |
| 370 | // Del delete multiple values |
| 371 | func (c *redisClusterCache) Del(ctx context.Context, keys ...string) error { |
nothing calls this directly
no test coverage detected