Documentation
¶
Overview ¶
Package redis provides Redis service for gorp framework. This file defines Prometheus metrics hook for Redis client monitoring. Includes command count, duration, and connection count metrics.
Redis 包提供 Redis 服务,用于 gorp 框架。 本文件定义用于 Redis 客户端监控的 Prometheus 指标 hook。 包括命令次数、耗时和连接数指标。
Package redis provides Redis service for gorp framework. Supports connection configuration, basic operations (Get/Set/Del/MGet). Includes Prometheus metrics hook for monitoring.
Redis 包提供 Redis 服务,用于 gorp 框架。 支持连接配置、基本操作(Get/Set/Del/MGet)。 包含 Prometheus 指标 hook 用于监控。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct{}
Provider registers Redis service. Core logic: Read redis config, create client with metrics hook, bind to container.
Provider 注册 Redis 服务。 核心逻辑:读取 redis 配置、创建带指标 hook 的客户端、绑定到容器。
func NewProvider ¶
func NewProvider() *Provider
NewProvider creates a new Redis provider.
NewProvider 创建新的 Redis provider。
func (*Provider) Boot ¶
func (p *Provider) Boot(runtimecontract.Container) error
Boot initializes the Redis provider. No additional startup logic required.
Boot 初始化 Redis provider。 无需额外启动逻辑。
func (*Provider) DependsOn ¶
DependsOn returns the keys this provider depends on. Redis provider depends on Config for connection configuration.
DependsOn 返回该 provider 依赖的 key。 Redis provider 依赖 Config 获取连接配置。
func (*Provider) IsDefer ¶
IsDefer indicates Redis provider should not defer loading. Redis may be needed early for caching/session.
IsDefer 表示 Redis provider 不应延迟加载。 Redis 可能早期就被用于缓存/session。
type RedisMetricsHook ¶
type RedisMetricsHook struct{}
RedisMetricsHook 为 Redis 客户端添加指标收集 hook。
中文说明: - 通过 go-redis 的 Hook 接口拦截每次命令执行; - 记录命令执行次数和耗时; - 区分成功和失败的命令(status 标签); - 用于监控 Redis 性能和识别慢命令。
func NewRedisMetricsHook ¶
func NewRedisMetricsHook() *RedisMetricsHook
NewRedisMetricsHook 创建 Redis 指标收集 hook。
func (*RedisMetricsHook) DialHook ¶
func (h *RedisMetricsHook) DialHook(next redis.DialHook) redis.DialHook
DialHook 实现 redis.Hook 接口,透传连接建立。 go-redis 的 Hook 没有连接关闭回调,在 Dial 成功时 Inc 的 Gauge 无人 Dec, 只增不减与真实连接数脱节——曾因此误报连接泄漏告警,故不再在此统计连接数; 需要连接池指标时请从 client.PoolStats() 采集。
func (*RedisMetricsHook) ProcessHook ¶
func (h *RedisMetricsHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook
ProcessHook 实现 redis.Hook 接口,在命令执行前后记录指标。
func (*RedisMetricsHook) ProcessPipelineHook ¶
func (h *RedisMetricsHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook
ProcessPipelineHook 实现 redis.Hook 接口,处理 pipeline 命令。
type RedisPoolCollector ¶ added in v0.2.0
type RedisPoolCollector struct {
// contains filtered or unexported fields
}
RedisPoolCollector 定期从 client.PoolStats() 采集连接池指标。 go-redis 的 Dial/Close 没有成对的连接生命周期钩子,在 Hook 层统计连接数 只会得到只增不减的失真 Gauge;PoolStats 是官方给出的连接池状态来源。
func NewRedisPoolCollector ¶ added in v0.2.0
func NewRedisPoolCollector(client *redis.Client, addr string) *RedisPoolCollector
NewRedisPoolCollector 创建连接池指标采集器。
func (*RedisPoolCollector) Close ¶ added in v0.2.0
func (c *RedisPoolCollector) Close() error
Close 实现 io.Closer,便于 RegisterCloser 接线。
func (*RedisPoolCollector) Start ¶ added in v0.2.0
func (c *RedisPoolCollector) Start()
Start 启动后台采集 goroutine(每 5 秒一次)。
func (*RedisPoolCollector) Stop ¶ added in v0.2.0
func (c *RedisPoolCollector) Stop() error
Stop 停止采集 goroutine。幂等。