template-monorepo/internal/library/redis
王性驊 49e7099bf2 add notification and member modules with local dev stack
Implement outbound notification (sync/async, idempotency, quota, DLQ),
member OTP/verification, SMTP/SES/Mitake providers, shared Redis wiring,
docker-compose for Mongo/Redis, and gateway config documentation.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-20 15:01:08 +08:00
..
README.md add notification and member modules with local dev stack 2026-05-20 15:01:08 +08:00
client.go add notification and member modules with local dev stack 2026-05-20 15:01:08 +08:00
client_test.go add notification and member modules with local dev stack 2026-05-20 15:01:08 +08:00

README.md

Redis(Gateway 共用連線)

用途

  • 在 svc.ServiceContext 建立一次 *redis.Client,全進程共用 go-zero 的 connection pool(同一 Addr 只會有一個 pool)。
  • 各 internal/model/{module} 的 factory / repository 注入此 client,禁止在 module 內 go-redis.NewClient 或重複 MustNewRedis。

使用

import redislib "gateway/internal/library/redis"

rds, err := redislib.NewClient(c.Redis) // Host 空 → (nil, nil)
rds.Zero() // *github.com/zeromicro/go-zero/core/stores/redis.Redis

與 Mongo 對照

Mongo Redis
封裝 library/mongo library/redis
共用機制 go-zero mon.clientManager(key = URI) go-zero redis.clientManager(key = Addr)
模組內 每 collection 一個 repository 共用 client + 模組 redis.go 定義 key