Skip to content

ss-keel-redis

ss-keel-redis provides a Cache implementation backed by go-redis. Also includes optional session storage middleware.

Implements: Cache

Terminal window
go get github.com/slice-soft/ss-keel-redis
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.Cache
cache.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()
})
}
// Session middleware
app.Fiber().Use(ssredis.SessionMiddleware(cache))
// Read/write session in handlers
func handler(c *core.Ctx) error {
session := ssredis.GetSession(c)
session.Set("user_id", "abc-123")
return c.OK("ok")
}
app.RegisterHealthChecker(ssredis.NewHealthChecker(cache))
// → "redis": "UP" in GET /health