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
|
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func New(config Config) *Adapter {
|
2024-01-14 15:53:37 +00:00
|
|
|
rdb := redis.NewClient(&redis.Options{
|
|
|
|
Addr: fmt.Sprintf("%s:%d", config.Host, config.Port),
|
|
|
|
Password: config.Password,
|
|
|
|
DB: config.DB,
|
|
|
|
})
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
return &Adapter{client: rdb}
|
2024-01-14 15:53:37 +00:00
|
|
|
}
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func (a *Adapter) Client() *redis.Client {
|
2024-01-14 15:53:37 +00:00
|
|
|
return a.client
|
|
|
|
}
|