redisx

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalClient redis.UniversalClient

Functions

func Decr

func Decr(ctx context.Context, key string, expire time.Duration) (int64, error)

func DecrByClient

func DecrByClient(ctx context.Context, cli redis.UniversalClient, key string, expire time.Duration) (int64, error)

func Del

func Del(ctx context.Context, key string) error

func DelByClient

func DelByClient(ctx context.Context, cli redis.UniversalClient, key string) error

func Get

func Get[T any](ctx context.Context, key string) (T, error)

func GetByClient

func GetByClient[T any](ctx context.Context, cli redis.UniversalClient, key string) (T, error)

func Incr

func Incr(ctx context.Context, key string, expire time.Duration) (int64, error)

func IncrByClient

func IncrByClient(ctx context.Context, cli redis.UniversalClient, key string, expire time.Duration) (int64, error)

func Set

func Set[T any](ctx context.Context, key string, value T, expire time.Duration) error

func SetByClient

func SetByClient[T any](ctx context.Context, cli redis.UniversalClient, key string, value T, expire time.Duration) error

func SetClient

func SetClient(cli redis.UniversalClient)

Types

type Element

type Element[T any] struct {
	Member T     `json:"member"`
	Score  int64 `json:"score"`
}

Element z set element

type ElementList

type ElementList[T any] []Element[T]

func (ElementList[T]) Members

func (e ElementList[T]) Members() []T

type HashMap

type HashMap[K comparable, V any] struct {
	Key string
	Cli redis.UniversalClient
}

func NewHashMap

func NewHashMap[K comparable, V any](cli redis.UniversalClient, key string) *HashMap[K, V]

func (*HashMap[K, V]) Delete

func (h *HashMap[K, V]) Delete(ctx context.Context, fields ...K) error

Delete deletes fields from the hash

func (*HashMap[K, V]) Exists

func (h *HashMap[K, V]) Exists(ctx context.Context, field K) (bool, error)

Exists checks if a field exists in the hash

func (*HashMap[K, V]) Get

func (h *HashMap[K, V]) Get(ctx context.Context, field K) (V, error)

Get gets a field from the hash

func (*HashMap[K, V]) GetAll

func (h *HashMap[K, V]) GetAll(ctx context.Context) (map[K]V, error)

GetAll gets all fields and values from the hash

func (*HashMap[K, V]) GetMulti

func (h *HashMap[K, V]) GetMulti(ctx context.Context, fields []K) (map[K]V, error)

GetMulti gets multiple fields from the hash

func (*HashMap[K, V]) Incr

func (h *HashMap[K, V]) Incr(ctx context.Context, field K, increment int64, expire time.Duration) (int64, error)

Incr increments the integer value of a field by the given amount

func (*HashMap[K, V]) IncrFloat

func (h *HashMap[K, V]) IncrFloat(ctx context.Context, field K, increment float64, expire time.Duration) (float64, error)

IncrFloat increments the float value of a field by the given amount

func (*HashMap[K, V]) Keys

func (h *HashMap[K, V]) Keys(ctx context.Context) ([]K, error)

Keys returns all field names in the hash

func (*HashMap[K, V]) Len

func (h *HashMap[K, V]) Len(ctx context.Context) (int64, error)

Len returns the number of fields in the hash

func (*HashMap[K, V]) Set

func (h *HashMap[K, V]) Set(ctx context.Context, field K, value V, expire time.Duration) error

Set sets a field in the hash

func (*HashMap[K, V]) SetMulti

func (h *HashMap[K, V]) SetMulti(ctx context.Context, fields map[K]V, expire time.Duration) error

SetMulti sets multiple fields in the hash

func (*HashMap[K, V]) Values

func (h *HashMap[K, V]) Values(ctx context.Context) ([]V, error)

Values returns all values in the hash

type ZQueue

type ZQueue[T any] struct {
	Key  string
	Cli  redis.UniversalClient
	Desc bool // true for descending order, false for ascending order
}

func NewZQueue

func NewZQueue[T any](cli redis.UniversalClient, key string, desc bool) *ZQueue[T]

func (*ZQueue[T]) Add

func (q *ZQueue[T]) Add(ctx context.Context, member T, score int64, expire time.Duration) error

Add adds an element to the sorted set with the given score

func (*ZQueue[T]) AddMulti

func (q *ZQueue[T]) AddMulti(ctx context.Context, elements []Element[T], expire time.Duration) error

AddMulti adds multiple elements to the sorted set

func (*ZQueue[T]) Count

func (q *ZQueue[T]) Count(ctx context.Context) (int64, error)

Count returns the number of elements in the sorted set

func (*ZQueue[T]) CountByScore

func (q *ZQueue[T]) CountByScore(ctx context.Context, min, max string) (int64, error)

CountByScore returns the number of elements with scores between min and max Use "-inf" for min or "+inf" for max to represent infinity

func (*ZQueue[T]) PopMax

func (q *ZQueue[T]) PopMax(ctx context.Context) (*Element[T], error)

PopMax removes and returns the element with the highest score

func (*ZQueue[T]) PopMaxMulti

func (q *ZQueue[T]) PopMaxMulti(ctx context.Context, count int64) ([]Element[T], error)

PopMaxMulti removes and returns multiple elements with the highest scores

func (*ZQueue[T]) PopMin

func (q *ZQueue[T]) PopMin(ctx context.Context) (*Element[T], error)

PopMin removes and returns the element with the lowest score

func (*ZQueue[T]) PopMinMulti

func (q *ZQueue[T]) PopMinMulti(ctx context.Context, count int64) ([]Element[T], error)

PopMinMulti removes and returns multiple elements with the lowest scores

func (*ZQueue[T]) RangeByScore

func (q *ZQueue[T]) RangeByScore(ctx context.Context, minScore, maxScore int64) ([]Element[T], error)

RangeByScore returns elements with scores between min and max Respects the Desc field in ZQueue

func (*ZQueue[T]) RangeByScoreRev

func (q *ZQueue[T]) RangeByScoreRev(ctx context.Context, minScore, maxScore int64) ([]Element[T], error)

RangeByScoreRev returns elements with scores between min and max in reversed order Reverses the Desc field in ZQueue

func (*ZQueue[T]) RangeByScoreWithLimit

func (q *ZQueue[T]) RangeByScoreWithLimit(ctx context.Context, minScore, maxScore int64, offset, count int64) ([]Element[T], error)

RangeByScoreWithLimit returns elements with scores between min and max with pagination Respects the Desc field in ZQueue

func (*ZQueue[T]) RangeByScoreWithLimitRev

func (q *ZQueue[T]) RangeByScoreWithLimitRev(ctx context.Context, minScore, maxScore int64, offset, count int64) ([]Element[T], error)

RangeByScoreWithLimitRev returns elements with scores between min and max with pagination in reversed order Reverses the Desc field in ZQueue

func (*ZQueue[T]) RangeFromScore

func (q *ZQueue[T]) RangeFromScore(ctx context.Context, minScore int64) ([]Element[T], error)

RangeFromScore returns elements with scores >= minScore Respects the Desc field in ZQueue

func (*ZQueue[T]) RangeFromScoreRev

func (q *ZQueue[T]) RangeFromScoreRev(ctx context.Context, minScore int64) ([]Element[T], error)

RangeFromScoreRev returns elements with scores >= minScore in reversed order Reverses the Desc field in ZQueue

func (*ZQueue[T]) RangeToScore

func (q *ZQueue[T]) RangeToScore(ctx context.Context, maxScore int64) ([]Element[T], error)

RangeToScore returns elements with scores <= maxScore Respects the Desc field in ZQueue

func (*ZQueue[T]) RangeToScoreRev

func (q *ZQueue[T]) RangeToScoreRev(ctx context.Context, maxScore int64) ([]Element[T], error)

RangeToScoreRev returns elements with scores <= maxScore in reversed order Reverses the Desc field in ZQueue

func (*ZQueue[T]) Remove

func (q *ZQueue[T]) Remove(ctx context.Context, member T) error

Remove removes an element from the sorted set

func (*ZQueue[T]) RemoveMulti

func (q *ZQueue[T]) RemoveMulti(ctx context.Context, members []T) error

RemoveMulti removes multiple elements from the sorted set

func (*ZQueue[T]) RemoveRangeByScore

func (q *ZQueue[T]) RemoveRangeByScore(ctx context.Context, min, max string) (int64, error)

RemoveRangeByScore removes elements with scores between min and max Use "-inf" for min or "+inf" for max to represent infinity

func (*ZQueue[T]) Score

func (q *ZQueue[T]) Score(ctx context.Context, member T) (int64, error)

Score returns the score of a member

Jump to

Keyboard shortcuts

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