Get retrieves a value from the cache. It returns cachetypes.ErrCachedDataNotFound if it does not exist. nolint: ireturn // V is not a interface always. Can ignore this.
( ctx context.Context, key K, )
| 99 | // It returns cachetypes.ErrCachedDataNotFound if it does not exist. |
| 100 | // nolint: ireturn // V is not a interface always. Can ignore this. |
| 101 | func (c *ValkeyDataCache[K, V]) Get( |
| 102 | ctx context.Context, |
| 103 | key K, |
| 104 | ) (V, error) { |
| 105 | defaultValue := *new(V) |
| 106 | msg, err := c.client.Do(ctx, c.client.B().Get().Key(c.cacheKey(key)).Build()).ToMessage() |
| 107 | if errors.Is(err, valkey.Nil) { |
| 108 | return defaultValue, cachetypes.ErrCachedDataNotFound |
| 109 | } else if err != nil { |
| 110 | // All other errors |
| 111 | return defaultValue, err |
| 112 | } |
| 113 | |
| 114 | return msg.AsBytes() |
| 115 | } |