redis

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package redis provides a Redis client (built on go-redis) with helpers for distributed locks and priority queues.

Index

Constants

View Source
const (
	ErrCodeRedisPingErr                   = "RDS-001"
	ErrCodeRedisPriorityQueuePushErr      = "RDS-002"
	ErrCodeRedisPriorityQueuePopErr       = "RDS-003"
	ErrCodeRedisPriorityQueuePopRemoveErr = "RDS-004"
)
View Source
const (
	NotFound = redis.Nil
)

Variables

View Source
var (
	ErrRedisPingErr = func(cause error) error {
		return jet.NewAppErrBuilder(ErrCodeRedisPingErr, "").Wrap(cause).Err()
	}
	ErrRedisPriorityQueuePushErr = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeRedisPriorityQueuePushErr, "priority queue: push").Wrap(cause).Err()
	}
	ErrRedisPriorityQueuePopErr = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeRedisPriorityQueuePopErr, "priority queue: pop").Wrap(cause).Err()
	}
	ErrRedisPriorityQueuePopRemoveErr = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeRedisPriorityQueuePopRemoveErr, "priority queue: pop and remove").Wrap(cause).Err()
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     string
	Username string
	Password string
	Db       int
	Ttl      uint
}

Config redis config

type PriorityQueue

type PriorityQueue[T any] interface {
	// Push pushes item to queue with the given priority
	Push(ctx context.Context, item T, priority int) error
	// PopManyAndRemove pops requested number of items according to priority and remove them atomically
	PopManyAndRemove(ctx context.Context, numItems int) ([]T, error)
	// Pop pops requested number of items
	Pop(ctx context.Context, numItems int) ([]T, error)
}

func NewPriorityQueue

func NewPriorityQueue[T any](queue string, redis *Redis) PriorityQueue[T]

type Redis

type Redis struct {
	Instance *redis.Client
	Ttl      time.Duration
	// contains filtered or unexported fields
}

func Open

func Open(ctx context.Context, params *Config, logger jet.CLoggerFunc) (*Redis, error)

func (*Redis) Close

func (r *Redis) Close()

func (*Redis) Lock

func (r *Redis) Lock(ctx context.Context, key, unlockId string, ttl time.Duration) (bool, error)

Lock applies distributed lock unlockId allows only process issuing lock to unlock it

func (*Redis) UnLock

func (r *Redis) UnLock(ctx context.Context, key, unlockId string) (bool, error)

UnLock unlocks

Jump to

Keyboard shortcuts

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