Set one value
(ctx context.Context, key string, val interface{}, expiration time.Duration)
| 38 | |
| 39 | // Set one value |
| 40 | func (c *redisCache) Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error { |
| 41 | buf, err := encoding.Marshal(c.encoding, val) |
| 42 | if err != nil { |
| 43 | return fmt.Errorf("encoding.Marshal error: %v, key=%s, val=%+v ", err, key, val) |
| 44 | } |
| 45 | |
| 46 | cacheKey, err := BuildCacheKey(c.KeyPrefix, key) |
| 47 | if err != nil { |
| 48 | return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key) |
| 49 | } |
| 50 | //if expiration == 0 { |
| 51 | // expiration = DefaultExpireTime |
| 52 | //} |
| 53 | if len(buf) == 0 { |
| 54 | buf = NotFoundPlaceholderBytes |
| 55 | } |
| 56 | err = c.client.Set(ctx, cacheKey, buf, expiration).Err() |
| 57 | if err != nil { |
| 58 | return fmt.Errorf("c.client.Set error: %v, cacheKey=%s", err, cacheKey) |
| 59 | } |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | // Get one value |
| 64 | func (c *redisCache) Get(ctx context.Context, key string, val interface{}) error { |
nothing calls this directly
no test coverage detected