Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Flags = []cli.Flag{ &cli.StringFlag{ Name: redisURL, Value: "redis://localhost:6379/0", Usage: "Redis connection URL", EnvVars: []string{"REDIS_URL"}, }, }
Flags defines the CLI flags available for configuring the Redis connection. These flags enable the URL to be set via command-line arguments or environment variables.
var Module = fx.Options( fx.Provide(NewRedisClient), )
Module provides the Redis client as an Fx module, enabling dependency injection for applications that require Redis as a data store.
Functions ¶
func NewRedisClient ¶
NewRedisClient initializes and returns a new Redis client instance configured with the provided Redis server URL from Config. This function parses the URL, creates a Redis client using the go-redis library, and ensures that the client can connect to the specified Redis server.
Parameters:
- cfg (*Config): The configuration struct containing the Redis server URL.
Returns:
- (*libredis.Client): The initialized Redis client instance.
- (error): An error if URL parsing or client creation fails.
Types ¶
type Config ¶
type Config struct {
URL string // The Redis connection URL
}
Config represents the configuration settings required to connect to the Redis server. It includes a single field, URL, which specifies the Redis connection URL.
func GetRedisConfig ¶
func GetRedisConfig(c *cli.Context) *Config
GetRedisConfig reads the Redis URL from the CLI context, allowing configuration via command-line arguments or environment variables.
Parameters:
- c (*cli.Context): The CLI context containing flag and environment variable values.
Returns:
- (*Config): A Config struct populated with the Redis URL.