wynn/go/pkg/services/redis/component.go
a 9a5864b152
Some checks failed
commit-tag / commit-tag-image (push) Successful in 18s
commit-tag / commit-tag-image (./cmd/caddy) (push) Failing after 1m4s
noot
2025-03-02 02:38:31 -06:00

48 lines
654 B
Go

package redis
import (
"context"
"log/slog"
"github.com/redis/rueidis"
"go.uber.org/config"
"go.uber.org/fx"
)
type Params struct {
fx.In
Config config.Provider
Ctx context.Context
Lc fx.Lifecycle
Log *slog.Logger
}
type Result struct {
fx.Out
client rueidis.Client
}
func New(p Params) (r Result, err error) {
var cfg struct {
Url string
}
err = p.Config.Get("redis").Populate(&cfg)
if err != nil {
return
}
redisConfig, err := rueidis.ParseURL(cfg.Url)
if err != nil {
return r, err
}
redisClient, err := rueidis.NewClient(redisConfig)
if err != nil {
return r, err
}
r.client = redisClient
return
}