ss-keel-redis
ss-keel-redis provides a Cache implementation backed by go-redis. Also includes optional session storage middleware.
Implements: Cache
Planned Installation
Section titled “Planned Installation”go get github.com/slice-soft/ss-keel-redisPlanned Usage
Section titled “Planned Usage”import "github.com/slice-soft/ss-keel-redis"
cache, err := ssredis.NewCache(ssredis.Config{ URL: os.Getenv("REDIS_URL"), // redis://localhost:6379})
// cache implements core.Cachecache.Set(ctx, "user:123", data, 5*time.Minute)cache.Get(ctx, "user:123")cache.Delete(ctx, "user:123")cache.Exists(ctx, "user:123")Inject into your services through the module:
type UserModule struct{}
func (m *UserModule) Register(app *core.App) { cache, _ := ssredis.NewCache(ssredis.Config{URL: os.Getenv("REDIS_URL")})
service := NewUserService(repo, cache) app.RegisterController(NewUserController(service))
app.OnShutdown(func(ctx context.Context) error { return cache.Close() })}Sessions
Section titled “Sessions”// Session middlewareapp.Fiber().Use(ssredis.SessionMiddleware(cache))
// Read/write session in handlersfunc handler(c *core.Ctx) error { session := ssredis.GetSession(c) session.Set("user_id", "abc-123") return c.OK("ok")}Health Check
Section titled “Health Check”app.RegisterHealthChecker(ssredis.NewHealthChecker(cache))// → "redis": "UP" in GET /health