Get one value
(ctx context.Context, key string, val interface{})
| 62 | |
| 63 | // Get one value |
| 64 | func (c *redisCache) Get(ctx context.Context, key string, val interface{}) error { |
| 65 | cacheKey, err := BuildCacheKey(c.KeyPrefix, key) |
| 66 | if err != nil { |
| 67 | return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key) |
| 68 | } |
| 69 | |
| 70 | dataBytes, err := c.client.Get(ctx, cacheKey).Bytes() |
| 71 | // NOTE: don't handle the case where redis value is nil |
| 72 | // but leave it to the upstream for processing |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | |
| 77 | // prevent Unmarshal from reporting an error if data is empty |
| 78 | if len(dataBytes) == 0 || bytes.Equal(dataBytes, NotFoundPlaceholderBytes) { |
| 79 | return ErrPlaceholder |
| 80 | } |
| 81 | err = encoding.Unmarshal(c.encoding, dataBytes, val) |
| 82 | if err != nil { |
| 83 | return fmt.Errorf("encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, json=%s ", |
| 84 | err, key, cacheKey, val, dataBytes) |
| 85 | } |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // MultiSet set multiple values |
| 90 | func (c *redisCache) MultiSet(ctx context.Context, valueMap map[string]interface{}, expiration time.Duration) error { |
nothing calls this directly
no test coverage detected