redis

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package redis provides Redis connection and key-value helpers.

New code should use explicit connection ownership and core-owned command shapes:

import "github.com/InsideGallery/core/db/redis"

store := redis.NewConnectionStore(redis.NewRedisClient(config))
conn, err := store.Get()

Prefer KeyValueStore with GetOptions, SetOptions, StringResult, and CommandResult for application-facing code.

Compatibility: package-level Set, Get, and Default remain available for existing consumers. Prefer NewRedisClient or ConnectionStore.GetOrCreate with explicit configuration in new code.

Index

Constants

View Source
const EnvPrefix = "REDIS"

Variables

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

Functions

func Set deprecated

func Set(r *Connection)

Set global client

Deprecated: use ConnectionStore.Set on an explicit store.

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 CommandResult added in v1.1.0

type CommandResult struct {
	Key string
}

CommandResult is the core-owned result for Redis commands.

type Connection deprecated

type Connection struct {
	*redis.Client
}

Connection is the legacy Redis SDK wrapper.

Deprecated: use KeyValueStore and core-owned option/result types for new code.

func Default deprecated

func Default() (*Connection, error)

Default return default client

Deprecated: use NewRedisClient or ConnectionStore.GetOrCreate with explicit config.

func Get deprecated

func Get() (*Connection, error)

Get return redis client

Deprecated: use ConnectionStore.Get on an explicit store.

func NewRedisClient deprecated

func NewRedisClient(config *ConnectionConfig) *Connection

NewRedisClient creates the legacy Redis SDK wrapper.

Deprecated: use KeyValueStore methods on Connection for new code.

func (Connection) Get

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

func (Connection) GetValue added in v1.1.0

func (c Connection) GetValue(ctx context.Context, options GetOptions) (StringResult, error)

GetValue reads a Redis string value with core-owned options.

func (Connection) Set

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

func (Connection) SetValue added in v1.1.0

func (c Connection) SetValue(ctx context.Context, options SetOptions) (CommandResult, error)

SetValue writes a Redis string value with core-owned options.

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)

type ConnectionStore added in v1.1.0

type ConnectionStore struct {
	// contains filtered or unexported fields
}

ConnectionStore owns a Redis client for explicit application composition.

func NewConnectionStore added in v1.1.0

func NewConnectionStore(client *Connection) *ConnectionStore

NewConnectionStore creates a Redis connection store with an optional existing client.

func (*ConnectionStore) Close added in v1.1.0

func (s *ConnectionStore) Close() error

Close closes the stored Redis connection and clears this store.

func (*ConnectionStore) Get added in v1.1.0

func (s *ConnectionStore) Get() (*Connection, error)

Get returns the Redis connection from this store.

func (*ConnectionStore) GetOrCreate added in v1.1.0

func (s *ConnectionStore) GetOrCreate(config *ConnectionConfig) (*Connection, error)

GetOrCreate returns or creates a Redis connection from explicit config.

func (*ConnectionStore) Set added in v1.1.0

func (s *ConnectionStore) Set(client *Connection)

Set stores a Redis connection in this store.

type GetOptions added in v1.1.0

type GetOptions struct {
	Key string
}

GetOptions is the core-owned input for reading a Redis string value.

type KeyValueStore added in v1.1.0

type KeyValueStore interface {
	GetValue(ctx context.Context, options GetOptions) (StringResult, error)
	SetValue(ctx context.Context, options SetOptions) (CommandResult, error)
	Stop() error
}

KeyValueStore is the core-owned Redis contract for new consumers.

type SetOptions added in v1.1.0

type SetOptions struct {
	Key   string
	Value string
	TTL   time.Duration
}

SetOptions is the core-owned input for writing a Redis string value.

type StringResult added in v1.1.0

type StringResult struct {
	Key     string
	Value   string
	Present bool
}

StringResult is the core-owned result for Redis string reads.

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