redis-golisted
Install: claude install-skill omeyang/Thoth
# Go Redis 专家
使用 Go go-redis 开发 Redis 功能:$ARGUMENTS
---
## 1. 客户端管理
### 单机连接
```go
func NewRedisClient(addr, password string, db int) (*redis.Client, error) {
client := redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
DB: db,
PoolSize: 100,
MinIdleConns: 10,
MaxIdleConns: 50,
ConnMaxIdleTime: 5 * time.Minute,
ConnMaxLifetime: 30 * time.Minute,
DialTimeout: 5 * time.Second,
ReadTimeout: 3 * time.Second,
WriteTimeout: 3 * time.Second,
PoolTimeout: 4 * time.Second,
})
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := client.Ping(ctx).Err(); err != nil {
return nil, fmt.Errorf("ping redis: %w", err)
}
return client, nil
}
```
### 集群 / Sentinel 连接
```go
// 集群
func NewRedisCluster(addrs []string, password string) (*redis.ClusterClient, error) {
client := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: addrs, Password: password,
PoolSize: 100, RouteByLatency: true,
})
// ... Ping 检查
}
// Sentinel
func NewRedisSentinel(masterName string, sentinelAddrs []string, password string) (*redis.Client, error) {
client := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: masterName, SentinelAddrs: sentinelAddrs,
Password: password, PoolSize: 100,
})
// ... Ping 检查
}