1package redis
2
3import (
4 "github.com/charmbracelet/soft-serve/server/config"
5)
6
7// Config is the configuration for the Redis cache.
8type Config struct {
9 // Addr is the Redis address [host][:port].
10 Addr string `env:"ADDR" yaml:"addr"`
11 // Username is the Redis username.
12 Username string `env:"USERNAME" yaml:"username"`
13 // Password is the Redis password.
14 Password string `env:"PASSWORD" yaml:"password"`
15 // DB is the Redis database.
16 DB int `env:"DB" yaml:"db"`
17}
18
19// NewConfig returns a new Redis cache configuration.
20// If path is empty, the default config path will be used.
21//
22// TODO: add support for TLS and other Redis options.
23func NewConfig(path string) (*Config, error) {
24 if path == "" {
25 path = config.DefaultConfig().FilePath()
26 }
27
28 cfg := DefaultConfig()
29 wrapper := &struct {
30 Redis *Config `envPrefix:"REDIS_" yaml:"redis"`
31 }{
32 Redis: cfg,
33 }
34
35 if err := config.ParseConfig(wrapper, path); err != nil {
36 return cfg, err
37 }
38
39 return cfg, nil
40}
41
42// DefaultConfig returns the default configuration for the Redis cache.
43func DefaultConfig() *Config {
44 return &Config{
45 Addr: "localhost:6379",
46 }
47}