redis

package module
v0.0.0-...-edaca3c Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package redis provides a Cache implementation and simple distributed locking built on Redis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseConnection

func CloseConnection() error

CloseConnection closes the package-level singleton connection, if present.

func IsConnectionInstantiated

func IsConnectionInstantiated() bool

IsConnectionInstantiated reports whether the package-level singleton connection exists.

func NewClient

func NewClient(options sop.TransactionOptions) sop.L2Cache

NewClient returns a Cache backed by the default shared Redis connection. The underlying connection must have been initialized via package-level setup.

func NewConnectionClient

func NewConnectionClient(options Options) sop.CloseableCache

NewConnectionClient opens a new Redis connection with the given options and returns a CloseableCache. Call Close on the returned cache when no longer needed. Useful for isolating blob-related caches.

Types

type Connection

type Connection struct {
	Client  *redis.Client
	Options Options
}

Connection wraps a redis.Client and the Options used to create it.

func OpenConnection

func OpenConnection(options Options) (*Connection, error)

OpenConnection initializes and returns the package-level singleton connection. Subsequent calls return the same connection.

func OpenConnectionWithURL

func OpenConnectionWithURL(url string) (*Connection, error)

OpenConnectionWithURL initializes and returns the package-level singleton connection using a Redis URI.

type Options

type Options struct {
	// Address is the host:port of the Redis server/cluster.
	Address string
	// Password is the password used to authenticate.
	Password string
	// DB is the database index to select.
	DB int
	// TLSConfig contains TLS configuration for secure connections.
	TLSConfig *tls.Config

	// DialTimeout specifies the timeout for connecting to Redis.
	DialTimeout time.Duration
	// ReadTimeout specifies the timeout for reading from Redis.
	ReadTimeout time.Duration
	// WriteTimeout specifies the timeout for writing to Redis.
	WriteTimeout time.Duration
	// MaxRetries is the maximum number of retries before giving up on Redis connection.
	MaxRetries int
}

Options holds configuration for connecting to a Redis server or cluster.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns an Options with localhost defaults (no password, DB 0).

Jump to

Keyboard shortcuts

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