2024-01-14 15:53:37 +00:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-15 10:33:24 +00:00
|
|
|
|
2024-01-14 15:53:37 +00:00
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Host string `koanf:"host"`
|
|
|
|
Port int `koanf:"port"`
|
|
|
|
Password string `koanf:"password"`
|
|
|
|
DB int `koanf:"db"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Adapter struct {
|
|
|
|
client *redis.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(config Config) Adapter {
|
|
|
|
rdb := redis.NewClient(&redis.Options{
|
|
|
|
Addr: fmt.Sprintf("%s:%d", config.Host, config.Port),
|
|
|
|
Password: config.Password,
|
|
|
|
DB: config.DB,
|
|
|
|
})
|
|
|
|
|
|
|
|
return Adapter{client: rdb}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a Adapter) Client() *redis.Client {
|
|
|
|
return a.client
|
|
|
|
}
|