add password configuration to Valkey settings
This commit is contained in:
@@ -11,7 +11,8 @@
|
|||||||
"host": "127.0.0.1",
|
"host": "127.0.0.1",
|
||||||
"port": "6379",
|
"port": "6379",
|
||||||
"max_conns": 50,
|
"max_conns": 50,
|
||||||
"timeout_ms": 5000
|
"timeout_ms": 5000,
|
||||||
|
"password": "the_valkey_password"
|
||||||
},
|
},
|
||||||
"temp": "value"
|
"temp": "value"
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ type Config struct {
|
|||||||
Port string `json:"port"`
|
Port string `json:"port"`
|
||||||
MaxConns int `json:"max_conns"`
|
MaxConns int `json:"max_conns"`
|
||||||
TimeoutMs int `json:"timeout_ms"`
|
TimeoutMs int `json:"timeout_ms"`
|
||||||
|
Password string `json:"password"` // Add this line
|
||||||
} `json:"valkey"`
|
} `json:"valkey"`
|
||||||
Temp string `json:"temp"`
|
Temp string `json:"temp"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type ValkeyConfig struct {
|
|||||||
Port string `json:"port"`
|
Port string `json:"port"`
|
||||||
MaxConns int `json:"max_conns"`
|
MaxConns int `json:"max_conns"`
|
||||||
TimeoutMs int `json:"timeout_ms"`
|
TimeoutMs int `json:"timeout_ms"`
|
||||||
|
Password string `json:"password"` // Add this line
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadValkeyConfig(file string) (ValkeyConfig, error) {
|
func LoadValkeyConfig(file string) (ValkeyConfig, error) {
|
||||||
@@ -48,21 +49,27 @@ func LoadValkeyConfig(file string) (ValkeyConfig, error) {
|
|||||||
config.TimeoutMs = val
|
config.TimeoutMs = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if password := os.Getenv("VALKEY_PASSWORD"); password != "" {
|
||||||
|
config.Password = password
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectToValkey(configPath string) (valkey.Client, error) {
|
func ConnectToValkey(configPath string) (valkey.Client, error) {
|
||||||
fmt.Println("Loading Valkey configuration...")
|
fmt.Println("Loading configuration...")
|
||||||
valkeyConfig, err := LoadValkeyConfig(configPath)
|
config, err := LoadConfig(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load Valkey config: %v", err)
|
return nil, fmt.Errorf("failed to load config: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Println("Valkey configuration loaded successfully!")
|
fmt.Println("Configuration loaded successfully!")
|
||||||
|
|
||||||
|
valkeyConfig := config.Valkey
|
||||||
|
|
||||||
// Setup Valkey client options
|
// Setup Valkey client options
|
||||||
options := valkey.ClientOption{
|
options := valkey.ClientOption{
|
||||||
InitAddress: []string{fmt.Sprintf("%s:%s", valkeyConfig.Host, valkeyConfig.Port)},
|
InitAddress: []string{fmt.Sprintf("%s:%s", valkeyConfig.Host, valkeyConfig.Port)},
|
||||||
|
Password: valkeyConfig.Password,
|
||||||
// Additional options can be added here if required
|
// Additional options can be added here if required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user