← ClaudeAtlas

redis-golisted

Go Redis 专家 - 使用 go-redis/v9 实现缓存模式(Cache-Aside/Singleflight/双层缓存)、分布式锁(SETNX/Lua/Redlock)、限流(令牌桶/滑动窗口)、Pipeline批量操作、Pub/Sub消息、数据结构(排行榜/布隆过滤器/HyperLogLog)、Lua脚本、集群/Sentinel连接。适用:缓存、会话存储、排行榜、实时计数、分布式锁、消息队列。不适用:持久化主存储(Redis非唯一数据源)、复杂关联查询(应使用关系型数据库)、强一致性事务(Redis事务不支持回滚)。触发词:redis, 缓存, cache, 分布式锁, distributed lock, 限流, 排行榜, leaderboard, pub/sub, lua脚本, pipeline, go-redis
omeyang/Thoth · ★ 0 · AI & Automation · score 73
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 检查 }