redis

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const EnvPrefix = "REDIS"

Variables

View Source
var ErrConnectionIsNotSet = errors.New("connection is not set")

Functions

func Set

func Set(r *Connection)

Set global client

Types

type Client

type Client interface {
	Get(ctx context.Context, key string) (result string, present bool, err error)
	Set(ctx context.Context, key, value string, ttl time.Duration) error
	Stop() error
}

type Connection

type Connection struct {
	*redis.Client
}

func Default

func Default() (*Connection, error)

Default return default client

func Get

func Get() (*Connection, error)

Get return redis client

func NewRedisClient

func NewRedisClient(config *ConnectionConfig) *Connection

func (Connection) Get

func (c Connection) Get(ctx context.Context, key string) (string, bool, error)

func (Connection) Set

func (c Connection) Set(ctx context.Context, key, value string, expiration time.Duration) error

func (Connection) Stop

func (c Connection) Stop() error

type ConnectionConfig

type ConnectionConfig struct {
	Host     string `env:"_HOST" envDefault:"localhost"`
	Port     string `env:"_PORT" envDefault:"6379"`
	User     string `env:"_USER" envDefault:""`
	Pass     string `env:"_PASS" envDefault:""`
	Database int    `env:"_DATABASE" envDefault:"0"`
}

func GetConnectionConfigFromEnv

func GetConnectionConfigFromEnv() (*ConnectionConfig, error)

Directories

Path Synopsis
Package mock_redis is a generated GoMock package.
Package mock_redis is a generated GoMock package.

Jump to

Keyboard shortcuts

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