redis

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package redis provides a redis interface for http caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v1.3.0

func New(config Config) (httpcache.Cache, error)

New creates a new Cache with the given configuration. It establishes a connection pool to Redis. The caller should call Close() on the returned cache when done to clean up resources.

func NewWithClient

func NewWithClient(client redis.Conn) httpcache.Cache

NewWithClient returns a new Cache with the given redis connection. This constructor is useful for backwards compatibility or when you want to manage the connection yourself. Note: This creates a single-connection cache. For production use with connection pooling, use New() instead.

Types

type Config added in v1.3.0

type Config struct {
	// Address is the Redis server address (e.g., "localhost:6379").
	// Required field.
	Address string

	// Password is the Redis password for authentication.
	// Optional - leave empty if no authentication is required.
	Password string

	// DB is the Redis database number to use.
	// Optional - defaults to 0.
	DB int

	// MaxIdle is the maximum number of idle connections in the pool.
	// Optional - defaults to 10.
	MaxIdle int

	// MaxActive is the maximum number of active connections in the pool.
	// Optional - defaults to 100. Set to 0 for unlimited.
	MaxActive int

	// IdleTimeout is the duration after which idle connections are closed.
	// Optional - defaults to 5 minutes.
	IdleTimeout time.Duration

	// ConnectTimeout is the timeout for connecting to Redis.
	// Optional - defaults to 5 seconds.
	ConnectTimeout time.Duration

	// ReadTimeout is the timeout for reading from Redis.
	// Optional - defaults to 5 seconds.
	ReadTimeout time.Duration

	// WriteTimeout is the timeout for writing to Redis.
	// Optional - defaults to 5 seconds.
	WriteTimeout time.Duration
}

Config holds the configuration for creating a Redis cache.

func DefaultConfig added in v1.3.0

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

Jump to

Keyboard shortcuts

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