redis

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConfigured = errors.New("redis not configured")
View Source
var ErrPipelineFailed = errors.New("redis pipeline failed")

Functions

func NewNoop

func NewNoop() *noopClient

Types

type Client

type Client interface {
	Get(ctx context.Context, key string) ([]byte, error)
	MGet(ctx context.Context, keys ...string) (map[string][]byte, error)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	MSet(ctx context.Context, values map[string][]byte, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
	Pipeline(ctx context.Context, commands ...Command) ([]Result, error)
}

type ClusterConfig

type ClusterConfig struct {
	Enabled         bool
	Addrs           []string
	RouteByLatency  bool
	RouteRandomly   bool
	ReadOnly        bool
	MaxRedirects    int
	Username        string
	Password        string
	UseReplicasOnly bool
}

type Command

type Command struct {
	Name  string
	Key   string
	Value []byte
	TTL   time.Duration
	Args  []any
}

func (Command) Clone

func (c Command) Clone() Command

type Config

type Config struct {
	Mode      Mode
	Endpoint  Endpoint
	Cluster   ClusterConfig
	Pool      PoolConfig
	Retry     RetryConfig
	Timeout   TimeoutConfig
	TLS       TLSConfig
	Namespace string
}

func NewConfig

func NewConfig(options ...Option) Config

type Endpoint

type Endpoint struct {
	Address  string
	Username string
	Password string
	Database int
}

type Mode

type Mode string
const (
	ModeStandalone Mode = "standalone"
	ModeCluster    Mode = "cluster"
)

type OperationEvent

type OperationEvent struct {
	Name         string
	Key          string
	Keys         []string
	CommandCount int
	StartedAt    time.Time
	Duration     time.Duration
	Err          error
}

func (OperationEvent) Clone

func (e OperationEvent) Clone() OperationEvent

type OperationHook

type OperationHook interface {
	BeforeRedis(ctx context.Context, event OperationEvent) context.Context
	AfterRedis(ctx context.Context, event OperationEvent)
}

type OperationHookFuncs

type OperationHookFuncs struct {
	Before func(ctx context.Context, event OperationEvent) context.Context
	After  func(ctx context.Context, event OperationEvent)
}

func (OperationHookFuncs) AfterRedis

func (h OperationHookFuncs) AfterRedis(ctx context.Context, event OperationEvent)

func (OperationHookFuncs) BeforeRedis

func (h OperationHookFuncs) BeforeRedis(ctx context.Context, event OperationEvent) context.Context

type Option

type Option func(*Options)

func WithAddress

func WithAddress(address string) Option

func WithCluster

func WithCluster(addrs ...string) Option

func WithDatabase

func WithDatabase(database int) Option

func WithNamespace

func WithNamespace(namespace string) Option

func WithOperationHooks

func WithOperationHooks(hooks ...OperationHook) Option

func WithPool

func WithPool(pool PoolConfig) Option

func WithRetry

func WithRetry(retry RetryConfig) Option

func WithTLS

func WithTLS(tls TLSConfig) Option

func WithTimeouts

func WithTimeouts(timeout TimeoutConfig) Option

type Options

type Options struct {
	Address   string
	Addrs     []string
	Database  int
	Namespace string
	Cluster   ClusterConfig
	Pool      PoolConfig
	Retry     RetryConfig
	Timeout   TimeoutConfig
	TLS       TLSConfig
	Hooks     []OperationHook
}

func NewOptions

func NewOptions(options ...Option) Options

type Pipeline

type Pipeline interface {
	Do(ctx context.Context, commands ...Command) ([]Result, error)
}

type PipelineError

type PipelineError struct {
	Results []Result
}

func (PipelineError) Error

func (e PipelineError) Error() string

func (PipelineError) Is

func (e PipelineError) Is(target error) bool

func (PipelineError) Unwrap

func (e PipelineError) Unwrap() error

type PoolConfig

type PoolConfig struct {
	Size            int
	MinIdle         int
	MaxIdle         int
	MaxActive       int
	MaxLifetime     time.Duration
	IdleTimeout     time.Duration
	WaitTimeout     time.Duration
	ConnMaxIdleTime time.Duration
}

type Result

type Result struct {
	Command Command
	Value   []byte
	Err     error
}

func (Result) Clone

func (r Result) Clone() Result

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	BackoffMin  time.Duration
	BackoffMax  time.Duration
}

type Stats

type Stats struct {
	Commands  int64
	Hits      int64
	Misses    int64
	Sets      int64
	Deletes   int64
	Pipelines int64
	Errors    int64
}

func (Stats) Clone

func (s Stats) Clone() Stats

type Statser

type Statser interface {
	Stats() Stats
}

type TLSConfig

type TLSConfig struct {
	Enabled            bool
	ServerName         string
	InsecureSkipVerify bool
	MinVersion         string
}

type TimeoutConfig

type TimeoutConfig struct {
	Dial  time.Duration
	Read  time.Duration
	Write time.Duration
	Pool  time.Duration
}

Jump to

Keyboard shortcuts

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