redis

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRedisOptions

func ParseRedisOptions(redisURL string) (*redis.Options, error)

ParseRedisOptions parses a redis:// URL into options.

func Remember

func Remember[T any](ctx context.Context, r *Redis, key string, ttl time.Duration, loader func() (T, error)) (T, error)

Remember returns the cached value for key, or runs loader on a cache miss, stores its result with ttl, and returns it. A failure to store the loaded value does not fail the call.

Types

type Client

type Client = redis.Client

Client is re-exported from go-redis so callers need not import that package directly.

type Redis

type Redis struct {
	Client *Client
}

Redis wraps a go-redis client with JSON (de)serialization helpers.

func New

func New(client *Client) *Redis

New creates a new Redis wrapper.

func (*Redis) Delete

func (r *Redis) Delete(ctx context.Context, keys ...string) error

Delete removes the given keys. It is a no-op (returns nil) when no keys are given.

func (*Redis) Exists

func (r *Redis) Exists(ctx context.Context, key string) (bool, error)

Exists reports whether key is present.

func (*Redis) Expire

func (r *Redis) Expire(ctx context.Context, key string, ttl time.Duration) (bool, error)

Expire sets a time-to-live on key. The returned bool reports whether the key existed (and therefore whether the TTL was applied).

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string, dest interface{}) error

Get reads key and JSON-decodes it into dest. Returns an error on cache miss.

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set JSON-encodes value and stores it under key with the given expiration.

func (*Redis) TTL

func (r *Redis) TTL(ctx context.Context, key string) (time.Duration, error)

TTL returns the remaining lifetime of key. Following go-redis semantics, a missing key yields a negative duration (-2) and a key without an expiry yields -1.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL