fix: use redis config
This commit is contained in:
parent
cf410bdf05
commit
a2a6fe6374
@ -28,6 +28,7 @@ type Config struct {
|
||||
Database Database `mapstructure:"postgresql"`
|
||||
Jwt Jwt `mapstructure:"jwt"`
|
||||
OSSConfig OSSConfig `mapstructure:"oss"`
|
||||
Redis Redis `mapstructure:"redis"`
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
14
config/redis.go
Normal file
14
config/redis.go
Normal file
@ -0,0 +1,14 @@
|
||||
package config
|
||||
|
||||
type Redis struct {
|
||||
Host string `mapstructure:"host"`
|
||||
Port string `mapstructure:"port"`
|
||||
DB int `mapstructure:"db"`
|
||||
Username string `mapstructure:"username"`
|
||||
Password string `mapstructure:"password"`
|
||||
SslMode string `mapstructure:"ssl-mode"`
|
||||
Debug bool `mapstructure:"debug"`
|
||||
MaxIdleConnectionsInSecond int `mapstructure:"max-idle-connections-in-second"`
|
||||
MaxOpenConnectionsInSecond int `mapstructure:"max-open-connections-in-second"`
|
||||
ConnectionMaxLifetimeInSecond int64 `mapstructure:"connection-max-life-time-in-second"`
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package redisaccessor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"legalgo-BE-go/config"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
@ -12,12 +13,13 @@ func Get() *redis.Client {
|
||||
return redisClient
|
||||
}
|
||||
|
||||
func New() *redis.Client {
|
||||
func New(cfg *config.Config) *redis.Client {
|
||||
addr := fmt.Sprintf("%s:%s", cfg.Redis.Host, cfg.Redis.Port)
|
||||
|
||||
redisClient = redis.NewClient(&redis.Options{
|
||||
Username: config.REDIS_USERNAME,
|
||||
Addr: config.REDIS_ADDR,
|
||||
Password: config.REDIS_PASSWORD,
|
||||
DB: config.REDIS_DB,
|
||||
Addr: addr,
|
||||
Password: cfg.Redis.Password,
|
||||
DB: cfg.Redis.DB,
|
||||
})
|
||||
|
||||
return redisClient
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user