redis

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package redis is a cache.Store in Redis, or anything that speaks its protocol (Valkey, KeyDB, Dragonfly), shared by every process of the app. It speaks RESP itself, with the four commands the cache needs, so it adds no dependency.

store, err := redis.New(os.Getenv("REDIS_URL")) // redis://:password@host:6379/0
c := cache.New(store)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error is an error the server answered with.

func (Error) Error

func (e Error) Error() string

type Store

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

Store is a cache.Store in Redis.

func New

func New(rawURL string) (*Store, error)

New connects to the server at rawURL, redis://[user:password@]host:port[/db] or rediss:// for TLS. Connections are made as needed, up to 16 idle.

func (*Store) Close

func (s *Store) Close() error

Close closes the idle connections.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, keys ...string) error

Delete implements cache.Store.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, bool, error)

Get implements cache.Store.

func (*Store) Incr

func (s *Store) Incr(ctx context.Context, key string) (int64, error)

Incr implements cache.Store.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks that the server answers.

func (*Store) Set

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

Set implements cache.Store.

Jump to

Keyboard shortcuts

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