/matex-skills:Matex-Setup-Redisfrom matex-skills
Integrates Redis into a Matex project: configures the redis section, implements cache-aside read/write patterns, and adds distributed locking with TTL safety. Activates on phrases like 'setup redis' or 'distributed lock'.
Ships in matex-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Redis 经 pkg/core/redis 使用(go-redis 薄封装 + JSON 助手 + 带 token 的分布式锁),业务不 import go-redis。
redis:
addr: ${REDIS_ADDR:localhost:6379}
password: ""
db: 0
留空/删除 redis: 段即禁用(env.Redis() 返回 ok=false;业务必需时用 env.RequireRedis() 让启动失败)。本地 make dev 起 redis。
func (s *Service) Get(ctx context.Context, id int64) (*Thing, error) {
key := fmt.Sprintf("thing:%d", id)
if s.deps.Redis != nil {
if v, ok, err := redis.GetJSON[Thing](ctx, s.deps.Redis, key); err == nil && ok {
return &v, nil // 命中
}
}
// 回源(DB / 计算)
t, err := s.load(ctx, id)
if err != nil { return nil, err }
if s.deps.Redis != nil {
_ = s.deps.Redis.SetJSON(ctx, key, t, time.Minute) // 写缓存
}
return t, nil
}
redis.GetJSON[T] 返回 (v, ok, err):ok=false 是 miss,err!=nil 是故障/坏值(按需决定当 miss 还是报错)。
release, ok, err := s.deps.Redis.TryLock(ctx, "lock:job:1", 10*time.Second)
if err != nil { return err }
if !ok { return nil, errs.Conflict(40900, "job already running") }
defer release(context.Background()) // 只释放自己持有的锁,ttl 兜底防死锁
matex:thing:1),集中放一个 keys.go 更佳。TryLock 的 release 会校验持有者 token,安全释放。rc := redistest.Start(t) // miniredis 进程内
make ci
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
redis-integration, cache-aside, distributed-lock, go-redis, matex
Other plugins' skills for the same job
npx claudepluginhub smallnest/matex --plugin matex-skills15 skills in this plugin
/Matex-Add-DomainMatex Add Domain在 matex 脚手架中新增一个业务域(handler/service/dao + 路由注册 + 装配 + 测试)。当用户说"新增 domain / 加一个业务域 / 新增模块 / add domain / new domain / 建一个 xx 服务"时使用。/Matex-Setup-Audit-LogMatex Setup Audit Log在 matex 中记录审计日志:pkg/core/audit 的 Record/Event(actor/action/resource/result/detail),默认写结构化日志,可用 SetSink 落库或投递到只追加的存储。当用户说"审计 / 审计日志 / audit log / 操作记录 / 谁改了什么 / 合规 / 不可否认 / access log"时使用。/Matex-Setup-AuthMatex Setup Auth在 matex 中接入认证与授权:配置 auth 段、验签 Bearer token、按路由分级保护、读取当前主体。当用户说"加认证 / 加鉴权 / 接 auth / setup auth / JWT / OIDC / 登录校验 / token 校验 / 权限控制 / RBAC"时使用。/Matex-Setup-CacheMatex Setup Cache在 matex 中接入缓存模式:cache-aside 回源、并发 miss 合并(防击穿)、TTL 抖动(防雪崩)、写后失效。当用户说"加缓存 / 缓存模式 / cache-aside / 防击穿 / 防雪崩 / 缓存击穿 / 缓存穿透 / 缓存一致性 / setup cache"时使用。/Matex-Setup-CronMatex Setup Cron在 matex 中加定时任务:固定周期 / cron 表达式 / 一次性任务,多副本下用 redis 选主保证每个周期(槽)只跑一次。当用户说"定时任务 / 定时器 / cron / cron 表达式 / 周期任务 / 后台任务 / 跑批 / 一次性任务 / one-shot / 延迟执行 / 选主 / leader election / 只能跑一次 / schedule"时使用。/Matex-Setup-DatabaseMatex Setup Database在 matex 中接入 SQL 数据库(PostgreSQL / MySQL / SQLite):配置 db 段、写迁移、写 DAO、跑测试。当用户说"接数据库 / 配 postgres / 配 mysql / 配 sqlite / setup database / 加数据库 / 连数据库 / 写表 / 迁移 / DAO"时使用。