()
| 8 | ) |
| 9 | |
| 10 | func InitRedis() redis.Cmdable { |
| 11 | // 初始化 Redis 客户端 |
| 12 | client := redis.NewClient(&redis.Options{ |
| 13 | Addr: viper.GetString("redis.addr"), |
| 14 | Password: viper.GetString("redis.password"), |
| 15 | }) |
| 16 | |
| 17 | // 创建并注册自定义的 RedisMetricsHook 插件 |
| 18 | prometheusHook := prometheus2.NewRedisMetricsHook(prometheus.SummaryOpts{ |
| 19 | Namespace: "linkme", |
| 20 | Subsystem: "redis", |
| 21 | Name: "operation_duration_seconds", |
| 22 | Help: "Duration of Redis operations in seconds", |
| 23 | Objectives: map[float64]float64{ |
| 24 | 0.5: 0.01, |
| 25 | 0.75: 0.01, |
| 26 | 0.9: 0.01, |
| 27 | 0.99: 0.001, |
| 28 | }, |
| 29 | }) |
| 30 | |
| 31 | // 添加 Hook 插件到 Redis 客户端 |
| 32 | client.AddHook(prometheusHook) |
| 33 | |
| 34 | return client |
| 35 | } |
no outgoing calls