Documentation
¶
Index ¶
- func Increment[T int | float64](ctx context.Context, cache *RedisCache[T], key string, delta T) (T, error)
- type JSONValueCoder
- type RedisCache
- func (c *RedisCache[T]) Delete(ctx context.Context, key string) error
- func (c *RedisCache[T]) DeleteAll(ctx context.Context) error
- func (c *RedisCache[T]) Exists(ctx context.Context, key string) (bool, error)
- func (c *RedisCache[T]) Get(ctx context.Context, key string) (T, error)
- func (c *RedisCache[T]) GetAll(ctx context.Context) (map[string]T, error)
- func (c *RedisCache[T]) GetWithTTL(ctx context.Context, key string) (T, time.Duration, error)
- func (c *RedisCache[T]) Getdel(ctx context.Context, key string) (T, error)
- func (c *RedisCache[T]) Keys(ctx context.Context) ([]string, error)
- func (c *RedisCache[T]) Set(ctx context.Context, key string, value T) error
- func (c *RedisCache[T]) SetWithExpiration(ctx context.Context, key string, value T, expiration time.Duration) error
- func (c *RedisCache[T]) WithCoder(coder ValueCoder[T]) *RedisCache[T]
- type StringValueCoder
- type ValueCoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JSONValueCoder ¶
type JSONValueCoder[T any] struct{}
JSONValueCoder implements ValueCoder using JSON encoding
func (JSONValueCoder[T]) Decode ¶
func (c JSONValueCoder[T]) Decode(encoded string) (T, error)
func (JSONValueCoder[T]) Encode ¶
func (c JSONValueCoder[T]) Encode(value T) (string, error)
type RedisCache ¶
type RedisCache[T any] struct { // contains filtered or unexported fields }
RedisCache implements a generic Redis-based cache
func NewCache ¶
func NewCache[T any](client *redis.Client, prefix string) *RedisCache[T]
NewCache creates a new RedisCache instance
func NewStringCache ¶
func NewStringCache(client *redis.Client, prefix string) *RedisCache[string]
NewStringCache creates a new RedisCache instance for string values
func (*RedisCache[T]) Delete ¶
func (c *RedisCache[T]) Delete(ctx context.Context, key string) error
Delete removes a value from the cache
func (*RedisCache[T]) DeleteAll ¶
func (c *RedisCache[T]) DeleteAll(ctx context.Context) error
DeleteAll removes all values with the cache's prefix
func (*RedisCache[T]) Get ¶
func (c *RedisCache[T]) Get(ctx context.Context, key string) (T, error)
Get retrieves a value from the cache
func (*RedisCache[T]) GetAll ¶
func (c *RedisCache[T]) GetAll(ctx context.Context) (map[string]T, error)
GetAll retrieves all values from the cache
func (*RedisCache[T]) GetWithTTL ¶
GetWithTTL retrieves a value and its TTL from the cache
func (*RedisCache[T]) Getdel ¶
func (c *RedisCache[T]) Getdel(ctx context.Context, key string) (T, error)
Getdel retrieves and deletes a value from the cache
func (*RedisCache[T]) Keys ¶
func (c *RedisCache[T]) Keys(ctx context.Context) ([]string, error)
Keys returns all keys in the cache with the given prefix
func (*RedisCache[T]) Set ¶
func (c *RedisCache[T]) Set(ctx context.Context, key string, value T) error
Set stores a value in the cache
func (*RedisCache[T]) SetWithExpiration ¶
func (c *RedisCache[T]) SetWithExpiration(ctx context.Context, key string, value T, expiration time.Duration) error
SetWithExpiration stores a value in the cache with an expiration time
func (*RedisCache[T]) WithCoder ¶
func (c *RedisCache[T]) WithCoder(coder ValueCoder[T]) *RedisCache[T]
WithCoder allows setting a custom value coder
type StringValueCoder ¶
type StringValueCoder struct{}
StringValueCoder implements ValueCoder for string values without JSON encoding