MultiGet get multiple values
(ctx context.Context, keys []string, value interface{})
| 133 | |
| 134 | // MultiGet get multiple values |
| 135 | func (c *redisCache) MultiGet(ctx context.Context, keys []string, value interface{}) error { |
| 136 | if len(keys) == 0 { |
| 137 | return nil |
| 138 | } |
| 139 | cacheKeys := make([]string, len(keys)) |
| 140 | for index, key := range keys { |
| 141 | cacheKey, err := BuildCacheKey(c.KeyPrefix, key) |
| 142 | if err != nil { |
| 143 | return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key) |
| 144 | } |
| 145 | cacheKeys[index] = cacheKey |
| 146 | } |
| 147 | values, err := c.client.MGet(ctx, cacheKeys...).Result() |
| 148 | if err != nil { |
| 149 | return fmt.Errorf("c.client.MGet error: %v, keys=%+v", err, cacheKeys) |
| 150 | } |
| 151 | |
| 152 | // Injection into map via reflection |
| 153 | valueMap := reflect.ValueOf(value) |
| 154 | for i, v := range values { |
| 155 | if v == nil { |
| 156 | continue |
| 157 | } |
| 158 | dataBytes := []byte(v.(string)) |
| 159 | if len(dataBytes) == 0 || bytes.Equal(dataBytes, NotFoundPlaceholderBytes) { |
| 160 | continue |
| 161 | } |
| 162 | object := c.newObject() |
| 163 | err = encoding.Unmarshal(c.encoding, dataBytes, object) |
| 164 | if err != nil { |
| 165 | fmt.Printf("unmarshal data error: %+v, cacheKey=%s valueType=%T\n", err, cacheKeys[i], value) |
| 166 | continue |
| 167 | } |
| 168 | valueMap.SetMapIndex(reflect.ValueOf(cacheKeys[i]), reflect.ValueOf(object)) |
| 169 | } |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | // Del delete multiple values |
| 174 | func (c *redisCache) Del(ctx context.Context, keys ...string) error { |
nothing calls this directly
no test coverage detected