mredis

package
v2.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client = submodule.MakeModifiable[*RedisClient](func(self submodule.Self, config RedisConfig, logger *slog.Logger) (*RedisClient, error) {
	logger.Debug("parsing config", "config object", config)
	opts, e := redis.ParseURL(config.Url)
	if e != nil {
		logger.Error("invalid configuration form", "config", config, slog.Any("error", e))
		return nil, e
	}

	client := redis.NewClient(opts)

	logger.Debug("trying to connect to redis", "url", config.Url)
	e = client.Ping(context.TODO()).Err()

	if e != nil {
		logger.Error("failed to ping redis server, is it connected?", slog.Any("error", e), "url", config.Url)
		return nil, e
	}

	self.Scope.AppendMiddleware(submodule.WithScopeEnd(func() error {
		logger.Info("closing redis client")
		return client.Close()
	}))

	return client, nil
}, defaultRedisConfigMod, mlogger.CreateLogger("redis"))

Functions

func AlterConfig

func AlterConfig(c func(*RedisConfig))

func Reset

func Reset()

Types

type RedisClient

type RedisClient = redis.Client

type RedisConfig

type RedisConfig struct {
	Url string
}

type RedisOptions

type RedisOptions = redis.Options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL