cache

package
v0.0.0-...-777b0ca Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package cache holds the library for interacting with redis

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Healthcheck

func Healthcheck(c *redis.Client) func(ctx context.Context) error

Healthcheck pings the client to check if the connection is working

func New

func New(c Config) *redis.Client

New returns a new redis client based on the configuration settings

Types

type Config

type Config struct {
	// Enabled to enable redis client in the server
	Enabled bool `json:"enabled" koanf:"enabled" default:"true"`
	// Address is the host:port to connect to redis
	Address string `json:"address" koanf:"address" default:"localhost:6379"`
	// Name of the connecting client
	Name string `json:"name" koanf:"name" default:"central-server"`
	// Username to connect to redis
	Username string `json:"username" koanf:"username"`
	// Password, must match the password specified in the server configuration
	Password string `json:"password" koanf:"password"`
	// DB to be selected after connecting to the server, 0 uses the default
	DB int `json:"db" koanf:"db" default:"0"`
	// Dial timeout for establishing new connections, defaults to 5s
	DialTimeout time.Duration `json:"dialTimeout" koanf:"dialTimeout" default:"5s"`
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Supported values:
	//   - `0` - default timeout (3 seconds).
	//   - `-1` - no timeout (block indefinitely).
	//   - `-2` - disables SetReadDeadline calls completely.
	ReadTimeout time.Duration `json:"readTimeout" koanf:"readTimeout" default:"0"`
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.  Supported values:
	//   - `0` - default timeout (3 seconds).
	//   - `-1` - no timeout (block indefinitely).
	//   - `-2` - disables SetWriteDeadline calls completely.
	WriteTimeout time.Duration `json:"writeTimeout" koanf:"writeTimeout" default:"0"`
	// MaxRetries before giving up.
	// Default is 3 retries; -1 (not 0) disables retries.
	MaxRetries int `json:"maxRetries" koanf:"maxRetries" default:"3"`
	// MinIdleConns is useful when establishing new connection is slow.
	// Default is 0. the idle connections are not closed by default.
	MinIdleConns int `json:"minIdleConns" koanf:"minIdleConns" default:"0"`
	// Maximum number of idle connections.
	// Default is 0. the idle connections are not closed by default.
	MaxIdleConns int `json:"maxIdleConns" koanf:"maxIdleConns" default:"0"`
	// Maximum number of connections allocated by the pool at a given time.
	// When zero, there is no limit on the number of connections in the pool.
	MaxActiveConns int `json:"maxActiveConns" koanf:"maxActiveConns" default:"0"`
}

Config for the redis client used to store key-value pairs

Jump to

Keyboard shortcuts

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