Documentation
¶
Index ¶
- type Binding
- type Config
- type Handle
- type Option
- type ProfileState
- type ProfileStatus
- type RedisProfile
- type Registry
- func (r *Registry) Bind(name string) (*Handle, error)
- func (r *Registry) ByProfile(name string) (*Handle, error)
- func (r *Registry) Client(name string) (goredis.UniversalClient, error)
- func (r *Registry) Close() error
- func (r *Registry) Connect() error
- func (r *Registry) Default() (*Handle, error)
- func (r *Registry) HasConnections() bool
- func (r *Registry) HealthCheck(ctx context.Context) error
- func (r *Registry) Profiles() []RedisProfile
- func (r *Registry) Status(name string) ProfileStatus
- func (r *Registry) Statuses() map[string]ProfileStatus
- type Runtime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string `json:"host" mapstructure:"host"`
Port int `json:"port" mapstructure:"port"`
Addrs []string `json:"addrs" mapstructure:"addrs"`
Username string `json:"username" mapstructure:"username"`
Password string `json:"password" mapstructure:"password"`
Database int `json:"database" mapstructure:"database"`
MaxIdle int `json:"max-idle" mapstructure:"max-idle"`
MaxActive int `json:"max-active" mapstructure:"max-active"`
Timeout int `json:"timeout" mapstructure:"timeout"`
MinIdleConns int `json:"min-idle-conns" mapstructure:"min-idle-conns"`
PoolTimeout int `json:"pool-timeout" mapstructure:"pool-timeout"`
DialTimeout int `json:"dial-timeout" mapstructure:"dial-timeout"`
ReadTimeout int `json:"read-timeout" mapstructure:"read-timeout"`
WriteTimeout int `json:"write-timeout" mapstructure:"write-timeout"`
EnableCluster bool `json:"enable-cluster" mapstructure:"enable-cluster"`
UseSSL bool `json:"use-ssl" mapstructure:"use-ssl"`
SSLInsecureSkipVerify bool `json:"ssl-insecure-skip-verify" mapstructure:"ssl-insecure-skip-verify"`
}
Config 描述单个 Redis profile 的连接策略。
func MergeConfig ¶
MergeConfig 使用 override 配置覆盖 base 配置。
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle 封装了 Redis 客户端及其解析后的 profile 元数据。
func (*Handle) HealthCheck ¶
HealthCheck 检查底层 Redis 客户端健康状态。
type Option ¶
type Option func(*Registry)
func WithFallbackOnMissing ¶
WithFallbackOnMissing 控制缺失命名 profile 时是否回退到默认 profile。
func WithProfileObserver ¶
func WithProfileObserver(observer observability.ProfileObserver) Option
WithProfileObserver 注册 profile 状态变化观测器。
type ProfileState ¶
type ProfileState string
ProfileState 表示已配置 profile 的健康状态。
const ( ProfileStateMissing ProfileState = "missing" ProfileStateAvailable ProfileState = "available" )
type ProfileStatus ¶
type ProfileStatus struct {
Name string
State ProfileState
Err error
NextRetryAt time.Time
}
ProfileStatus 描述 profile 当前的可用性状态。
type RedisProfile ¶
type RedisProfile struct {
Name string
Config Config
Status ProfileStatus
}
RedisProfile 描述一个已配置的命名 profile。
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 基于默认 profile 与命名 profile 实现 Runtime 门面。
func (*Registry) Client ¶
func (r *Registry) Client(name string) (goredis.UniversalClient, error)
Client 返回绑定解析后的 Redis 客户端。
func (*Registry) HasConnections ¶
HasConnections 返回运行时是否至少存在一个已配置连接。
func (*Registry) HealthCheck ¶
HealthCheck 检查已配置 Redis 连接,并在可重试时尝试恢复。
func (*Registry) Profiles ¶
func (r *Registry) Profiles() []RedisProfile
Profiles 返回已配置命名 profile 及其状态快照。
func (*Registry) Status ¶
func (r *Registry) Status(name string) ProfileStatus
Status 返回指定命名 profile 的当前状态。
func (*Registry) Statuses ¶
func (r *Registry) Statuses() map[string]ProfileStatus
Statuses 返回所有已配置命名 profile 的状态快照。
type Runtime ¶
type Runtime interface {
HasConnections() bool
Connect() error
Close() error
HealthCheck(ctx context.Context) error
Default() (*Handle, error)
ByProfile(name string) (*Handle, error)
Bind(name string) (*Handle, error)
Client(name string) (goredis.UniversalClient, error)
Status(name string) ProfileStatus
Statuses() map[string]ProfileStatus
Profiles() []RedisProfile
}
Runtime 定义稳定的 Redis 运行时门面接口。
Click to show internal directories.
Click to hide internal directories.