Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadFromEnv ¶ added in v0.1.9
func LoadFromEnv() error
Example ¶
ExampleLoadFromEnv shows the typical call-site pattern for LoadFromEnv. It reads Redis connection parameters from the koanf env singleton (keys: redis.clusters, redis.database, redis.password) and initialises the package-level default client via redis.InitDefault.
go-redis creates the client without establishing a connection (lazy dial), so LoadFromEnv always returns nil — connectivity errors are discovered on the first real command instead.
redis.InitDefault uses sync.Once: only the first call takes effect. After LoadFromEnv returns, redis.Default() is non-nil regardless of whether the Redis server is reachable.
package main
import (
"fmt"
"github.com/phcp-tech/common-library-golang/redis"
"github.com/phcp-tech/common-library-golang/redis/loader"
)
func main() {
err := loader.LoadFromEnv()
fmt.Println(err) // <nil> — go-redis is lazy, no immediate connect
fmt.Println(redis.Default() != nil) // true — singleton registered
}
Output: <nil> true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.