rds

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-rds

A high-level Redis client library for Go that provides type-safe operations, batch processing, and enhanced Redis data structure support.

Features

  • Type-safe operations: Automatic encoding/decoding for various data types
  • Batch processing: Efficient batch operations with configurable batch sizes
  • Redis data structures: Comprehensive support for Strings, Hashes, Lists, Sets, and Sorted Sets
  • Distributed locking: Built-in Redis lock implementation
  • Stream support: Redis Stream operations for message queuing
  • Cache penetration protection: Mechanisms to prevent cache penetration
  • Connection management: Redis client with version detection and connection pooling

Installation

go get github.com/stephenfire/go-rds

Quick Start

Basic Usage
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/stephenfire/go-rds"
)

func main() {
	ctx := context.Background()
	
	// Connect to Redis
	client, err := rds.ConnectRedis(ctx, "redis://localhost:6379")
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	// Set a value
	err = client.Set(ctx, "mykey", "Hello, Redis!", 10*time.Minute)
	if err != nil {
		log.Fatal(err)
	}

	// Get a value
	value, exists, err := client.Get(ctx, "mykey", reflect.TypeOf(""))
	if err != nil {
		log.Fatal(err)
	}
	if exists {
		fmt.Println("Value:", value.(string))
	}
}
String Operations
// Create a string reader/writer
stringRW := rds.NewRedisString[string, string](
	client.C(),
	rds.RedisStringEncoder,
	rds.RedisStringDecoder,
	rds.RedisStringEncoder,
	rds.RedisStringDecoder,
)

// Set multiple values
err := stringRW.Sets(ctx, map[string]string{
	"key1": "value1",
	"key2": "value2",
	"key3": "value3",
})

// Get multiple values
notCached, cached, err := stringRW.Gets(ctx, "key1", "key2", "key3")
Hash Operations
// Create a hash reader/writer
hasher := rds.NewRedisHasher[string, int64](
	client.C(),
	rds.RedisStringEncoder, rds.RedisStringDecoder,
	rds.RedisInt64Encoder, rds.RedisInt64Decoder,
)

// Set hash values
err := hasher.HSetsMap(ctx, "user:scores", map[string]int64{
	"user1": 100,
	"user2": 200,
	"user3": 300,
})

// Get hash values
notCached, cached, err := hasher.HGets(ctx, "user:scores", "user1", "user2")
Sorted Set Operations
// Create a sorted set for ID scores
zset := rds.NewIdScoreZSet(client.C())

// Add scores to sorted set
scores := []*rds.IdScore{
	{Id: 1, Score: 100},
	{Id: 2, Score: 200},
	{Id: 3, Score: 300},
}

count, err := zset.ZAdd(ctx, "leaderboard", scores...)

// Query top 10 scores
args := &rds.ZArgs{}
args.WithKey("leaderboard").ByScore().Range(0, 1000).Paginate(0, 10).Rev()
topScores, err := zset.ZRangeWithScores(ctx, args)
Distributed Locking
// Create a Redis lock
locker := redislock.New(client.C())
redisLock := rds.NewRedisLock(client.C(), locker, "my-lock", "lock-value", 30*time.Second)

// Acquire lock
lockingValue, err := redisLock.Fetch(ctx)
if err != nil {
	log.Fatal("Failed to acquire lock")
}

// Do critical work
fmt.Println("Lock acquired, doing critical work...")

// Release lock
err = redisLock.Release()
if err != nil {
	log.Fatal("Failed to release lock")
}
Stream Operations
// Initialize stream group
err := client.InitStreamGroup(ctx, "mystream", "mygroup")

// Push messages to stream
messages := []map[string]interface{}{
	{"field1": "value1", "field2": 123},
	{"field1": "value2", "field2": 456},
}

err = client.QueuePushMaxLen(ctx, "mystream", 1000, messages...)

// Read messages from stream
msgs, err := client.QueueReadGroup(ctx, "mystream", "mygroup", "worker1", 5*time.Second, 10)

Configuration

Connection Options
// Custom connection with specific timeouts
opts, err := redis.ParseURL("redis://localhost:6379")
if err != nil {
	log.Fatal(err)
}
opts.ReadTimeout = 2 * time.Second
opts.WriteTimeout = 5 * time.Second

client := redis.NewClient(opts)
redisClient := &rds.RedisClient{Client: client}
Batch Size Configuration
// Configure batch sizes for different operations
const (
	ModelsBatchSize = 100  // For hash operations
	BatchSize       = 500  // For sorted set operations
)

Advanced Usage

Custom Type Encoding/Decoding
type User struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

// Custom encoder
func userEncoder(u User) (string, error) {
	return rds.RedisEncode(u)
}

// Custom decoder  
func userDecoder(s string) (User, error) {
	var u User
	err := rds.RedisDecode(reflect.TypeOf(u), s, &u)
	return u, err
}

// Use custom types
userHasher := rds.NewRedisHasher[int64, User](
	client.C(),
	rds.RedisInt64Encoder, rds.RedisInt64Decoder,
	userEncoder, userDecoder,
)
Cache Penetration Protection
// Using HGetsAndSetsIfNA to prevent cache penetration
flagField := int64(-1) // Special flag field
placeholderUser := User{ID: -1, Name: "", Email: ""}

users, err := userHasher.HGetsAndSetsIfNA(ctx, "users:cache", 
	func(ctx context.Context) (map[int64]User, error) {
		// Load all users from database
		return loadAllUsersFromDB(ctx)
	}, 
	flagField, 
	userID1, userID2, userID3,
)

Error Handling

// Check for Redis nil errors
value, exists, err := client.Get(ctx, "nonexistent", reflect.TypeOf(""))
if err != nil {
	if rds.IsRedisNil(err) {
		fmt.Println("Key does not exist")
	} else {
		log.Fatal(err)
	}
}

Performance Considerations

  • Use appropriate batch sizes for your workload
  • Consider using pipeline for multiple operations
  • Monitor memory usage for large datasets
  • Use connection pooling for high-throughput applications

License

Apache License 2.0 - See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For support and questions, please open an issue on GitHub.

Documentation

Index

Constants

View Source
const (
	ModelsBatchSize = 100
	BatchSize       = 500

	TypeKeyNone   = "none"
	TypeKeyStream = "stream"

	RdbStatusOK         = "OK"
	ErrBUSYGROUPKeyword = "BUSYGROUP"

	// DefaultStartScore zset default score range
	DefaultStartScore = "0"
	DefaultStopScore  = "+inf"

	StringPlaceHolder = "_"
	IdPlaceHolder     = 0
	NegIdPlaceHolder  = -1

	// HashExpireMinVersion min version of redis-server starting support HExpire
	HashExpireMinVersion = common.Version(7004000)
)
View Source
const (
	RedisTimeout      = 10 * time.Second
	RedisReadTimeout  = 2 * time.Second
	RedisWriteTimeout = 5 * time.Second
)

Variables

View Source
var (
	ErrInvalidValue    = errors.New("rds: invalid value object")
	ErrExpectingString = errors.New("rds: expecting string")
)
View Source
var EmptyZ = redis.Z{Score: -1, Member: "0"}

Functions

func Float64ToInt64

func Float64ToInt64(f float64) (int64, error)

func IdScoreToZ

func IdScoreToZ(is *IdScore) (redis.Z, bool, error)

IdScoreToZ is the RedisZEncoder for *IdScore: Id becomes the member, Score the score.

func Int64ToFloat64

func Int64ToFloat64(i int64) (float64, error)

func IsDefaultZero added in v0.1.3

func IsDefaultZero[T any](t T) bool

IsDefaultZero 判断泛型值 t 是否为其类型的默认零值(如 int 的 0、string 的 ""、指针的 nil)。

func IsRedisNil

func IsRedisNil(err error) bool

func IsRedisNoGroup

func IsRedisNoGroup(err error) bool

func MapKV

func MapKV[K comparable, V any, T KeyValuer[K, V]](values []T) map[K]V

func NewTimeZ

func NewTimeZ(id int64, ts time.Time) redis.Z

func NewZ

func NewZ(member string, score int64) redis.Z

func RedisDecode

func RedisDecode(typ reflect.Type, strVal string) (any, error)

func RedisEncode

func RedisEncode(value any) (string, error)

func RedisInt64Decoder

func RedisInt64Decoder(s string) (int64, error)

func RedisInt64Encoder

func RedisInt64Encoder(s int64) (string, error)

func RedisInt64SliceDecoder

func RedisInt64SliceDecoder(s string) ([]int64, error)

func RedisInt64SliceEncoder

func RedisInt64SliceEncoder(s []int64) (string, error)

func RedisStringDecoder

func RedisStringDecoder(s string) (string, error)

func RedisStringEncoder

func RedisStringEncoder(s string) (string, error)

func RedisStringSliceDecoder

func RedisStringSliceDecoder(s string) ([]string, error)

func RedisStringSliceEncoder

func RedisStringSliceEncoder(s []string) (string, error)

func RedisUint64Decoder

func RedisUint64Decoder(s string) (uint64, error)

func RedisUint64Encoder

func RedisUint64Encoder(s uint64) (string, error)

func RedisValueDecode

func RedisValueDecode[T any](val any, decoder func(string) (T, error)) (exist bool, t T, err error)

func TypeDecoder

func TypeDecoder[T any](typ reflect.Type, strVal string) (t T, err error)

func TypeEncoder

func TypeEncoder[T any](value T) (string, error)

Types

type BatchIterator

type BatchIterator[T any] struct {
	// contains filtered or unexported fields
}

func NewBatchIterator

func NewBatchIterator[T any](ts []T, size ...int) *BatchIterator[T]

func (*BatchIterator[T]) Current

func (b *BatchIterator[T]) Current() []T

func (*BatchIterator[T]) HasNext

func (b *BatchIterator[T]) HasNext() bool

func (*BatchIterator[T]) Next

func (b *BatchIterator[T]) Next() []T

func (*BatchIterator[T]) String

func (b *BatchIterator[T]) String() string

type Decoder added in v0.2.0

type Decoder[T any, R any] func(r R) (T, error)

func (Decoder[T, R]) Decode added in v0.2.0

func (d Decoder[T, R]) Decode(r R, rdsErr error) (t T, e error)

func (Decoder[T, R]) Decodes added in v0.2.0

func (d Decoder[T, R]) Decodes(rs []R, rdsErr error) ([]T, error)

type Encoder added in v0.2.0

type Encoder[T any, R any] func(t T) (R, error)

func (Encoder[T, R]) Encodes added in v0.2.0

func (e Encoder[T, R]) Encodes(ts ...T) ([]R, error)

func (Encoder[T, R]) EncodesAsAny added in v0.2.0

func (e Encoder[T, R]) EncodesAsAny(ts ...T) ([]any, error)

func (Encoder[T, R]) EncodesTo added in v0.2.0

func (e Encoder[T, R]) EncodesTo(dest []R, ts ...T) error

func (Encoder[T, R]) EncodesToAsAny added in v0.2.0

func (e Encoder[T, R]) EncodesToAsAny(dest []any, ts ...T) error

type IdScore

type IdScore struct {
	Id    int64
	Score int64
}

IdScore represents a zset element: an int64 member ID paired with an int64 score.

func ZToIdScore

func ZToIdScore(z redis.Z) (*IdScore, error)

ZToIdScore is the RedisZDecoder for *IdScore: parses the member back into the ID.

func (*IdScore) ScoreTime

func (i *IdScore) ScoreTime() tools.Time

ScoreTime interprets the score as a Unix timestamp.

type IsNil

type IsNil[T any] func(T) bool

IsNil 判断泛型值是否为空/零值的函数类型。

type KeyValuer

type KeyValuer[K comparable, V any] interface {
	Key() K
	Value() V
}

func ConvertKV

func ConvertKV[K comparable, V any, T KeyValuer[K, V]](values []T) []KeyValuer[K, V]

type KeyValuers added in v0.2.0

type KeyValuers[K comparable, V any] []KeyValuer[K, V]

func (KeyValuers[K, V]) All added in v0.2.0

func (vs KeyValuers[K, V]) All() iter.Seq2[K, V]

type MS added in v0.2.0

type MS[M comparable, S any] struct {
	M M
	S S
}

MS is an ordered member-score pair returned by ZRangeArgsWithScores. It implements KeyValuer, so it can be converted with ConvertKV to reuse the KeyValuers iterators.

func (MS[M, S]) Key added in v0.2.0

func (ms MS[M, S]) Key() M

Key returns the member (KeyValuer implementation).

func (MS[M, S]) Value added in v0.2.0

func (ms MS[M, S]) Value() S

Value returns the score (KeyValuer implementation).

type MapLoader

type MapLoader[K comparable, V any] func(ctx context.Context, ks ...K) (map[K]V, error)

MapLoader 是一个从 Redis 加载数据的回调函数类型。 接收一组 key,返回 key-value 映射,用于批量回源加载缺失数据。

type RedisAtomicPointer

type RedisAtomicPointer[T any] struct {
	// contains filtered or unexported fields
}

func NewAtomicPointer

func NewAtomicPointer[T any](newT func(client *RedisClient, batchSize ...int) *T) *RedisAtomicPointer[T]

func (*RedisAtomicPointer[T]) Get

func (a *RedisAtomicPointer[T]) Get(client *RedisClient, batchSize ...int) *T

type RedisBatchValue

type RedisBatchValue[V any] struct {
	// contains filtered or unexported fields
}

RedisBatchValue 批量操作的泛型辅助结构体,封装了编码/解码器和批次大小, 用于将大量数据拆分为小批次进行 Redis 操作,避免单次操作数据量过大。

type RedisClient

type RedisClient struct {
	*redis.Client
	// contains filtered or unexported fields
}

func ConnectRedis

func ConnectRedis(ctx context.Context, url string) (*RedisClient, error)

func (*RedisClient) C

func (c *RedisClient) C() *redis.Client

func (*RedisClient) Del

func (c *RedisClient) Del(ctx context.Context, keys ...string) error

func (*RedisClient) Exist

func (c *RedisClient) Exist(ctx context.Context, key string) bool

func (*RedisClient) Get

func (c *RedisClient) Get(ctx context.Context, key string, typ reflect.Type) (any, bool, error)

func (*RedisClient) GetIds

func (c *RedisClient) GetIds(ctx context.Context, key string) ([]int64, bool, error)

func (*RedisClient) GetStringWithNil

func (c *RedisClient) GetStringWithNil(ctx context.Context, key string) (string, error)

func (*RedisClient) GetValues

func (c *RedisClient) GetValues(ctx context.Context, typ reflect.Type,
	keys ...string) (hitList []bool, values any, errr error)

GetValues returns hitList: same length as the input keys, indicates whether each key hit the cache values: array of decoded values or nil (not hit or cached nil)

func (*RedisClient) HDel

func (c *RedisClient) HDel(ctx context.Context, key string, fields ...string) error

func (*RedisClient) HDels

func (c *RedisClient) HDels(ctx context.Context, key string, fields ...string) error

func (*RedisClient) HGet

func (c *RedisClient) HGet(ctx context.Context, key, field string, typ reflect.Type) (any, bool, error)

func (*RedisClient) HGets

func (c *RedisClient) HGets(ctx context.Context, key string, typ reflect.Type,
	fields ...string) (hitList []bool, cached any, err error)

HGets returns cached as map[string]anyOftyp

func (*RedisClient) HGetsAll

func (c *RedisClient) HGetsAll(ctx context.Context, key string, typ reflect.Type) (any, error)

HGetsAll returns map[string]anyOftyp

func (*RedisClient) HSet

func (c *RedisClient) HSet(ctx context.Context, key, field string, value any) error

func (*RedisClient) HSetMap

func (c *RedisClient) HSetMap(ctx context.Context, key string, m map[string]any) error

func (*RedisClient) HSets

func (c *RedisClient) HSets(ctx context.Context, key string, fieldValues ...any) error

func (*RedisClient) HSetsOnce

func (c *RedisClient) HSetsOnce(ctx context.Context, key string, fieldValues ...any) error

func (*RedisClient) InitStreamGroup

func (c *RedisClient) InitStreamGroup(ctx context.Context, streamName string, groupName string) error

InitStreamGroup workers should call this at start procedure

func (*RedisClient) QueueAck

func (c *RedisClient) QueueAck(ctx context.Context, stream, group string, ids ...string) error

func (*RedisClient) QueuePush

func (c *RedisClient) QueuePush(ctx context.Context, stream string, minId string, values ...map[string]interface{}) error

func (*RedisClient) QueuePushMaxLen

func (c *RedisClient) QueuePushMaxLen(ctx context.Context, stream string, maxLen int64, values ...map[string]any) error

func (*RedisClient) QueueRead

func (c *RedisClient) QueueRead(ctx context.Context, stream string, timeout time.Duration,
	count int64, startId ...string) ([]redis.XMessage, error)

func (*RedisClient) QueueReadGroup

func (c *RedisClient) QueueReadGroup(ctx context.Context, stream, group, worker string,
	timeout time.Duration, count int64) ([]redis.XMessage, error)

func (*RedisClient) ResetZSet

func (c *RedisClient) ResetZSet(ctx context.Context, key string, zs ...redis.Z) error

func (*RedisClient) Set

func (c *RedisClient) Set(ctx context.Context, key string, value any, expire ...time.Duration) error

func (*RedisClient) SetValues

func (c *RedisClient) SetValues(ctx context.Context, pairs ...any) error

func (*RedisClient) SetZSet

func (c *RedisClient) SetZSet(ctx context.Context, key string, zs ...redis.Z) error

func (*RedisClient) String

func (c *RedisClient) String() string

func (*RedisClient) Version

func (c *RedisClient) Version() common.Version

func (*RedisClient) ZScoreByPaddedIds

func (c *RedisClient) ZScoreByPaddedIds(ctx context.Context, key string, paddedIds ...string) (map[int64]int64, error)

type RedisDecoder

type RedisDecoder[T any] func(r string) (T, error)

func NewTypeDecoder

func NewTypeDecoder[T any](typ reflect.Type) RedisDecoder[T]

func (RedisDecoder[T]) Decode added in v0.2.0

func (d RedisDecoder[T]) Decode(str string, rdsErr error) (t T, e error)

func (RedisDecoder[T]) Decodes added in v0.2.0

func (d RedisDecoder[T]) Decodes(strs []string, rdsErr error) ([]T, error)

type RedisEncoder

type RedisEncoder[T any] func(t T) (string, error)

RedisEncoder returns "" means ignoring

func (RedisEncoder[T]) Encodes added in v0.2.0

func (e RedisEncoder[T]) Encodes(ts ...T) ([]string, error)

func (RedisEncoder[T]) EncodesTo added in v0.2.0

func (e RedisEncoder[T]) EncodesTo(dest []string, ts ...T) error

type RedisFloatDecoder

type RedisFloatDecoder[S any] func(f float64) (S, error)

RedisFloatDecoder decoder for ZSet score

type RedisFloatEncoder

type RedisFloatEncoder[S any] func(v S) (float64, error)

RedisFloatEncoder encoder for ZSet score

type RedisHasher

type RedisHasher[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewHashReader

func NewHashReader[K comparable, V any](client redis.Cmdable, fieldEncoder RedisEncoder[K],
	fieldDecoder RedisDecoder[K], valueDecoder RedisDecoder[V]) *RedisHasher[K, V]

func NewRedisHasher

func NewRedisHasher[K comparable, V any](
	client redis.Cmdable,
	fieldEncoder RedisEncoder[K], fieldDecoder RedisDecoder[K],
	valueEncoder RedisEncoder[V], valueDecoder RedisDecoder[V]) *RedisHasher[K, V]

func NewStringInt64Hasher

func NewStringInt64Hasher(c redis.Cmdable) *RedisHasher[string, int64]

func (*RedisHasher[K, V]) FieldDecoder

func (t *RedisHasher[K, V]) FieldDecoder(decoder RedisDecoder[K]) *RedisHasher[K, V]

func (*RedisHasher[K, V]) FieldEncoder

func (t *RedisHasher[K, V]) FieldEncoder(encoder RedisEncoder[K]) *RedisHasher[K, V]

func (*RedisHasher[K, V]) HDel

func (t *RedisHasher[K, V]) HDel(ctx context.Context, key string, fields ...K) (int64, error)

func (*RedisHasher[K, V]) HDelFieldString

func (t *RedisHasher[K, V]) HDelFieldString(ctx context.Context, key string, fieldStrings ...string) (int64, error)

func (*RedisHasher[K, V]) HExists

func (t *RedisHasher[K, V]) HExists(ctx context.Context, key string, field K) (bool, error)

func (*RedisHasher[K, V]) HExpire

func (t *RedisHasher[K, V]) HExpire(ctx context.Context, key string, seconds int64, fields ...K) ([]bool, error)

func (*RedisHasher[K, V]) HGet

func (t *RedisHasher[K, V]) HGet(ctx context.Context, key string, field K) (hit bool, value V, err error)

func (*RedisHasher[K, V]) HGetAll

func (t *RedisHasher[K, V]) HGetAll(ctx context.Context, key string) (map[K]V, error)

func (*RedisHasher[K, V]) HGetAllAndSetIfNA

func (t *RedisHasher[K, V]) HGetAllAndSetIfNA(ctx context.Context, key string,
	allLoader func(ctx context.Context) (map[K]V, error), flagField K) (map[K]V, error)

func (*RedisHasher[K, V]) HGetAndSet

func (t *RedisHasher[K, V]) HGetAndSet(ctx context.Context, key string,
	dbLoader func(cctx context.Context, kks ...K) (map[K]V, error), k K) (v V, err error)

func (*RedisHasher[K, V]) HGetAndSetIfNA

func (t *RedisHasher[K, V]) HGetAndSetIfNA(ctx context.Context, key string,
	allLoader func(ctx context.Context) (map[K]V, error), flagField K, k K) (v V, err error)

func (*RedisHasher[K, V]) HGetByFieldString

func (t *RedisHasher[K, V]) HGetByFieldString(ctx context.Context, key string, fieldString string) (hit bool, value V, err error)

func (*RedisHasher[K, V]) HGetByFieldStrings

func (t *RedisHasher[K, V]) HGetByFieldStrings(ctx context.Context, key string, fieldStrings ...string) (hitList []bool, cached map[K]V, err error)

func (*RedisHasher[K, V]) HGets

func (t *RedisHasher[K, V]) HGets(ctx context.Context, key string, fields ...K) (notcached []K, cached map[K]V, err error)

func (*RedisHasher[K, V]) HGetsAndSets

func (t *RedisHasher[K, V]) HGetsAndSets(ctx context.Context, key string,
	dbLoader func(cctx context.Context, kks ...K) (map[K]V, error), ks ...K) (map[K]V, error)

HGetsAndSets read data from hashes:key using ks as the fields. If any fields do not exist, use dbLoader to read the corresponding data from the database and store it in the cache. Note that dbLoader should not return an error if the corresponding data does not exist in the database.

func (*RedisHasher[K, V]) HGetsAndSetsIfNA

func (t *RedisHasher[K, V]) HGetsAndSetsIfNA(ctx context.Context, key string,
	allLoader func(ctx context.Context) (map[K]V, error), flagField K, kks ...K) (map[K]V, error)

HGetsAndSetsIfNA 检查key是否存在,如果不存在则通过allLoader获取所有key的数据并保存 redis的hash无法存储0个field,所以当使用hash存储对象时,如果不做特殊处理,将无法缓存不存在的key(如:数据库中不存在)。 此时通过使用在field中增加一个特殊值flag(不会与真实filed重复),用来保证没有其他field时也可以使得key在redis中。 而flag对应的值则是V的缺省值。 读取时,可以通过HMGet每次都将flag读取出来,一旦flag不存在,就说明key不存在。如果flag存在,而可以说明被读取的field是否真实存在。

func (*RedisHasher[K, V]) HIncrBy added in v0.2.0

func (t *RedisHasher[K, V]) HIncrBy(ctx context.Context, key string, k K, delta int64) (int64, error)

func (*RedisHasher[K, V]) HIncrByFloat added in v0.2.0

func (t *RedisHasher[K, V]) HIncrByFloat(ctx context.Context, key string, k K, delta float64) (float64, error)

func (*RedisHasher[K, V]) HKeys

func (t *RedisHasher[K, V]) HKeys(ctx context.Context, key string) ([]K, error)

func (*RedisHasher[K, V]) HKeysAndSetIfNA

func (t *RedisHasher[K, V]) HKeysAndSetIfNA(ctx context.Context, key string,
	allLoader func(ctx context.Context) (map[K]V, error), flagField K) (fields []K, err error)

func (*RedisHasher[K, V]) HMustSets

func (t *RedisHasher[K, V]) HMustSets(ctx context.Context, key string, values []KeyValuer[K, V],
	mustFields []K, placeholderVal V) error

func (*RedisHasher[K, V]) HMustSetsMap

func (t *RedisHasher[K, V]) HMustSetsMap(ctx context.Context, key string, valueMap map[K]V,
	mustFields []K, placeholderVal V) error

func (*RedisHasher[K, V]) HSet

func (t *RedisHasher[K, V]) HSet(ctx context.Context, key string, field K, value V) error

func (*RedisHasher[K, V]) HSets

func (t *RedisHasher[K, V]) HSets(ctx context.Context, key string, values []KeyValuer[K, V]) error

func (*RedisHasher[K, V]) HSetsIter added in v0.2.0

func (t *RedisHasher[K, V]) HSetsIter(ctx context.Context, key string, values iter.Seq2[K, V]) error

func (*RedisHasher[K, V]) HSetsMap

func (t *RedisHasher[K, V]) HSetsMap(ctx context.Context, key string, valueMap map[K]V) error

func (*RedisHasher[K, V]) LoadAndSetAll added in v0.2.0

func (t *RedisHasher[K, V]) LoadAndSetAll(ctx context.Context, key string,
	allLoader func(ctx context.Context) (map[K]V, error), flagField K) (all map[K]V, err error)

func (*RedisHasher[K, V]) ValueDecoder

func (t *RedisHasher[K, V]) ValueDecoder(decoder RedisDecoder[V]) *RedisHasher[K, V]

func (*RedisHasher[K, V]) ValueEncoder

func (t *RedisHasher[K, V]) ValueEncoder(encoder RedisEncoder[V]) *RedisHasher[K, V]

type RedisKey

type RedisKey[K any] struct {
	// contains filtered or unexported fields
}

func (*RedisKey[K]) Dels

func (rk *RedisKey[K]) Dels(ctx context.Context, ks ...K) error

func (*RedisKey[K]) Exist

func (rk *RedisKey[K]) Exist(ctx context.Context, k K) bool

func (*RedisKey[K]) Key

func (rk *RedisKey[K]) Key(k K) (key string, err error)

func (*RedisKey[K]) Keys

func (rk *RedisKey[K]) Keys(ks ...K) (keys []string, err error)

type RedisList

type RedisList[V any] struct {
	RedisBatchValue[V]
	// contains filtered or unexported fields
}

RedisList 是 Redis List 数据结构的泛型封装,支持批量操作。 通过组合 RedisBatchValue 实现自动分批编码/解码。

func NewRedisList added in v0.2.0

func NewRedisList[V any](client redis.Cmdable, encoder RedisEncoder[V], decoder RedisDecoder[V]) *RedisList[V]

func (*RedisList[V]) LLen added in v0.2.0

func (l *RedisList[V]) LLen(ctx context.Context, key string) (int64, error)

func (*RedisList[V]) LPop added in v0.2.0

func (l *RedisList[V]) LPop(ctx context.Context, key string) (V, error)

func (*RedisList[V]) LPopCount added in v0.2.0

func (l *RedisList[V]) LPopCount(ctx context.Context, key string, count int) ([]V, error)

func (*RedisList[V]) LPush added in v0.2.0

func (l *RedisList[V]) LPush(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisList[V]) LPushInPipe added in v0.2.0

func (l *RedisList[V]) LPushInPipe(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisList[V]) LPushX added in v0.2.0

func (l *RedisList[V]) LPushX(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisList[V]) LRange

func (l *RedisList[V]) LRange(ctx context.Context, key string, start, stop int64) ([]V, error)

LRange 获取 Redis List 中指定范围内的元素并解码为泛型类型。 start 和 stop 为索引,支持负数索引(如 -1 表示最后一个元素)。

func (*RedisList[V]) LRem added in v0.2.0

func (l *RedisList[V]) LRem(ctx context.Context, key string, count int64, v V) (int64, error)

func (*RedisList[V]) RPop added in v0.2.0

func (l *RedisList[V]) RPop(ctx context.Context, key string) (V, error)

func (*RedisList[V]) RPopCount added in v0.2.0

func (l *RedisList[V]) RPopCount(ctx context.Context, key string, count int) ([]V, error)

func (*RedisList[V]) RPush

func (l *RedisList[V]) RPush(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisList[V]) RPushInPipe added in v0.2.0

func (l *RedisList[V]) RPushInPipe(ctx context.Context, key string, vs ...V) (int64, error)

RPushInPipe 将数据从右侧推入 Redis List。支持批量推入,自动按批次大小拆分。 返回操作后列表的长度。

func (*RedisList[V]) RPushX added in v0.2.0

func (l *RedisList[V]) RPushX(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisList[V]) WithBatchSize

func (l *RedisList[V]) WithBatchSize(size int) *RedisList[V]

WithBatchSize 设置批量操作时的批次大小,返回自身以支持链式调用。

type RedisLock

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

func NewRedisLock

func NewRedisLock(client *redis.Client, locker *redislock.Client, key, value string, ttl time.Duration) *RedisLock

func (*RedisLock) Fetch

func (l *RedisLock) Fetch(cctx context.Context) (lockingValue string, err error)

func (*RedisLock) FetchOrRefresh

func (l *RedisLock) FetchOrRefresh(cctx context.Context) (lockingValue string, err error)

func (*RedisLock) Refresh

func (l *RedisLock) Refresh(cctx context.Context) (err error)

func (*RedisLock) Release

func (l *RedisLock) Release() (err error)

func (*RedisLock) String

func (l *RedisLock) String() string

type RedisMSZSet

type RedisMSZSet[M comparable, S any] struct {
	// contains filtered or unexported fields
}

RedisMSZSet is a generic Redis sorted-set wrapper that keeps members (M) and scores (S) as separate first-class types: scores can be read and updated independently via ZScore/ZMScore/ZIncrBy. Use NewIDZSet for the common int64/int64 case, or NewMSZSet with custom codecs.

func NewIDZSet

func NewIDZSet(client redis.Cmdable) *RedisMSZSet[int64, int64]

NewIDZSet creates a RedisMSZSet[int64, int64]: both members and scores are int64.

func NewMSZSet

func NewMSZSet[M comparable, S any](client redis.Cmdable, memberEncoder RedisEncoder[M], memberDecoder RedisDecoder[M],
	scoreEncoder RedisFloatEncoder[S], scoreDecoder RedisFloatDecoder[S], batchSize ...int) *RedisMSZSet[M, S]

NewMSZSet creates a RedisMSZSet with custom member/score codecs. batchSize optionally overrides the write batch size.

func (*RedisMSZSet[M, S]) WithBatchSize added in v0.1.1

func (ms *RedisMSZSet[M, S]) WithBatchSize(batchSize int) *RedisMSZSet[M, S]

WithBatchSize sets the write batch size.

func (*RedisMSZSet[M, S]) ZAdd added in v0.1.1

func (ms *RedisMSZSet[M, S]) ZAdd(ctx context.Context, key string, msmap map[M]S) (int64, error)

ZAdd upserts the members with their scores (existing members get their score updated) and returns the number of new members.

func (*RedisMSZSet[M, S]) ZCount

func (ms *RedisMSZSet[M, S]) ZCount(ctx context.Context, key string, min, max string) (count int64, err error)

ZCount counts the members with scores in [min, max]. Bounds are inclusive by default; prefix a bound with "(" to exclude it.

func (*RedisMSZSet[M, S]) ZIncrBy

func (ms *RedisMSZSet[M, S]) ZIncrBy(ctx context.Context, key string, incrBy float64, m M) (s S, err error)

ZIncrBy increments the score of member m by incrBy and returns the new score.

func (*RedisMSZSet[M, S]) ZMScore

func (ms *RedisMSZSet[M, S]) ZMScore(ctx context.Context, key string, inputs ...M) (map[M]S, error)

ZMScore returns the scores of the given members (deduplicated) as a map. Members whose scores fail to decode are skipped.

func (*RedisMSZSet[M, S]) ZRangeArgs

func (ms *RedisMSZSet[M, S]) ZRangeArgs(ctx context.Context, args *ZArgs, placeHolder ...M) ([]M, error)

ZRangeArgs returns the members in the range without scores. placeHolder optionally filters placeholder members from the result.

func (*RedisMSZSet[M, S]) ZRangeArgsWithScores added in v0.2.0

func (ms *RedisMSZSet[M, S]) ZRangeArgsWithScores(ctx context.Context, args *ZArgs, placeHolder ...M) ([]MS[M, S], error)

ZRangeArgsWithScores returns the ordered member-score pairs (MS[M, S]) in the range. placeHolder filters placeholder members like in ZRangeArgs. Note: Redis does not support WITHSCORES combined with BYLEX; use ZRangeArgs for lex ranges.

func (*RedisMSZSet[M, S]) ZScore

func (ms *RedisMSZSet[M, S]) ZScore(ctx context.Context, key string, m M) (s S, err error)

ZScore returns the score of member m; redis.Nil when the member is missing.

type RedisMsg

type RedisMsg map[string]interface{}

func (RedisMsg) ID

func (m RedisMsg) ID(key string, nilIsOk ...bool) (tools.ID, error)

func (RedisMsg) Int64

func (m RedisMsg) Int64(key string, nilIsOk ...bool) (i int64, err error)

func (RedisMsg) IsEmpty

func (m RedisMsg) IsEmpty() bool

func (RedisMsg) IsStopSignal

func (m RedisMsg) IsStopSignal() bool

func (RedisMsg) Map

func (m RedisMsg) Map() map[string]interface{}

func (RedisMsg) StopSignal

func (m RedisMsg) StopSignal() RedisMsg

func (RedisMsg) String

func (m RedisMsg) String(key string, nilIsOk ...bool) (string, error)

type RedisSet

type RedisSet[V any] struct {
	RedisBatchValue[V]
	// contains filtered or unexported fields
}

func NewRedisSet

func NewRedisSet[V any](client redis.Cmdable, encoder RedisEncoder[V], decoder RedisDecoder[V]) *RedisSet[V]

func (*RedisSet[V]) SAdd

func (s *RedisSet[V]) SAdd(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisSet[V]) SAddInBatch added in v0.2.0

func (s *RedisSet[V]) SAddInBatch(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisSet[V]) SAddWithEmpty

func (s *RedisSet[V]) SAddWithEmpty(ctx context.Context, key string, emptyValue V, vs ...V) (int64, error)

func (*RedisSet[V]) SAddWithEmptyInBatch added in v0.2.0

func (s *RedisSet[V]) SAddWithEmptyInBatch(ctx context.Context, key string, emptyValue V, vs ...V) (int64, error)

func (*RedisSet[V]) SIsMember

func (s *RedisSet[V]) SIsMember(ctx context.Context, key string, v V) (bool, error)

func (*RedisSet[V]) SRem

func (s *RedisSet[V]) SRem(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisSet[V]) SRemInBatch added in v0.2.0

func (s *RedisSet[V]) SRemInBatch(ctx context.Context, key string, vs ...V) (int64, error)

func (*RedisSet[V]) WithBatchSize

func (s *RedisSet[V]) WithBatchSize(size int) *RedisSet[V]

type RedisString

type RedisString[K comparable, V any] struct {
	RedisKey[K]
	// contains filtered or unexported fields
}

func NewRedisString

func NewRedisString[K comparable, V any](client redis.Cmdable, keyEncoder RedisEncoder[K],
	valueEncoder RedisEncoder[V], valueDecoder RedisDecoder[V]) *RedisString[K, V]

func NewStringReader

func NewStringReader[K comparable, V any](client redis.Cmdable, keyEncoder RedisEncoder[K],
	valueDecoder RedisDecoder[V]) *RedisString[K, V]

func NewStringWriter

func NewStringWriter[K comparable, V any](client redis.Cmdable, keyEncoder RedisEncoder[K],
	valueEncoder RedisEncoder[V]) *RedisString[K, V]

func (*RedisString[K, V]) Client

func (s *RedisString[K, V]) Client(client redis.Cmdable) *RedisString[K, V]

func (*RedisString[K, V]) Get

func (s *RedisString[K, V]) Get(ctx context.Context, k K) (exist bool, t V, err error)

func (*RedisString[K, V]) GetAndSet

func (s *RedisString[K, V]) GetAndSet(ctx context.Context,
	dbLoader func(cctx context.Context, kks ...K) (map[K]V, error), k K) (v V, err error)

func (*RedisString[K, V]) Gets

func (s *RedisString[K, V]) Gets(ctx context.Context, ks ...K) (notcached []K, cached map[K]V, err error)

func (*RedisString[K, V]) GetsAndSets

func (s *RedisString[K, V]) GetsAndSets(ctx context.Context,
	dbLoader MapLoader[K, V], ks ...K) (map[K]V, error)

func (*RedisString[K, V]) KeyEncoder

func (s *RedisString[K, V]) KeyEncoder(encoder RedisEncoder[K]) *RedisString[K, V]

func (*RedisString[K, V]) Set

func (s *RedisString[K, V]) Set(ctx context.Context, k K, v V, expire ...time.Duration) error

func (*RedisString[K, V]) Sets

func (s *RedisString[K, V]) Sets(ctx context.Context, values map[K]V) error

func (*RedisString[K, V]) ValueDecoder

func (s *RedisString[K, V]) ValueDecoder(decoder RedisDecoder[V]) *RedisString[K, V]

func (*RedisString[K, V]) ValueEncoder

func (s *RedisString[K, V]) ValueEncoder(encoder RedisEncoder[V]) *RedisString[K, V]

type RedisTree added in v0.1.3

type RedisTree[K1 comparable, K2 comparable, V any] struct {
	// contains filtered or unexported fields
}

RedisTree 是 Redis 二级树形数据结构的泛型封装。 第一级 key(K1)映射到第二级 key 列表([]K2),第二级 key(K2)映射到实际数据(V)。 适用于父子关系数据的缓存场景,如分类-商品、用户-订单等。

func NewRedisTree added in v0.1.3

func NewRedisTree[K1 comparable, K2 comparable, V any](
	parentRS *RedisString[K1, []K2], parentLoader MapLoader[K1, []K2],
	childRS *RedisString[K2, V], childLoader MapLoader[K2, V],
	isChildNil ...IsNil[V]) *RedisTree[K1, K2, V]

NewRedisTree 创建一个新的 RedisTree 实例。 isChildNil 为可选参数,用于自定义判断子级值是否为空的逻辑; 如果不提供,则默认使用 IsDefaultZero 判断。

func (*RedisTree[K1, K2, V]) Children added in v0.1.3

func (t *RedisTree[K1, K2, V]) Children(ctx context.Context, ks ...K1) (map[K1][]V, error)

Children 根据父级 key 列表获取对应的子级数据。 先通过 parent 缓存获取每个 K1 对应的 K2 列表,再通过 child 缓存获取每个 K2 对应的实际数据 V, 最终返回 map[K1][]V 的映射结果。空值子数据会被自动过滤。

type RedisZDecoder

type RedisZDecoder[Z any] func(z redis.Z) (v Z, err error)

type RedisZEncoder

type RedisZEncoder[Z any] func(v Z) (z redis.Z, ok bool, err error)

RedisZEncoder returns ok==false means ignoring the value

type RedisZSet

type RedisZSet[Z any] struct {
	// contains filtered or unexported fields
}

RedisZSet is a generic Redis sorted-set wrapper for values of type Z, where Z carries both the member and the score. Use NewIdScoreZSet for the common {Id, Score} case, or NewRedisZSet with custom codecs.

func NewIdScoreZSet

func NewIdScoreZSet(client redis.Cmdable, batchSize ...int) *RedisZSet[*IdScore]

NewIdScoreZSet creates a RedisZSet[*IdScore] with the built-in codecs.

func NewRedisZSet

func NewRedisZSet[Z any](client redis.Cmdable, encoder RedisZEncoder[Z],
	decoder RedisZDecoder[Z], batchSize ...int) *RedisZSet[Z]

NewRedisZSet creates a RedisZSet[Z] with custom encode/decode functions. encoder returns ok=false to skip a value. batchSize optionally overrides the write batch size.

func (*RedisZSet[Z]) BZPopMin

func (zs *RedisZSet[Z]) BZPopMin(ctx context.Context, timeout time.Duration, key string) ([]Z, error)

BZPopMin blocks up to timeout for the member with the lowest score. The redis.Nil timeout error is converted to a nil slice, so nil means "no result".

func (*RedisZSet[Z]) WithBatchSize

func (zs *RedisZSet[Z]) WithBatchSize(size int) *RedisZSet[Z]

WithBatchSize sets the write batch size; values are sent in batches to avoid oversized commands.

func (*RedisZSet[Z]) ZAdd

func (zs *RedisZSet[Z]) ZAdd(ctx context.Context, key string, vs ...Z) (int64, error)

ZAdd upserts values (existing members get their score updated) and returns the number of new members.

func (*RedisZSet[Z]) ZAddCall

func (zs *RedisZSet[Z]) ZAddCall(op func(client redis.Cmdable, vals ...redis.Z) (int64, error), vs ...Z) (int64, error)

ZAddCall runs a custom add op (e.g. ZAddNX) in batches over the encoded values.

func (*RedisZSet[Z]) ZAddNX

func (zs *RedisZSet[Z]) ZAddNX(ctx context.Context, key string, vs ...Z) (int64, error)

ZAddNX adds values only for members not already present and returns the number of new members.

func (*RedisZSet[Z]) ZAddNXWithEmpty

func (zs *RedisZSet[Z]) ZAddNXWithEmpty(ctx context.Context, key string, emptyValue Z, vs ...Z) (int64, error)

ZAddNXWithEmpty behaves like ZAddNX but writes emptyValue when vs is empty.

func (*RedisZSet[Z]) ZAddWithEmpty

func (zs *RedisZSet[Z]) ZAddWithEmpty(ctx context.Context, key string, emptyValue Z, vs ...Z) (int64, error)

ZAddWithEmpty behaves like ZAdd but writes emptyValue when vs is empty.

func (*RedisZSet[Z]) ZCard

func (zs *RedisZSet[Z]) ZCard(ctx context.Context, key string) (int64, error)

ZCard returns the number of members in the zset.

func (*RedisZSet[Z]) ZCount

func (zs *RedisZSet[Z]) ZCount(ctx context.Context, key string, min, max string) (int64, error)

ZCount counts the members with scores in [min, max]. Bounds are inclusive by default; prefix a bound with "(" to exclude it.

func (*RedisZSet[Z]) ZPopMin

func (zs *RedisZSet[Z]) ZPopMin(ctx context.Context, key string, count ...int64) ([]Z, error)

ZPopMin removes and returns up to count members with the lowest scores (default 1), in ascending order.

func (*RedisZSet[Z]) ZRangeArgs added in v0.2.0

func (zs *RedisZSet[Z]) ZRangeArgs(ctx context.Context, args *ZArgs) ([]Z, error)

ZRangeArgs returns the members in the range without scores, mirroring RedisMSZSet.ZRangeArgs. Note: decoded Z values only carry the member; Score is 0. Use ZRangeWithScores when scores are needed.

func (*RedisZSet[Z]) ZRangeWithScores

func (zs *RedisZSet[Z]) ZRangeWithScores(ctx context.Context, args *ZArgs) ([]Z, error)

ZRangeWithScores returns the full Z entries (member + score) in the range; the ordering is controlled by ZArgs (ByIndex/ByScore/ByLEX). Note: Redis does not support WITHSCORES combined with BYLEX; use ZRangeArgs for lex ranges.

type Z

type Z redis.Z

func (Z) IdAndValue

func (z Z) IdAndValue() (int64, int64, error)

func (Z) IsEmpty

func (z Z) IsEmpty() bool

func (Z) KeyID

func (z Z) KeyID() (tools.ID, error)

func (Z) KeyStr

func (z Z) KeyStr() (string, error)

func (Z) ScoreInt

func (z Z) ScoreInt() int64

func (Z) Z

func (z Z) Z() redis.Z

type ZArgs

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

ZArgs describes a ZRANGE query: key, range bounds, ordering mode, direction and pagination. Build it fluently, e.g. NewZArgs(key).ByScore().Rev().Range(min, max).

func NewZArgs added in v0.1.1

func NewZArgs(key string) *ZArgs

NewZArgs creates a ZArgs for the given key (index mode, forward by default).

func (*ZArgs) ByIndex

func (a *ZArgs) ByIndex() *ZArgs

ByIndex selects range by index (the default). With REV, indices are interpreted on the reversed set (0 = highest score).

func (*ZArgs) ByLEX

func (a *ZArgs) ByLEX() *ZArgs

ByLEX selects range by lexicographical order. Only meaningful when all members share the same score.

func (*ZArgs) ByScore

func (a *ZArgs) ByScore() *ZArgs

ByScore selects range by score.

func (*ZArgs) Fw

func (a *ZArgs) Fw() *ZArgs

Fw sets forward order (lowest first). This is the default.

func (*ZArgs) MaxString

func (a *ZArgs) MaxString() string

MaxString renders the range maximum as a Redis boundary string. Panics on unsupported boundary types.

func (*ZArgs) MinString

func (a *ZArgs) MinString() string

MinString renders the range minimum as a Redis boundary string. Panics on unsupported boundary types.

func (*ZArgs) Paginate

func (a *ZArgs) Paginate(begin, size int64) *ZArgs

Paginate applies LIMIT offset count to the range result.

func (*ZArgs) Range

func (a *ZArgs) Range(min, max any) *ZArgs

Range sets the range bounds. min is always the smaller value and max the larger one; with REV the effective interval on the wire becomes (max, min).

func (*ZArgs) Redis

func (a *ZArgs) Redis() redis.ZRangeArgs

Redis converts the query into go-redis ZRangeArgs. Redis expects "ZRANGE key max min BYSCORE REV": with REV the min/max positions are swapped on the wire. go-redis v9.14.0 swapped them automatically in appendArgs, but v9.21.0 removed that and leaves it to the caller, so swap here to match String(). Index ranges with REV need no swap (indices are interpreted on the reversed set).

func (*ZArgs) Rev

func (a *ZArgs) Rev() *ZArgs

Rev sets reverse order (highest first). For REV with BYSCORE/BYLEX, pass the bounds in ascending order; they are swapped for the wire automatically.

func (*ZArgs) String

func (a *ZArgs) String() string

String renders the query as a command-like string for logging.

func (*ZArgs) WithKey

func (a *ZArgs) WithKey(key string) *ZArgs

WithKey sets the zset key.

type ZB

type ZB struct {
	V        any
	AsScore  bool // true for score range, false for lexicographical range
	Excluded bool
}

ZB is a boundary value for SCORE or LEX ranges used by ZRange. Use ForScore/ForLex to pick the range mode and Val/Infinite to set the value.

func ZForScore

func ZForScore() *ZB

ZForScore returns a score-mode ZB boundary builder.

func (*ZB) Boundary

func (b *ZB) Boundary(isMin bool) string

Boundary renders the boundary for a Redis command. isMin selects the open-ended default: -inf/- for a minimum, +inf/+ for a maximum. Panics on unsupported value types.

func (*ZB) Exclude

func (b *ZB) Exclude() *ZB

Exclude marks the boundary as excluded from the range.

func (*ZB) ForLex

func (b *ZB) ForLex() *ZB

ForLex switches the boundary to lexicographical mode.

func (*ZB) ForScore

func (b *ZB) ForScore() *ZB

ForScore switches the boundary to score mode.

func (*ZB) Include

func (b *ZB) Include() *ZB

Include marks the boundary as included in the range (the default).

func (*ZB) Infinite

func (b *ZB) Infinite() *ZB

Infinite makes the boundary open-ended: -inf for Min, +inf for Max.

func (*ZB) Max

func (b *ZB) Max() string

Max renders the boundary as a range maximum.

func (*ZB) Min

func (b *ZB) Min() string

Min renders the boundary as a range minimum.

func (*ZB) Val

func (b *ZB) Val(v any) *ZB

Val sets the boundary value. Use nil (or Infinite) for an open end.

type Zs

type Zs[T any] []redis.Z

func (Zs[T]) Decode

func (zs Zs[T]) Decode(decoder RedisZDecoder[T]) ([]T, error)

func (Zs[T]) Encode

func (zs Zs[T]) Encode(encoder RedisZEncoder[T], ts ...T) (Zs[T], error)

func (Zs[T]) Slice

func (zs Zs[T]) Slice() []redis.Z

Jump to

Keyboard shortcuts

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