redis

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package redis provides a Redis-backed implementation of cache.Cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache wraps a Redis client and implements cache.Cache.

func New

func New(redisOpts *goredis.Options, opts ...Option) (*Cache, error)

New creates a Redis cache from go-redis Options.

func NewWithClient

func NewWithClient(client goredis.Cmdable, opts ...Option) (*Cache, error)

NewWithClient wraps an existing go-redis Cmdable (Client, ClusterClient, etc.). If the client implements Close(), it will be called by Cache.Close.

func (*Cache) Clear

func (c *Cache) Clear(ctx context.Context) error

Clear removes keys matching the configured prefix. Without a prefix it runs FLUSHDB (use with care).

func (*Cache) Client

func (c *Cache) Client() goredis.Cmdable

Client exposes the underlying go-redis Cmdable for advanced use.

func (*Cache) Close

func (c *Cache) Close() error

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

func (*Cache) Exists

func (c *Cache) Exists(ctx context.Context, key string) (bool, error)

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) ([]byte, error)

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

type Option

type Option func(*config)

Option configures a Redis cache.

func WithDefaultTTL

func WithDefaultTTL(ttl time.Duration) Option

WithDefaultTTL sets the default TTL used when Set is called with ttl == 0.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets a key prefix.

Jump to

Keyboard shortcuts

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