rdx

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package rdx 提供 Redis 单机和 Sentinel 客户端初始化,并统一接入应用生命周期。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAddressRequired 表示没有配置 Redis 地址。
	ErrAddressRequired = errx.New("redis address must not be empty")
	// ErrInvalidMode 表示 Redis 连接模式不受支持。
	ErrInvalidMode = errx.New("redis mode must be standalone or sentinel")
	// ErrStandaloneAddressCount 表示单机模式配置了不止一个地址。
	ErrStandaloneAddressCount = errx.New("redis standalone mode requires exactly one address")
	// ErrSentinelMasterRequired 表示 Sentinel 模式没有配置主节点名称。
	ErrSentinelMasterRequired = errx.New("redis sentinel master name must not be empty")
	// ErrInvalidDatabase 表示 Redis 数据库编号无效。
	ErrInvalidDatabase = errx.New("redis database must not be negative")
	// ErrInvalidPoolConfig 表示 Redis 连接池参数无效。
	ErrInvalidPoolConfig = errx.New("redis pool values must not be negative")
)

Functions

This section is empty.

Types

type Client

type Client = redis.UniversalClient

Client 是单机和 Sentinel Redis 客户端共同实现的接口。

func Open

func Open(ctx context.Context, config Config) (Client, error)

Open 校验配置、建立 Redis 连接、执行 Ping,并登记生命周期关闭函数。

type Config

type Config struct {
	Mode             Mode          `json:"mode"`
	Addresses        []string      `json:"addresses"`
	MasterName       string        `json:"master_name"`
	Username         string        `json:"username"`
	Password         string        `json:"password"`
	SentinelUsername string        `json:"sentinel_username"`
	SentinelPassword string        `json:"sentinel_password"`
	Database         int           `json:"database"`
	ClientName       string        `json:"client_name"`
	DialTimeout      time.Duration `json:"dial_timeout"`
	ReadTimeout      time.Duration `json:"read_timeout"`
	WriteTimeout     time.Duration `json:"write_timeout"`
	PoolTimeout      time.Duration `json:"pool_timeout"`
	PoolSize         int           `json:"pool_size"`
	MinIdleConns     int           `json:"min_idle_conns"`
	MaxIdleConns     int           `json:"max_idle_conns"`
	MaxActiveConns   int           `json:"max_active_conns"`
	ConnMaxIdleTime  time.Duration `json:"conn_max_idle_time"`
	ConnMaxLifetime  time.Duration `json:"conn_max_lifetime"`
	TLS              TLSConfig     `json:"tls"`
}

Config 定义 Redis 单机或 Sentinel 客户端参数。

type Mode

type Mode string

Mode 表示 Redis 的连接模式。

const (
	// ModeStandalone 连接一个 Redis 单机节点。
	ModeStandalone Mode = "standalone"
	// ModeSentinel 通过 Sentinel 发现并连接主节点。
	ModeSentinel Mode = "sentinel"
)

type TLSConfig

type TLSConfig struct {
	Enabled    bool   `json:"enabled"`
	ServerName string `json:"server_name"`
}

TLSConfig 定义 Redis TLS 连接参数。

Directories

Path Synopsis
Package lock 提供基于 Redis 的持有者令牌租约锁。
Package lock 提供基于 Redis 的持有者令牌租约锁。

Jump to

Keyboard shortcuts

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