redi

package module
v0.2.13 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: 19 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

redi.go

中文 | English | Français | 日本語 | 한국어

一个用 Pure Go 复刻 Redisson 的 Redis 客户端库,面向 Redis 8.x。 Wire format(key 布局 / Lua 算法 / 值编码)与 Java Redisson(JsonJacksonCodec 配置)及 redi.py 对齐,可互操作——详见 COMPATIBILITY.md。 已通过 Go ↔ 真实 Redisson 4.6.1 直接双向互操作测试(56 个 TestJavaInterop_* 测试函数)与 Go ↔ redi.py 双向回归(含 Multimap 等)。Client.Get* 工厂当前覆盖 66 种唯一 R 返回类型*。贡献指南见 CONTRIBUTING.md。

特性

特性 说明
RLock / RFairLock / RSpinLock / RNonReentrantLock / RNonReentrantFairLock 可重入、公平 FIFO、自旋与禁止重入锁;支持固定租约或 watchdog
RReadWriteLock 单 HASH + mode 字段的原子读写锁(含同线程 write→read 降级)
RSemaphore / RCountDownLatch 分布式信号量 / 倒计时闩,pub/sub 唤醒
RRateLimiter 滑动窗口限流器,配置持久化到 Redis(跨进程生效),Redisson 4.6 二进制格式
RMap / RMapCache / RMapCacheNative 分布式 Hash;MapCache 支持 entry TTL/maxIdle、packed 表面与容量淘汰;MapCacheNative 用 Redis HPEXPIRE(≥7.4);Map key 可派生 Lock/FairLock/RWLock/Semaphore
RSetCache 带 TTL/maxIdle 的集合(单 ZSET,含随机/批量集合表面,Redisson 格式)
*RMultimap / RMultimapCache / CacheNative(Set/List) 一键多值;内部 ID = HighwayHash-128 大端 base64;Cache 按 key TTL;Native 用 HPEXPIRE+PEXPIRE
RList / RSet / RQueue / RDeque / RBlockingQueue / RBlockingDeque / RBoundedBlockingQueue 集合与队列全家桶;有界阻塞队列使用 redisson_bqs:{name} 容量 companion
RDelayedQueue 延迟队列(timeout ZSET + packed LIST + 后台迁移;支持待投递项查询/删除/清空)
RScoredSortedSet / RLexSortedSet 分数/字典序集合(rank、随机、首尾弹出、正反向范围;Lex 成员裸存储)
RBucket 对象桶(毫秒 TTL、CAS、GetAndDelete…)
RBinaryStream 原始字节流(APPEND/GETRANGE/SETRANGE、顺序流与可 seek 通道,不经过 Codec)
RAtomicLong / RAtomicDouble 原子计数器(十进制字符串,CAS)
RTopic / RPatternTopic 发布订阅(含模式订阅)
RBloomFilter / RBloomFilterNative / RCuckooFilter / RTopK / RTDigest / RGcra 自研布隆 / Redis BF.* / CF.* / TOPK.* / TDIGEST.* / GCRA(命令缺失时测试自动 skip)
RIdGenerator ID 生成器(批量分配缓存)
RTransferQueue / GetQueueTransfer GO_ONLY 跨队列原子迁移(非 Java RemoteService TransferQueue)
RHyperLogLog / RGeo / RBitSet / RStream 基数估计 / 地理索引(批量 GEO、GEOSEARCHSTORE)/ 分布式位图(Java 位序)/ 分布式日志(消费组、Pending、Claim/AutoClaim)
RPermitExpirableSemaphore / RReliableTopic 按许可独立租约过期的信号量 / Stream 可靠广播主题(每订阅者独立消费组 + 崩溃重投递)
RLocalCachedMap 近端缓存 Map(写穿 + Go 失效广播;混部可用 DisableNearCache);数据层 RMap wire
RPriorityQueue / RPriorityBlockingQueue / RPriorityBlockingDeque / RPriorityDeque ZSET+score 优先队列及阻塞/双端包装(非 Java Comparator 同名协议)
RArray / RCircularBuffer Redis 8.8+ ARRAY;CircularBuffer 为稳定槽位环(≠ RingBuffer);命令缺失 skip
RJsonBucket / RVectorSet / RSearch / RMaps RedisJSON / Vector Set / RediSearch 子集 / 批量 HASH 导入(模块缺失 skip)
RClientSideCaching PARTIAL:go-redis RESP3 TRACKING(standalone DB0);非 Java EvictionPolicy
RLongAdder / RDoubleAdder 高争用计数器:本地零网络累积,Sum() 跨实例(含 Java)协同 flush;非破坏性
RFencedLock / RMultiLock / RRedLock 栅栏令牌锁 / 多锁全有或全无 / RedLock 严格多数派(失败回滚)
RTimeSeries 时间序列(同刻多条、entry TTL、首尾读取/弹出、正反向范围,Redisson wire 兼容)
RRingBuffer / RShardedTopic / RFunction 定容环形缓冲(溢出淘汰最旧)/ Redis 7+ 分片 pub/sub(SSUBSCRIBE,cluster 友好)/ Redis Functions(FUNCTION/FCALL)
RKeys / RBuckets / RScript / GetRedisNodes 键空间 / 批量桶 / Lua / 拓扑探测
RBatch 管道批处理(NewBatch() → 结构写操作入队 → Execute() 单次往返,实测 ~7x 加速)
多拓扑 single / cluster / sentinel(redis.UniversalClient)
TUI Dashboard 基于 charmbracelet/bubbles 的终端监控面板
对齐路线 见 演进方案.md 与 COMPATIBILITY.md 工厂总表

值编码默认 JSONCodec:与 Redisson JsonJacksonCodec 互通(超 int32 的整数自动包裹 ["java.lang.Long",v],解码剥离 @class 类型信息),可通过 Config.Codec 替换。结构化读取可用 GetInto / PeekInto / PollInto / Remove*Into(RBucket / RMap / RList / RQueue / RDeque / RLocalCachedMap)绑定到类型化指针;RMap 另有 PutAll / FastPut* / Replace* / Keys / Values。

依赖

快速开始

package main

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

    redi "github.com/linkerlin/redi.go"
)

func main() {
    client, err := redi.NewClient(redi.DefaultConfig())
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    ctx := context.Background()

    // --- RLock(ttl<=0 启用 watchdog 自动续期) ---
    lock := client.GetLock("my-lock")
    if err := lock.Lock(ctx, "instance-1:1", 0); err != nil {
        log.Fatal(err)
    }
    defer lock.Unlock(ctx, "instance-1:1")

    // --- RMap ---
    m := client.GetMap("my-map")
    _ = m.Put(ctx, "key", "value")
    val, _ := m.Get(ctx, "key")
    fmt.Println(val) // value

    // --- RAtomicLong ---
    counter := client.GetAtomicLong("hits")
    n, _ := counter.IncrementAndGet(ctx)
    fmt.Println(n) // 1
}
限流器
rl := client.GetRateLimiter("api-limiter")
rl.TrySetRate(ctx, redi.RateTypeOverall, 100, time.Second) // 持久化到 Redis
if ok, _ := rl.TryAcquire(ctx, 1); !ok {
    // 被限流
}
RBatch(管道批处理)
batch := client.NewBatch()
m := batch.GetMap("my-map")
for i := 0; i < 1000; i++ {
    _ = m.Put(ctx, fmt.Sprint(i), i) // 入队,无网络往返
}
if err := batch.Execute(ctx); err != nil { // 单次往返写入全部
    log.Fatal(err)
}

(批处理结构上的读方法在 Execute 前返回零值 —— 用普通结构读回。)

Cluster / Sentinel
cfg := redi.DefaultConfig()
cfg.Mode = redi.ModeCluster
cfg.Addrs = []string{"node1:7000", "node2:7001", "node3:7002"}

// 或
cfg.Mode = redi.ModeSentinel
cfg.MasterName = "mymaster"
cfg.Addrs = []string{"sentinel-1:26379", "sentinel-2:26379"}

TUI Dashboard

import "github.com/linkerlin/redi.go/dashboard"

// Blocks until the user presses 'q'.
// Locks tab scans the given lock-name patterns (default "*" — Redisson
// lock keys are the raw name, so pass your prefixes to scope the scan).
if err := dashboard.Run(client.Redis(), "order-lock", "job-*"); err != nil {
    log.Fatal(err)
}

三个页签:INFO(服务器指标)、Locks(持锁者/重入计数/TTL)、Limiters(限流器配置与剩余许可)。1/2/3 或 ←/→ 切换。

开发

go test ./...          # 需要本地 Redis(localhost:6379),无 Redis 自动 skip
go test -race ./...    # CI 完整模式
go test -run TestInterop -v .        # Go ↔ redi.py 双向互操作(需 Python + redi.py,缺失自动 skip)
go test -run TestJavaInterop -v .    # Go ↔ Java Redisson 4.6.1 直接双向(需 java+mvn,首次自动编译探针;CI 有独立 java-interop job)
go test -bench . -benchtime 1s .     # 基准
go vet ./...

wire-format 契约测试在 wire_compat_test.go;跨语言双向回归在 interop_redipy_test.go(经 redi.py——其格式已与真实 Redisson 双向实测——传递性验证)。任何破坏互操作的改动都会在这两处失败。

版本

见 CHANGELOG.md。v0.2.0 起 key 不再带 redi: 私有前缀(破坏性变更,换取互操作)。贡献流程见 CONTRIBUTING.md。

Documentation

Overview

Package redi provides a Pure Go Redisson-like client for Redis 8.x.

Wire formats (key names, Lua scripts, value encoding) are aligned with Java Redisson configured with JsonJacksonCodec, and with the sibling ports redi.py (Python). See COMPATIBILITY.md for the per-structure status.

Index

Examples

Constants

View Source
const (
	EventCreated = "created"
	EventUpdated = "updated"
	EventRemoved = "removed"
	EventExpired = "expired"
)

MapCache event kinds (channel suffixes).

Variables

View Source
var ErrClientSideCachingUnavailable = errors.New("redi: client-side caching requires ModeSingle, DB 0, and RESP3")

ErrClientSideCachingUnavailable is returned when a scoped CSC client cannot be created (non-single mode, non-zero DB, or RESP2 forced).

View Source
var ErrIDAlloc = errors.New("redi: id range allocation failed")

ErrIDAlloc is returned when the id generator fails to allocate a range.

View Source
var ErrLockNotHeld = errors.New("redi: lock not held")

ErrLockNotHeld is returned by Unlock when the caller does not own the lock.

View Source
var ErrLockReentrant = errors.New("redi: non-reentrant lock is already held by caller")

ErrLockReentrant is returned when a non-reentrant lock's current holder attempts to acquire it again.

View Source
var ErrMultiLockFailed = errors.New("redi: multilock acquisition failed")

ErrMultiLockFailed is returned by Lock when the context ends before all member locks are acquired (acquired members are rolled back).

View Source
var ErrNoPermit = errors.New("redi: no permit acquired")

ErrNoPermit is returned by Acquire when the context ends first.

View Source
var ErrRedLockFailed = errors.New("redi: redlock majority acquisition failed")

ErrRedLockFailed is returned when the majority cannot be acquired within the requested wait budget.

Functions

func UnpackDelayedMember added in v0.2.1

func UnpackDelayedMember(v string) (string, string, bool)

UnpackDelayedMember is the exported test hook over unpackDelayedMember (wire contract tests assert the packed layout).

Types

type Client

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

Client is the central entry point for all redi.go operations. It wraps a redis.UniversalClient (single / cluster / sentinel) and exposes factory methods for distributed data-structure objects.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient creates a new Client using the provided Config and verifies the connection with a PING.

Example
package main

import (
	"context"
	"fmt"
	"log"

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close() //nolint:errcheck // example

	ctx := context.Background()

	// A distributed lock: ttl<=0 enables the watchdog auto-renewal.
	lock := client.GetLock("demo:lock")
	holder := client.HolderID("1")
	if err := lock.Lock(ctx, holder, 0); err != nil {
		log.Fatal(err)
	}
	defer lock.Unlock(ctx, holder) //nolint:errcheck // example

	// A distributed map (Redisson wire-compatible values).
	_, _ = client.GetKeys().Delete(ctx, "demo:map")
	m := client.GetMap("demo:map")
	_ = m.Put(ctx, "greeting", "hello")
	v, _ := m.Get(ctx, "greeting")
	fmt.Println(v)
}
Output:
hello

func (*Client) Close

func (c *Client) Close() error

Close cancels all background goroutines (watchdogs, delayed-queue workers, topic listeners) and shuts down the underlying connection pool.

func (*Client) Config added in v0.2.13

func (c *Client) Config() Config

Config returns a copy of the client Config (read-only snapshot).

func (*Client) GetArray added in v0.2.13

func (c *Client) GetArray(name string) *RArray

GetArray returns a Redis 8.8+ ARRAY object (AR* commands).

func (*Client) GetAtomicDouble

func (c *Client) GetAtomicDouble(name string) *RAtomicDouble

GetAtomicDouble returns a distributed atomic double.

func (*Client) GetAtomicLong

func (c *Client) GetAtomicLong(name string) *RAtomicLong

GetAtomicLong is the Redisson-style alias for GetRAtomicLong.

func (*Client) GetBinaryStream added in v0.2.13

func (c *Client) GetBinaryStream(name string) *RBinaryStream

GetBinaryStream returns a raw-byte stream backed by a Redis String.

func (*Client) GetBitSet added in v0.2.2

func (c *Client) GetBitSet(name string) *RBitSet

GetBitSet returns a distributed bitset (raw Redis bit numbering).

func (*Client) GetBlockingDeque

func (c *Client) GetBlockingDeque(name string) *RBlockingDeque

GetBlockingDeque returns a deque with blocking consumption from both ends.

func (*Client) GetBlockingQueue

func (c *Client) GetBlockingQueue(name string) *RBlockingQueue

GetBlockingQueue returns a queue with blocking consumption.

func (*Client) GetBloomFilter

func (c *Client) GetBloomFilter(name string) *RBloomFilter

GetBloomFilter returns a distributed bloom filter.

func (*Client) GetBloomFilterNative added in v0.2.13

func (c *Client) GetBloomFilterNative(name string) *RBloomFilterNative

GetBloomFilterNative returns a bloom filter backed by Redis BF.* commands.

func (*Client) GetBoundedBlockingQueue added in v0.2.13

func (c *Client) GetBoundedBlockingQueue(name string) *RBoundedBlockingQueue

GetBoundedBlockingQueue returns a capacity-bounded blocking queue.

func (*Client) GetBucket

func (c *Client) GetBucket(name string) *RBucket

GetBucket returns an object holder (Redis String).

func (*Client) GetBuckets

func (c *Client) GetBuckets() *RBuckets

GetBuckets returns the batch bucket operations facade.

func (*Client) GetCircularBuffer added in v0.2.13

func (c *Client) GetCircularBuffer(name string) *RCircularBuffer

GetCircularBuffer returns a Redis 8.8+ ARRAY circular buffer (≠ RRingBuffer).

func (*Client) GetClientSideCaching added in v0.2.13

func (c *Client) GetClientSideCaching() *RClientSideCaching

GetClientSideCaching returns a facade over this Client. Caching only occurs when Config.ClientSideCaching was set at NewClient, or use GetClientSideCachingWithOptions for a dedicated tracked pool (closer to Redisson getClientSideCaching(options)).

func (*Client) GetClientSideCachingWithOptions added in v0.2.13

func (c *Client) GetClientSideCachingWithOptions(opts *ClientSideCachingOptions) (*RClientSideCaching, error)

GetClientSideCachingWithOptions creates a dedicated RESP3 CLIENT TRACKING client (ModeSingle, DB 0) and returns an owned RClientSideCaching. Caller must Destroy() it (or rely on parent Close after registering via t.Cleanup in tests). Nil opts use go-redis defaults.

func (*Client) GetCountDownLatch

func (c *Client) GetCountDownLatch(name string) *RCountDownLatch

GetCountDownLatch returns a distributed countdown latch.

func (*Client) GetCuckooFilter added in v0.2.13

func (c *Client) GetCuckooFilter(name string) *RCuckooFilter

GetCuckooFilter returns a cuckoo filter backed by Redis CF.* commands.

func (*Client) GetDelayedQueue

func (c *Client) GetDelayedQueue(name string) *RDelayedQueue

GetDelayedQueue returns a delayed-delivery queue feeding the named queue.

func (*Client) GetDeque

func (c *Client) GetDeque(name string) *RDeque

GetDeque returns a distributed double-ended queue.

func (*Client) GetDoubleAdder added in v0.2.8

func (c *Client) GetDoubleAdder(name string) *RDoubleAdder

GetDoubleAdder returns the double variant of GetLongAdder.

func (*Client) GetFairLock added in v0.2.13

func (c *Client) GetFairLock(name string) *RFairLock

GetFairLock returns a FIFO, re-entrant distributed lock.

func (*Client) GetFencedLock added in v0.2.10

func (c *Client) GetFencedLock(name string) *RFencedLock

GetFencedLock returns a re-entrant lock whose acquisitions increment a fencing token (redisson_lock_token:{name}).

func (*Client) GetFunction added in v0.2.12

func (c *Client) GetFunction() *RFunction

GetFunction returns the Redis functions facade (FUNCTION/FCALL).

func (*Client) GetGcra added in v0.2.13

func (c *Client) GetGcra(name string) *RGcra

GetGcra returns a GCRA rate limiter (Redis GCRA command when available).

func (*Client) GetGeo added in v0.2.2

func (c *Client) GetGeo(name string) *RGeo

GetGeo returns a geospatial index (GEOADD/GEOSEARCH).

func (*Client) GetHyperLogLog added in v0.2.2

func (c *Client) GetHyperLogLog(name string) *RHyperLogLog

GetHyperLogLog returns a cardinality estimator (PFADD/PFCOUNT).

func (*Client) GetIdGenerator

func (c *Client) GetIdGenerator(name string) *RIdGenerator

GetIdGenerator returns a distributed id generator.

func (*Client) GetJsonBucket added in v0.2.13

func (c *Client) GetJsonBucket(name string) *RJsonBucket

GetJsonBucket returns a RedisJSON document bucket (JSON.* commands).

func (*Client) GetJsonBuckets added in v0.2.13

func (c *Client) GetJsonBuckets() *RJsonBuckets

GetJsonBuckets returns mass JSON bucket helpers.

func (*Client) GetKeys

func (c *Client) GetKeys() *RKeys

GetKeys returns the keyspace management facade.

func (*Client) GetLexSortedSet

func (c *Client) GetLexSortedSet(name string) *RLexSortedSet

GetLexSortedSet returns a lexicographically sorted set (raw members).

func (*Client) GetList

func (c *Client) GetList(name string) *RList

GetList is the Redisson-style alias for GetRList.

func (*Client) GetListMultimap

func (c *Client) GetListMultimap(name string) *RListMultimap

GetListMultimap returns a multimap with ordered value lists per key.

func (*Client) GetListMultimapCache added in v0.2.13

func (c *Client) GetListMultimapCache(name string) *RListMultimapCache

GetListMultimapCache returns a list multimap with per-key expiration.

func (*Client) GetListMultimapCacheNative added in v0.2.13

func (c *Client) GetListMultimapCacheNative(name string) *RListMultimapCacheNative

GetListMultimapCacheNative returns a list multimap with native per-key HPEXPIRE.

func (*Client) GetLocalCachedMap added in v0.2.5

func (c *Client) GetLocalCachedMap(name string) *RLocalCachedMap

GetLocalCachedMap returns a map with an in-process near cache (write-through + cross-instance invalidation broadcast).

func (*Client) GetLocalCachedMapWithOptions added in v0.2.13

func (c *Client) GetLocalCachedMapWithOptions(name string, opts *LocalCachedMapOptions) *RLocalCachedMap

GetLocalCachedMapWithOptions returns a local cached map with options (e.g. DisableNearCache for mixed Java/Go deployments).

func (*Client) GetLock

func (c *Client) GetLock(name string) *RLock

GetLock is the Redisson-style alias for GetRLock.

func (*Client) GetLongAdder added in v0.2.8

func (c *Client) GetLongAdder(name string) *RLongAdder

GetLongAdder returns a high-contention distributed counter (local buffer + coordinated flush on Sum).

func (*Client) GetMap

func (c *Client) GetMap(name string) *RMap

GetMap is the Redisson-style alias for GetRMap.

func (*Client) GetMapCache

func (c *Client) GetMapCache(name string) *RMapCache

GetMapCache returns a distributed map with per-entry TTL/maxIdle.

func (*Client) GetMapCacheNative added in v0.2.13

func (c *Client) GetMapCacheNative(name string) *RMapCacheNative

GetMapCacheNative returns a map with per-entry TTL via Redis HPEXPIRE (Redis ≥7.4).

func (*Client) GetMaps added in v0.2.13

func (c *Client) GetMaps() *RMaps

GetMaps returns mass HASH map import helpers (DEL+HSET per map).

func (*Client) GetMultiLock added in v0.2.13

func (c *Client) GetMultiLock(locks ...*RLock) *RMultiLock

GetMultiLock is the Redisson-style alias for NewMultiLock.

func (*Client) GetNonReentrantFairLock added in v0.2.13

func (c *Client) GetNonReentrantFairLock(name string) *RNonReentrantFairLock

GetNonReentrantFairLock returns a FIFO lock that rejects holder re-entry.

func (*Client) GetNonReentrantLock added in v0.2.13

func (c *Client) GetNonReentrantLock(name string) *RNonReentrantLock

GetNonReentrantLock returns a lock that refuses re-entry by the same holder.

func (*Client) GetPatternTopic

func (c *Client) GetPatternTopic(pattern string) *RPatternTopic

GetPatternTopic returns a pattern (PSUBSCRIBE) topic.

func (*Client) GetPermitExpirableSemaphore added in v0.2.4

func (c *Client) GetPermitExpirableSemaphore(name string) *RPermitExpirableSemaphore

GetPermitExpirableSemaphore returns a semaphore with individually leased, self-expiring permits.

func (*Client) GetPriorityBlockingDeque added in v0.2.13

func (c *Client) GetPriorityBlockingDeque(name string) *RPriorityBlockingDeque

GetPriorityBlockingDeque returns a BZPOPMIN/BZPOPMAX wrapper over the ZSET priority queue. Not Java Comparator RPriorityBlockingDeque.

func (*Client) GetPriorityBlockingQueue added in v0.2.13

func (c *Client) GetPriorityBlockingQueue(name string) *RPriorityBlockingQueue

GetPriorityBlockingQueue returns a BZPOPMIN wrapper over GetPriorityQueue. Not Java Comparator RPriorityBlockingQueue.

func (*Client) GetPriorityDeque added in v0.2.13

func (c *Client) GetPriorityDeque(name string) *RPriorityDeque

GetPriorityDeque returns non-blocking double-ended ZSET pops. Not Java Comparator RPriorityDeque.

func (*Client) GetPriorityQueue added in v0.2.6

func (c *Client) GetPriorityQueue(name string) *RPriorityQueue

GetPriorityQueue returns a ZSET-backed priority queue (lower score = higher priority). Not Java Comparator RPriorityQueue — see COMPATIBILITY.

func (*Client) GetQueue

func (c *Client) GetQueue(name string) *RQueue

GetQueue is the Redisson-style alias for GetRQueue.

func (*Client) GetQueueTransfer added in v0.2.13

func (c *Client) GetQueueTransfer(name string) *RTransferQueue

GetQueueTransfer is the honest alias of GetTransferQueue (GO_ONLY semantics).

func (*Client) GetRAtomicLong

func (c *Client) GetRAtomicLong(name string) *RAtomicLong

GetRAtomicLong returns a distributed atomic counter for the given name.

func (*Client) GetRList

func (c *Client) GetRList(name string) *RList

GetRList returns a distributed list (Redis List) for the given name.

func (*Client) GetRLock

func (c *Client) GetRLock(name string) *RLock

GetRLock returns a distributed re-entrant lock for the given name.

func (*Client) GetRMap

func (c *Client) GetRMap(name string) *RMap

GetRMap returns a distributed map (Redis Hash) for the given name.

func (*Client) GetRQueue

func (c *Client) GetRQueue(name string) *RQueue

GetRQueue returns a distributed FIFO queue for the given name.

func (*Client) GetRSet

func (c *Client) GetRSet(name string) *RSet

GetRSet returns a distributed set (Redis Set) for the given name.

func (*Client) GetRateLimiter

func (c *Client) GetRateLimiter(name string) *RRateLimiter

GetRateLimiter returns a distributed rate limiter.

func (*Client) GetReadWriteLock

func (c *Client) GetReadWriteLock(name string) *RReadWriteLock

GetReadWriteLock returns a distributed read-write lock for the given name.

func (*Client) GetRedisNodes added in v0.2.13

func (c *Client) GetRedisNodes() *RRedisNodes

GetRedisNodes returns a thin topology probe (PING / Info) for the current mode.

func (*Client) GetReliableTopic added in v0.2.4

func (c *Client) GetReliableTopic(name string) *RReliableTopic

GetReliableTopic returns a reliable (Stream-backed) pub/sub topic.

func (*Client) GetRingBuffer added in v0.2.12

func (c *Client) GetRingBuffer(name string) *RRingBuffer

GetRingBuffer returns a capacity-bounded FIFO that evicts on overflow.

func (*Client) GetScoredSortedSet

func (c *Client) GetScoredSortedSet(name string) *RScoredSortedSet

GetScoredSortedSet returns a distributed sorted set (Redis ZSET).

func (*Client) GetScript

func (c *Client) GetScript() *RScript

GetScript returns the Lua script evaluation facade.

func (*Client) GetSearch added in v0.2.13

func (c *Client) GetSearch() *RSearch

GetSearch returns a RediSearch facade (FT.CREATE/SEARCH/DROPINDEX subset).

func (*Client) GetSemaphore

func (c *Client) GetSemaphore(name string) *RSemaphore

GetSemaphore returns a distributed counting semaphore.

func (*Client) GetSet

func (c *Client) GetSet(name string) *RSet

GetSet is the Redisson-style alias for GetRSet.

func (*Client) GetSetCache

func (c *Client) GetSetCache(name string) *RSetCache

GetSetCache returns a set with per-element TTL/maxIdle.

func (*Client) GetSetMultimap

func (c *Client) GetSetMultimap(name string) *RSetMultimap

GetSetMultimap returns a multimap with unordered value sets per key.

func (*Client) GetSetMultimapCache added in v0.2.13

func (c *Client) GetSetMultimapCache(name string) *RSetMultimapCache

GetSetMultimapCache returns a set multimap with per-key expiration.

func (*Client) GetSetMultimapCacheNative added in v0.2.13

func (c *Client) GetSetMultimapCacheNative(name string) *RSetMultimapCacheNative

GetSetMultimapCacheNative returns a set multimap with native per-key HPEXPIRE.

func (*Client) GetShardedTopic added in v0.2.12

func (c *Client) GetShardedTopic(name string) *RShardedTopic

GetShardedTopic returns a Redis 7+ sharded pub/sub topic (SSUBSCRIBE).

func (*Client) GetSpinLock added in v0.2.13

func (c *Client) GetSpinLock(name string) *RSpinLock

GetSpinLock returns a re-entrant lock that busy-waits instead of pub/sub.

func (*Client) GetStream added in v0.2.3

func (c *Client) GetStream(name string) *RStream

GetStream returns a distributed log stream (Redis Stream).

func (*Client) GetTDigest added in v0.2.13

func (c *Client) GetTDigest(name string) *RTDigest

GetTDigest returns a t-digest sketch backed by Redis TDIGEST.* commands.

func (*Client) GetTimeSeries added in v0.2.11

func (c *Client) GetTimeSeries(name string) *RTimeSeries

GetTimeSeries returns a time-series store (Redisson wire-compatible).

func (*Client) GetTopK added in v0.2.13

func (c *Client) GetTopK(name string) *RTopK

GetTopK returns a Top-K sketch backed by Redis TOPK.* commands.

func (*Client) GetTopic

func (c *Client) GetTopic(name string) *RTopic

GetTopic returns a pub/sub topic.

func (*Client) GetTransferQueue

func (c *Client) GetTransferQueue(name string) *RTransferQueue

GetTransferQueue returns a Go-only queue-to-queue migrate helper. Not Redisson RTransferQueue (RemoteService). Prefer GetQueueTransfer.

func (*Client) GetVectorSet added in v0.2.13

func (c *Client) GetVectorSet(name string) *RVectorSet

GetVectorSet returns a Redis 8+ vector set (VADD/VSIM/…).

func (*Client) HolderID added in v0.2.13

func (c *Client) HolderID(threadID string) string

HolderID builds a Redisson-shaped lock HASH field "{clientUUID}:{threadID}". Use the same threadID for Lock/Unlock/re-entry on one logical holder. An empty threadID becomes "0".

func (*Client) ID

func (c *Client) ID() string

ID returns this client's random id (hex string), analogous to Redisson getId().

func (*Client) NewBatch

func (c *Client) NewBatch() *RBatch

NewBatch returns a batch bound to a fresh pipeline.

func (*Client) NewMultiLock added in v0.2.10

func (c *Client) NewMultiLock(locks ...*RLock) *RMultiLock

NewMultiLock groups RLocks into one all-or-nothing lock.

func (*Client) NewRedLock added in v0.2.13

func (c *Client) NewRedLock(locks ...*RLock) *RRedLock

NewRedLock groups independent RLocks using RedissonRedLock majority rules.

func (*Client) Redis

func (c *Client) Redis() redis.UniversalClient

Redis returns the underlying redis.UniversalClient for advanced direct use.

type ClientSideCachingOptions added in v0.2.13

type ClientSideCachingOptions struct {
	// MaxEntries limits cached replies; ≤0 lets go-redis apply its default bound.
	MaxEntries int
	// MaxMemoryBytes limits estimated cache memory; ≤0 means unlimited (subject
	// to MaxEntries defaulting).
	MaxMemoryBytes int64
	// DrainInterval bounds how often buffered invalidate frames are drained
	// (go-redis default ~5ms when zero).
	DrainInterval time.Duration
	// MaxStaleness caps how long a cached entry may be served without a fresh
	// fetch (0 = disabled). A backstop for lost invalidations.
	MaxStaleness time.Duration
}

ClientSideCachingOptions configures go-redis ClientSideCacheConfig (alias of CacheConfig). Eviction is LRU-ish inside go-redis LocalCache — not Java's EvictionPolicy enum (LRU/LFU/SOFT/WEAK).

type Codec

type Codec interface {
	Encode(v any) (string, error)
	Decode(s string) (any, error)
}

Codec encodes and decodes values stored in Redis, mirroring Redisson's codec layer. The default JSONCodec is wire-compatible with Redisson configured with JsonJacksonCodec (without type info) and with redi.py:

  • Strings, bools, floats and small ints are stored as bare JSON.
  • Ints outside the 32-bit range are wrapped as ["java.lang.Long", v] (matching Redisson's Long wrapping).
  • Decode unwraps ["java.lang.Long", v] / ["java.util.ArrayList", v]-style typed wrappers and strips JsonJacksonCodec "@class" fields.
  • Bytes that are not valid JSON decode to the raw string unchanged.

type Config

type Config struct {
	// Mode selects single / cluster / sentinel topology.
	Mode Mode
	// Addrs holds server addresses: the node for single, seed nodes for
	// cluster, sentinel addresses for sentinel mode.
	// Defaults to ["localhost:6379"].
	Addrs []string
	// MasterName is the sentinel master set name (sentinel mode only).
	MasterName string
	// Username for AUTH (empty if none).
	Username string
	// Password for authentication (empty if none).
	Password string
	// DB is the database number (single mode only).
	DB int
	// PoolSize is the number of connections in the pool.
	PoolSize int
	// DialTimeout for establishing new connections.
	DialTimeout time.Duration
	// ReadTimeout for socket reads.
	ReadTimeout time.Duration
	// WriteTimeout for socket writes.
	WriteTimeout time.Duration
	// Codec encodes/decodes values. Defaults to JSONCodec
	// (Redisson JsonJacksonCodec-compatible).
	Codec Codec
	// LockWatchdogTimeout is the lease time used by RLock when no explicit
	// TTL is given; the watchdog renews it every LockWatchdogTimeout/3.
	// Defaults to 30s (matching Redisson's lockWatchdogTimeout).
	LockWatchdogTimeout time.Duration
	// Logger receives background-goroutine error reports.
	// Defaults to the standard log package.
	Logger Logger
	// Protocol is the RESP version passed to go-redis (2 or 3). Zero lets
	// go-redis pick its default (currently 3). Required to be 3 when
	// ClientSideCaching is set.
	Protocol int
	// ClientSideCaching enables go-redis RESP3 client-side caching on
	// standalone ModeSingle clients (DB 0). Cluster/Sentinel ignore this
	// option. Prefer GetClientSideCachingWithOptions for a Redisson-shaped
	// runtime scope that owns its own tracked connection pool.
	ClientSideCaching *ClientSideCachingOptions
}

Config holds connection and behaviour options for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for Redis 8.x.

type EvictionMode added in v0.2.13

type EvictionMode string

EvictionMode controls which entries a size-limited map cache evicts.

const (
	EvictionModeLRU EvictionMode = "LRU"
	EvictionModeLFU EvictionMode = "LFU"
)

type GcraResult added in v0.2.13

type GcraResult struct {
	Allowed      bool
	Remaining    int64
	RetryAfterMs int64
	ResetAfterMs int64
}

GcraResult mirrors Redisson's GcraResult.

type GeoEntry added in v0.2.2

type GeoEntry struct {
	Member   any
	Lon, Lat float64
	Dist     float64
	HasDist  bool
}

GeoEntry is one search result.

type GeoLocation added in v0.2.13

type GeoLocation struct {
	Lon, Lat float64
	Member   any
}

GeoLocation describes one member and its longitude/latitude.

type IndexField added in v0.2.13

type IndexField struct {
	Name  string
	Type  IndexFieldType
	Alias string
}

IndexField describes one SCHEMA field.

type IndexFieldType added in v0.2.13

type IndexFieldType string

IndexFieldType is a RediSearch schema field type.

const (
	IndexText    IndexFieldType = "TEXT"
	IndexNumeric IndexFieldType = "NUMERIC"
	IndexTag     IndexFieldType = "TAG"
	IndexGeo     IndexFieldType = "GEO"
)

type IndexOptions added in v0.2.13

type IndexOptions struct {
	On       string // HASH or JSON (default HASH)
	Prefixes []string
}

IndexOptions configures FT.CREATE.

type JSONCodec

type JSONCodec struct{}

JSONCodec is the default Codec. It is stateless and safe for concurrent use.

func (JSONCodec) Decode

func (JSONCodec) Decode(s string) (any, error)

Decode implements Codec. Numbers decode to json.Number to preserve precision across languages.

func (JSONCodec) Encode

func (JSONCodec) Encode(v any) (string, error)

Encode implements Codec.

type LocalCachedMapOptions added in v0.2.13

type LocalCachedMapOptions struct {
	// DisableNearCache turns off the in-process cache (every Get hits Redis).
	// Use for Java/Go mixed deployments until Redisson binary invalidation is
	// implemented — data layer remains wire-compatible.
	DisableNearCache bool
	// CacheTTL expires local entries after this duration (0 = no local TTL).
	CacheTTL time.Duration
	// SizeLimit caps local entries (0 = unlimited).
	SizeLimit int
}

LocalCachedMapOptions configures near-cache behaviour.

type Logger

type Logger interface {
	Printf(format string, v ...any)
}

Logger is the minimal logging interface used to report background goroutine failures (lock watchdog renewals, delayed-queue migration…).

type Mode

type Mode int

Mode selects the Redis deployment topology.

const (
	// ModeSingle connects to a single Redis server (default).
	ModeSingle Mode = iota
	// ModeCluster connects to a Redis Cluster.
	ModeCluster
	// ModeSentinel connects via Redis Sentinel (MasterName required).
	ModeSentinel
)

type MultimapEntry added in v0.2.13

type MultimapEntry struct {
	Key   any
	Value any
}

MultimapEntry is one key/value association returned by Entries.

type PendingEntry added in v0.2.3

type PendingEntry struct {
	ID         string
	Consumer   string
	IdleMs     int64
	Deliveries int64
}

PendingEntry describes an entry delivered but not yet acknowledged.

type RArray added in v0.2.13

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

RArray is a Redis 8.8+ ARRAY type (ARSET/ARGET/…). Values are codec-encoded like other Redisson structures. Commands missing on older Redis return the server error; tests skip when the ARRAY command family is unavailable.

func (*RArray) Clear added in v0.2.13

func (a *RArray) Clear(ctx context.Context) error

Clear deletes the array key.

func (*RArray) ClearExpire added in v0.2.13

func (o *RArray) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RArray) Count added in v0.2.13

func (a *RArray) Count(ctx context.Context) (int64, error)

Count returns the number of set (non-empty) slots (ARCOUNT).

func (*RArray) Delete added in v0.2.13

func (o *RArray) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RArray) DeleteIndexes added in v0.2.13

func (a *RArray) DeleteIndexes(ctx context.Context, indexes ...int64) (int64, error)

Delete removes values at the given indexes (ARDEL).

func (*RArray) DeleteRange added in v0.2.13

func (a *RArray) DeleteRange(ctx context.Context, start, end int64) (int64, error)

DeleteRange removes indexes in [start, end] inclusive (ARDELRANGE).

func (*RArray) Exists added in v0.2.13

func (o *RArray) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RArray) Expire added in v0.2.13

func (o *RArray) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RArray) ExpireAt added in v0.2.13

func (o *RArray) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RArray) Get added in v0.2.13

func (a *RArray) Get(ctx context.Context, index int64) (any, error)

Get returns the value at index, or (nil, nil) when unset.

func (*RArray) GetMulti added in v0.2.13

func (a *RArray) GetMulti(ctx context.Context, indexes ...int64) ([]any, error)

GetMulti returns values at the given indexes (ARMGET). Missing slots are nil.

func (*RArray) Insert added in v0.2.13

func (a *RArray) Insert(ctx context.Context, values ...any) (int64, error)

Insert appends values at the internal cursor (ARINSERT). Returns the last inserted index.

func (*RArray) Length added in v0.2.13

func (a *RArray) Length(ctx context.Context) (int64, error)

Length returns max index + 1 (ARLEN), or 0 when the key is absent.

func (*RArray) Name added in v0.2.13

func (o *RArray) Name() string

Name returns the Redis key name of the object.

func (*RArray) Next added in v0.2.13

func (a *RArray) Next(ctx context.Context) (int64, error)

Next returns the next index ARINSERT would use (ARNEXT).

func (*RArray) Range added in v0.2.13

func (a *RArray) Range(ctx context.Context, start, end int64) ([]any, error)

Range returns values in [start, end] inclusive (ARGETRANGE). Unset slots are nil.

func (*RArray) RemainTTL added in v0.2.13

func (o *RArray) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RArray) Rename added in v0.2.13

func (o *RArray) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RArray) Seek added in v0.2.13

func (a *RArray) Seek(ctx context.Context, index int64) (bool, error)

Seek sets the insert cursor (ARSEEK).

func (*RArray) Set added in v0.2.13

func (a *RArray) Set(ctx context.Context, index int64, value any) (int64, error)

Set stores value at index (ARSET). Returns the number of newly filled slots.

func (*RArray) SetAll added in v0.2.13

func (a *RArray) SetAll(ctx context.Context, index int64, values ...any) (int64, error)

SetAll stores contiguous values starting at index.

func (*RArray) SetEntries added in v0.2.13

func (a *RArray) SetEntries(ctx context.Context, entries map[int64]any) (int64, error)

SetEntries stores non-contiguous index→value pairs (ARMSET).

func (*RArray) Touch added in v0.2.13

func (o *RArray) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RArray) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RAtomicDouble

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

RAtomicDouble is a distributed atomic double backed by a Redis String holding a plain decimal number (Redisson StringCodec-compatible).

func (*RAtomicDouble) AddAndGet

func (a *RAtomicDouble) AddAndGet(ctx context.Context, delta float64) (float64, error)

AddAndGet atomically adds delta (INCRBYFLOAT) and returns the new value.

func (*RAtomicDouble) ClearExpire

func (o *RAtomicDouble) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RAtomicDouble) CompareAndSet

func (a *RAtomicDouble) CompareAndSet(ctx context.Context, expect, newVal float64) (bool, error)

CompareAndSet sets newVal only when the current value equals expect (numeric comparison; missing key counts as 0).

func (*RAtomicDouble) DecrementAndGet

func (a *RAtomicDouble) DecrementAndGet(ctx context.Context) (float64, error)

DecrementAndGet subtracts 1 atomically.

func (*RAtomicDouble) Delete

func (o *RAtomicDouble) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RAtomicDouble) Exists

func (o *RAtomicDouble) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RAtomicDouble) Expire

func (o *RAtomicDouble) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RAtomicDouble) ExpireAt

func (o *RAtomicDouble) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RAtomicDouble) Get

func (a *RAtomicDouble) Get(ctx context.Context) (float64, error)

Get returns the current value; 0 when the key does not exist.

func (*RAtomicDouble) GetAndAdd added in v0.2.13

func (a *RAtomicDouble) GetAndAdd(ctx context.Context, delta float64) (float64, error)

GetAndAdd adds delta and returns the previous value.

func (*RAtomicDouble) GetAndDecrement added in v0.2.13

func (a *RAtomicDouble) GetAndDecrement(ctx context.Context) (float64, error)

GetAndDecrement returns the previous value then decrements by 1.

func (*RAtomicDouble) GetAndDelete added in v0.2.13

func (a *RAtomicDouble) GetAndDelete(ctx context.Context) (float64, error)

GetAndDelete removes the key and returns its previous value (0 if absent).

func (*RAtomicDouble) GetAndIncrement added in v0.2.13

func (a *RAtomicDouble) GetAndIncrement(ctx context.Context) (float64, error)

GetAndIncrement returns the previous value then increments by 1.

func (*RAtomicDouble) GetAndSet added in v0.2.13

func (a *RAtomicDouble) GetAndSet(ctx context.Context, value float64) (float64, error)

GetAndSet replaces the value and returns the previous one (alias of Set).

func (*RAtomicDouble) IncrementAndGet

func (a *RAtomicDouble) IncrementAndGet(ctx context.Context) (float64, error)

IncrementAndGet adds 1 atomically.

func (*RAtomicDouble) Name

func (o *RAtomicDouble) Name() string

Name returns the Redis key name of the object.

func (*RAtomicDouble) RemainTTL

func (o *RAtomicDouble) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RAtomicDouble) Rename

func (o *RAtomicDouble) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RAtomicDouble) Set

func (a *RAtomicDouble) Set(ctx context.Context, value float64) (float64, error)

Set replaces the value and returns the previous one.

func (*RAtomicDouble) SetIfGreater added in v0.2.13

func (a *RAtomicDouble) SetIfGreater(ctx context.Context, threshold, value float64) (bool, error)

SetIfGreater sets value when the current value is greater than threshold.

func (*RAtomicDouble) SetIfLess added in v0.2.13

func (a *RAtomicDouble) SetIfLess(ctx context.Context, threshold, value float64) (bool, error)

SetIfLess sets value when the current value is less than threshold.

func (*RAtomicDouble) Touch

func (o *RAtomicDouble) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RAtomicDouble) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RAtomicLong

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

RAtomicLong is a distributed atomic 64-bit integer backed by a Redis String holding a plain decimal number (Redisson StringCodec format, interoperable without any codec configuration).

Example
package main

import (
	"context"
	"fmt"

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		fmt.Println("skip:", err)
		return
	}
	defer client.Close() //nolint:errcheck // example
	ctx := context.Background()
	_, _ = client.GetKeys().Delete(ctx, "demo:hits")
	counter := client.GetAtomicLong("demo:hits")
	counter.Set(ctx, 0) //nolint:errcheck // example

	n, _ := counter.IncrementAndGet(ctx)
	fmt.Println("after inc:", n)

	swapped, _ := counter.CompareAndSet(ctx, 1, 100)
	fmt.Println("cas 1->100:", swapped)
}
Output:
after inc: 1
cas 1->100: true

func (*RAtomicLong) AddAndGet

func (a *RAtomicLong) AddAndGet(ctx context.Context, delta int64) (int64, error)

AddAndGet atomically adds delta to the value and returns the new value.

func (*RAtomicLong) ClearExpire

func (o *RAtomicLong) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RAtomicLong) CompareAndDelete added in v0.2.13

func (a *RAtomicLong) CompareAndDelete(
	ctx context.Context, expect int64,
) (bool, error)

CompareAndDelete deletes the value only when it equals expect.

func (*RAtomicLong) CompareAndSet

func (a *RAtomicLong) CompareAndSet(ctx context.Context, expect, newVal int64) (bool, error)

CompareAndSet atomically sets the value to newVal only when the current value equals expect. A missing key counts as 0.

func (*RAtomicLong) DecrementAndGet

func (a *RAtomicLong) DecrementAndGet(ctx context.Context) (int64, error)

DecrementAndGet atomically decrements the value by 1 and returns the new value.

func (*RAtomicLong) Delete

func (o *RAtomicLong) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RAtomicLong) Exists

func (o *RAtomicLong) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RAtomicLong) Expire

func (o *RAtomicLong) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RAtomicLong) ExpireAt

func (o *RAtomicLong) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RAtomicLong) Get

func (a *RAtomicLong) Get(ctx context.Context) (int64, error)

Get returns the current value; 0 when the key does not exist (Redisson semantics).

func (*RAtomicLong) GetAndAdd

func (a *RAtomicLong) GetAndAdd(ctx context.Context, delta int64) (int64, error)

GetAndAdd atomically adds delta and returns the previous value.

func (*RAtomicLong) GetAndDecrement added in v0.2.13

func (a *RAtomicLong) GetAndDecrement(ctx context.Context) (int64, error)

GetAndDecrement returns the previous value then decrements by 1.

func (*RAtomicLong) GetAndDelete added in v0.2.13

func (a *RAtomicLong) GetAndDelete(ctx context.Context) (int64, error)

GetAndDelete removes the key and returns its previous value (0 if absent).

func (*RAtomicLong) GetAndIncrement added in v0.2.13

func (a *RAtomicLong) GetAndIncrement(ctx context.Context) (int64, error)

GetAndIncrement returns the previous value then increments by 1.

func (*RAtomicLong) GetAndSet added in v0.2.13

func (a *RAtomicLong) GetAndSet(ctx context.Context, value int64) (int64, error)

GetAndSet replaces the value and returns the previous one (alias of Set).

func (*RAtomicLong) IncrementAndGet

func (a *RAtomicLong) IncrementAndGet(ctx context.Context) (int64, error)

IncrementAndGet atomically increments the value by 1 and returns the new value.

func (*RAtomicLong) Name

func (o *RAtomicLong) Name() string

Name returns the Redis key name of the object.

func (*RAtomicLong) RemainTTL

func (o *RAtomicLong) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RAtomicLong) Rename

func (o *RAtomicLong) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RAtomicLong) Set

func (a *RAtomicLong) Set(ctx context.Context, value int64) (int64, error)

Set replaces the value and returns the previous one.

func (*RAtomicLong) SetIfGreater added in v0.2.13

func (a *RAtomicLong) SetIfGreater(ctx context.Context, threshold, value int64) (bool, error)

SetIfGreater sets value when the current value is greater than threshold.

func (*RAtomicLong) SetIfLess added in v0.2.13

func (a *RAtomicLong) SetIfLess(ctx context.Context, threshold, value int64) (bool, error)

SetIfLess sets value when the current value is less than threshold.

func (*RAtomicLong) Touch

func (o *RAtomicLong) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RAtomicLong) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBatch

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

RBatch queues structure operations into a single pipeline; Execute flushes them all in one round-trip (the classic ~10x latency win over sequential commands).

The structures returned by the Get* factories below are bound to the pipeline: write methods (Put/Add/Offer/Set/…) queue commands and return immediately. Read methods return zero values until Execute has run — use a normal client structure to read results back (Redisson has the same constraint: batch reads need its Async API).

Example
package main

import (
	"context"
	"fmt"
	"log"

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		fmt.Println("skip:", err)
		return
	}
	defer client.Close() //nolint:errcheck // example
	ctx := context.Background()

	// Queue writes into one pipeline, flush in a single round-trip.
	_, _ = client.GetKeys().Delete(ctx, "demo:batch")
	batch := client.NewBatch()
	m := batch.GetMap("demo:batch")
	for i := 0; i < 100; i++ {
		_ = m.Put(ctx, fmt.Sprint(i), i)
	}
	if err := batch.Execute(ctx); err != nil {
		log.Fatal(err)
	}

	sz, _ := client.GetMap("demo:batch").Size(ctx)
	fmt.Println("batched size:", sz)
	_ = client.GetMap("demo:batch").Clear(ctx)
}
Output:
batched size: 100

func (*RBatch) Discard

func (b *RBatch) Discard()

Discard drops the queued commands without executing them.

func (*RBatch) Execute

func (b *RBatch) Execute(ctx context.Context) error

Execute flushes every queued command in one round-trip.

func (*RBatch) GetAtomicDouble

func (b *RBatch) GetAtomicDouble(name string) *RAtomicDouble

GetAtomicDouble returns a pipeline-bound double counter.

func (*RBatch) GetAtomicLong

func (b *RBatch) GetAtomicLong(name string) *RAtomicLong

GetAtomicLong returns a pipeline-bound counter.

func (*RBatch) GetBucket

func (b *RBatch) GetBucket(name string) *RBucket

GetBucket returns a pipeline-bound bucket.

func (*RBatch) GetDeque

func (b *RBatch) GetDeque(name string) *RDeque

GetDeque returns a pipeline-bound deque.

func (*RBatch) GetList

func (b *RBatch) GetList(name string) *RList

GetList returns a pipeline-bound list.

func (*RBatch) GetMap

func (b *RBatch) GetMap(name string) *RMap

GetMap returns a pipeline-bound map.

func (*RBatch) GetQueue

func (b *RBatch) GetQueue(name string) *RQueue

GetQueue returns a pipeline-bound queue.

func (*RBatch) GetScoredSortedSet

func (b *RBatch) GetScoredSortedSet(name string) *RScoredSortedSet

GetScoredSortedSet returns a pipeline-bound sorted set.

func (*RBatch) GetSet

func (b *RBatch) GetSet(name string) *RSet

GetSet returns a pipeline-bound set.

func (*RBatch) Len

func (b *RBatch) Len() int

Len returns the number of queued commands.

type RBinaryStream added in v0.2.13

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

RBinaryStream stores raw bytes in a Redis String. Unlike RBucket, values bypass the configured Codec to match Redisson's ByteArrayCodec wire format.

func (*RBinaryStream) Append added in v0.2.13

func (s *RBinaryStream) Append(ctx context.Context, data []byte) (int64, error)

Append appends raw bytes and returns the resulting stream size.

func (*RBinaryStream) ClearExpire added in v0.2.13

func (o *RBinaryStream) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RBinaryStream) Delete added in v0.2.13

func (o *RBinaryStream) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RBinaryStream) Exists added in v0.2.13

func (o *RBinaryStream) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RBinaryStream) Expire added in v0.2.13

func (o *RBinaryStream) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RBinaryStream) ExpireAt added in v0.2.13

func (o *RBinaryStream) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RBinaryStream) Get added in v0.2.13

func (s *RBinaryStream) Get(ctx context.Context) ([]byte, error)

Get returns all bytes, or (nil, nil) when the stream is absent.

func (*RBinaryStream) GetChannel added in v0.2.13

func (s *RBinaryStream) GetChannel(ctx context.Context) *RBinaryStreamChannel

GetChannel returns a seekable raw-byte channel starting at position 0. The returned channel is not safe for concurrent use.

func (*RBinaryStream) GetInputStream added in v0.2.13

func (s *RBinaryStream) GetInputStream(ctx context.Context) *RBinaryStreamReader

GetInputStream returns a sequential raw-byte reader starting at position 0. The returned reader is not safe for concurrent use.

func (*RBinaryStream) GetOutputStream added in v0.2.13

func (s *RBinaryStream) GetOutputStream(ctx context.Context) *RBinaryStreamWriter

GetOutputStream returns an append-only raw-byte writer. The returned writer is not safe for concurrent use.

func (*RBinaryStream) Name added in v0.2.13

func (o *RBinaryStream) Name() string

Name returns the Redis key name of the object.

func (*RBinaryStream) Read added in v0.2.13

func (s *RBinaryStream) Read(ctx context.Context, offset, length int64) ([]byte, error)

Read returns length bytes starting at offset. A length of -1 reads through the end of the stream.

func (*RBinaryStream) RemainTTL added in v0.2.13

func (o *RBinaryStream) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RBinaryStream) Rename added in v0.2.13

func (o *RBinaryStream) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBinaryStream) Set added in v0.2.13

func (s *RBinaryStream) Set(ctx context.Context, data []byte) error

Set replaces the stream with raw bytes.

func (*RBinaryStream) Size added in v0.2.13

func (s *RBinaryStream) Size(ctx context.Context) (int64, error)

Size returns the stream size in bytes.

func (*RBinaryStream) Touch added in v0.2.13

func (o *RBinaryStream) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RBinaryStream) Truncate added in v0.2.13

func (s *RBinaryStream) Truncate(ctx context.Context, size int64) error

Truncate shrinks the stream to size bytes. As in Redisson 4.6.1, growing is a no-op, size zero deletes the key, and a non-zero shrink clears its TTL.

func (o *RBinaryStream) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RBinaryStream) Write added in v0.2.13

func (s *RBinaryStream) Write(ctx context.Context, offset int64, data []byte) (int, error)

Write writes raw bytes at offset using SETRANGE and returns bytes written. A write beyond the current end fills the gap with zero bytes.

type RBinaryStreamChannel added in v0.2.13

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

RBinaryStreamChannel is a seekable read/write view over an RBinaryStream. Close is intentionally a no-op, matching Redisson's channel.

func (*RBinaryStreamChannel) Close added in v0.2.13

func (c *RBinaryStreamChannel) Close() error

Close is a no-op because the channel doesn't own a Redis connection.

func (*RBinaryStreamChannel) IsOpen added in v0.2.13

func (c *RBinaryStreamChannel) IsOpen() bool

IsOpen always returns true, matching Redisson's no-op channel Close.

func (*RBinaryStreamChannel) Position added in v0.2.13

func (c *RBinaryStreamChannel) Position() int64

Position returns the current channel position.

func (*RBinaryStreamChannel) Read added in v0.2.13

func (c *RBinaryStreamChannel) Read(p []byte) (int, error)

Read reads from the current position and advances by the bytes returned.

func (*RBinaryStreamChannel) Seek added in v0.2.13

func (c *RBinaryStreamChannel) Seek(offset int64, whence int) (int64, error)

Seek sets the channel position using standard io.Seeker semantics.

func (*RBinaryStreamChannel) Size added in v0.2.13

func (c *RBinaryStreamChannel) Size() (int64, error)

Size returns the underlying stream size.

func (*RBinaryStreamChannel) Truncate added in v0.2.13

func (c *RBinaryStreamChannel) Truncate(size int64) error

Truncate shrinks the underlying stream without changing the channel position.

func (*RBinaryStreamChannel) Write added in v0.2.13

func (c *RBinaryStreamChannel) Write(p []byte) (int, error)

Write writes at the current position and advances by len(p).

type RBinaryStreamReader added in v0.2.13

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

RBinaryStreamReader is the Go counterpart of Redisson's InputStream view.

func (*RBinaryStreamReader) Read added in v0.2.13

func (r *RBinaryStreamReader) Read(p []byte) (int, error)

Read reads from the current position and advances by the bytes returned.

type RBinaryStreamWriter added in v0.2.13

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

RBinaryStreamWriter is the Go counterpart of Redisson's append-only OutputStream view.

func (*RBinaryStreamWriter) Write added in v0.2.13

func (w *RBinaryStreamWriter) Write(p []byte) (int, error)

Write appends p and reports the number of bytes written.

type RBitSet added in v0.2.2

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

RBitSet is a distributed bitset over a Redis bitmap. Bit indexes are the raw Redis GETBIT/SETBIT indexes — identical to Java Redisson's RedissonBitSet (verified from its toByteArray: bit i maps to byte[i/8] bit (7-i%8), i.e. native MSB-first Redis numbering; no reversal anywhere).

func (*RBitSet) And added in v0.2.2

func (b *RBitSet) And(ctx context.Context, others ...string) error

And / Or / Xor apply BITOP with other bitsets, storing into this one.

func (*RBitSet) AndOr added in v0.2.13

func (b *RBitSet) AndOr(ctx context.Context, others ...string) (int64, error)

AndOr stores bits set in this bitset and in at least one other bitset.

func (*RBitSet) BitFieldGet added in v0.2.13

func (b *RBitSet) BitFieldGet(ctx context.Context, signed bool, width int, offset int64) (int64, error)

BitFieldGet reads a signed or unsigned integer field.

func (*RBitSet) BitFieldIncrBy added in v0.2.13

func (b *RBitSet) BitFieldIncrBy(
	ctx context.Context,
	signed bool,
	width int,
	offset, increment int64,
) (int64, error)

BitFieldIncrBy increments a field and returns its new value (WRAP overflow).

func (*RBitSet) BitFieldSet added in v0.2.13

func (b *RBitSet) BitFieldSet(
	ctx context.Context,
	signed bool,
	width int,
	offset, value int64,
) (int64, error)

BitFieldSet writes a field and returns its previous value.

func (*RBitSet) Cardinality added in v0.2.2

func (b *RBitSet) Cardinality(ctx context.Context) (int64, error)

Cardinality returns the number of set bits (BITCOUNT).

func (*RBitSet) Clear added in v0.2.2

func (b *RBitSet) Clear(ctx context.Context, bitIndex int64) (bool, error)

Clear clears the bit, returning its previous value.

func (*RBitSet) ClearAll added in v0.2.2

func (b *RBitSet) ClearAll(ctx context.Context) error

ClearAll deletes the bitset.

func (*RBitSet) ClearExpire added in v0.2.2

func (o *RBitSet) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RBitSet) ClearRange added in v0.2.13

func (b *RBitSet) ClearRange(ctx context.Context, from, toInclusive int64) error

ClearRange clears every bit in the inclusive range [from, toInclusive].

func (*RBitSet) Delete added in v0.2.2

func (o *RBitSet) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RBitSet) Diff added in v0.2.13

func (b *RBitSet) Diff(ctx context.Context, others ...string) (int64, error)

Diff stores bits set in this bitset and absent from every other bitset. It returns the stored bitmap length in bytes.

func (*RBitSet) Exists added in v0.2.2

func (o *RBitSet) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RBitSet) Expire added in v0.2.2

func (o *RBitSet) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RBitSet) ExpireAt added in v0.2.2

func (o *RBitSet) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RBitSet) FromByteArray added in v0.2.2

func (b *RBitSet) FromByteArray(ctx context.Context, data []byte) error

FromByteArray replaces the bitset with raw bytes (MSB-first, matching Java).

func (*RBitSet) Get added in v0.2.2

func (b *RBitSet) Get(ctx context.Context, bitIndex int64) (bool, error)

Get returns the bit at index.

func (*RBitSet) GetMany added in v0.2.13

func (b *RBitSet) GetMany(ctx context.Context, indexes ...int64) ([]bool, error)

GetMany returns bits in the same order as indexes.

func (*RBitSet) Length added in v0.2.2

func (b *RBitSet) Length(ctx context.Context) (int64, error)

Length returns the highest set bit index + 1 (Java BitSet semantics; 0 when empty).

func (*RBitSet) Name added in v0.2.2

func (o *RBitSet) Name() string

Name returns the Redis key name of the object.

func (*RBitSet) Not added in v0.2.2

func (b *RBitSet) Not(ctx context.Context, source ...string) error

Not applies bitwise NOT in place. An optional source name preserves the previous Not(ctx, otherName) form.

func (*RBitSet) Or added in v0.2.2

func (b *RBitSet) Or(ctx context.Context, others ...string) error

Or applies a bitwise OR.

func (*RBitSet) RemainTTL added in v0.2.2

func (o *RBitSet) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RBitSet) Rename added in v0.2.2

func (o *RBitSet) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBitSet) Set added in v0.2.2

func (b *RBitSet) Set(ctx context.Context, bitIndex int64, value bool) (bool, error)

Set sets (or clears) the bit, returning its previous value.

func (*RBitSet) SetExclusive added in v0.2.13

func (b *RBitSet) SetExclusive(
	ctx context.Context, others ...string,
) (int64, error)

SetExclusive stores bits set in exactly one source bitset.

func (*RBitSet) SetMany added in v0.2.13

func (b *RBitSet) SetMany(ctx context.Context, value bool, indexes ...int64) error

SetMany sets all indexes to value in one BITFIELD command.

func (*RBitSet) SetRange added in v0.2.13

func (b *RBitSet) SetRange(ctx context.Context, from, toInclusive int64) error

SetRange sets every bit in the inclusive range [from, toInclusive].

func (*RBitSet) Size added in v0.2.13

func (b *RBitSet) Size(ctx context.Context) (int64, error)

Size returns the logical bit length (highest set bit index + 1).

func (*RBitSet) ToByteArray added in v0.2.2

func (b *RBitSet) ToByteArray(ctx context.Context) ([]byte, error)

ToByteArray returns the raw bitmap bytes (MSB-first, matching Java).

func (*RBitSet) Touch added in v0.2.2

func (o *RBitSet) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RBitSet) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RBitSet) Xor added in v0.2.2

func (b *RBitSet) Xor(ctx context.Context, others ...string) error

Xor applies a bitwise XOR.

type RBlockingDeque

type RBlockingDeque struct {
	*RDeque
}

RBlockingDeque is an RDeque with blocking consumption from both ends.

func (RBlockingDeque) ClearExpire

func (o RBlockingDeque) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RBlockingDeque) Delete

func (o RBlockingDeque) Delete(ctx context.Context) error

Delete removes the object's key.

func (RBlockingDeque) Exists

func (o RBlockingDeque) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RBlockingDeque) Expire

func (o RBlockingDeque) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RBlockingDeque) ExpireAt

func (o RBlockingDeque) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RBlockingDeque) Name

func (o RBlockingDeque) Name() string

Name returns the Redis key name of the object.

func (*RBlockingDeque) PollFirstWithTimeout

func (d *RBlockingDeque) PollFirstWithTimeout(ctx context.Context, timeout time.Duration) (any, error)

PollFirstWithTimeout blocks up to timeout for a head element.

func (*RBlockingDeque) PollLastWithTimeout

func (d *RBlockingDeque) PollLastWithTimeout(ctx context.Context, timeout time.Duration) (any, error)

PollLastWithTimeout blocks up to timeout for a tail element.

func (RBlockingDeque) RemainTTL

func (o RBlockingDeque) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RBlockingDeque) Rename

func (o RBlockingDeque) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBlockingDeque) TakeFirst

func (d *RBlockingDeque) TakeFirst(ctx context.Context) (any, error)

TakeFirst blocks until an element is available at the head.

func (*RBlockingDeque) TakeLast

func (d *RBlockingDeque) TakeLast(ctx context.Context) (any, error)

TakeLast blocks until an element is available at the tail.

func (RBlockingDeque) Touch

func (o RBlockingDeque) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RBlockingDeque) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBlockingQueue

type RBlockingQueue struct {
	*RQueue
}

RBlockingQueue is an RQueue with blocking consumption (BLPOP).

func (RBlockingQueue) ClearExpire

func (o RBlockingQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RBlockingQueue) Delete

func (o RBlockingQueue) Delete(ctx context.Context) error

Delete removes the object's key.

func (RBlockingQueue) Exists

func (o RBlockingQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RBlockingQueue) Expire

func (o RBlockingQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RBlockingQueue) ExpireAt

func (o RBlockingQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RBlockingQueue) Name

func (o RBlockingQueue) Name() string

Name returns the Redis key name of the object.

func (*RBlockingQueue) PollFromAny added in v0.2.13

func (q *RBlockingQueue) PollFromAny(
	ctx context.Context, timeout time.Duration, otherNames ...string,
) (any, error)

PollFromAny blocks for a head element from this queue or any named queue. This queue has priority when multiple queues already contain elements.

func (*RBlockingQueue) PollLastAndOfferFirstTo added in v0.2.13

func (q *RBlockingQueue) PollLastAndOfferFirstTo(
	ctx context.Context, dest string, timeout time.Duration,
) (any, error)

PollLastAndOfferFirstTo atomically moves the tail element to the head of dest, blocking up to timeout while this queue is empty.

func (*RBlockingQueue) PollWithTimeout

func (q *RBlockingQueue) PollWithTimeout(ctx context.Context, timeout time.Duration) (any, error)

PollWithTimeout blocks up to timeout for an element. Sub-second timeouts are rounded up to 1s (BLPOP granularity).

func (RBlockingQueue) RemainTTL

func (o RBlockingQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RBlockingQueue) Rename

func (o RBlockingQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBlockingQueue) Take

func (q *RBlockingQueue) Take(ctx context.Context) (any, error)

Take blocks until an element is available or ctx is cancelled.

func (RBlockingQueue) Touch

func (o RBlockingQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RBlockingQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBloomFilter

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

RBloomFilter is a distributed bloom filter, wire-compatible with Redisson: HighwayHash-128 with Redisson's fixed key over the codec-encoded element, bitmap stored at the raw name, config HASH at {name}:config.

func (*RBloomFilter) Add

func (f *RBloomFilter) Add(ctx context.Context, element any) (bool, error)

Add adds element, returning true when it was not present before.

func (*RBloomFilter) AddAll added in v0.2.13

func (f *RBloomFilter) AddAll(ctx context.Context, elements ...any) (int64, error)

AddAll adds elements and returns how many set at least one previously clear bit, matching Redisson's collection add count.

func (*RBloomFilter) ClearExpire

func (o *RBloomFilter) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RBloomFilter) Contains

func (f *RBloomFilter) Contains(ctx context.Context, element any) (bool, error)

Contains reports whether element may have been added (false = definitely not).

func (*RBloomFilter) ContainsAll added in v0.2.13

func (f *RBloomFilter) ContainsAll(ctx context.Context, elements ...any) (int64, error)

ContainsAll returns how many supplied elements may be present.

func (*RBloomFilter) Count

func (f *RBloomFilter) Count(ctx context.Context) (int64, error)

Count estimates the number of distinct elements added.

func (*RBloomFilter) Delete

func (f *RBloomFilter) Delete(ctx context.Context) error

Delete removes the bitmap and its config.

func (*RBloomFilter) Exists

func (o *RBloomFilter) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RBloomFilter) ExpectedInsertions

func (f *RBloomFilter) ExpectedInsertions(ctx context.Context) (int64, error)

ExpectedInsertions returns the configured expected insertions.

func (*RBloomFilter) Expire

func (o *RBloomFilter) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RBloomFilter) ExpireAt

func (o *RBloomFilter) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RBloomFilter) FalseProbability

func (f *RBloomFilter) FalseProbability(ctx context.Context) (float64, error)

FalseProbability returns the configured false positive probability.

func (*RBloomFilter) HashIterations

func (f *RBloomFilter) HashIterations(ctx context.Context) (int64, error)

HashIterations returns the number of hash functions used.

func (*RBloomFilter) Name

func (o *RBloomFilter) Name() string

Name returns the Redis key name of the object.

func (*RBloomFilter) RemainTTL

func (o *RBloomFilter) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RBloomFilter) Rename

func (o *RBloomFilter) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBloomFilter) Size

func (f *RBloomFilter) Size(ctx context.Context) (int64, error)

Size returns the bitmap size in bits.

func (*RBloomFilter) Touch

func (o *RBloomFilter) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RBloomFilter) TryInit

func (f *RBloomFilter) TryInit(ctx context.Context, expectedInsertions int64, falseProbability float64) (bool, error)

TryInit initializes the filter only when it has not been initialized yet.

func (o *RBloomFilter) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBloomFilterNative added in v0.2.13

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

RBloomFilterNative wraps Redis BF.* commands (RedissonBloomFilterNative). Elements are codec-encoded before insertion so JsonJacksonCodec clients match.

func (*RBloomFilterNative) Add added in v0.2.13

func (f *RBloomFilterNative) Add(ctx context.Context, element any) (bool, error)

Add inserts element; true when newly set.

func (*RBloomFilterNative) AddAll added in v0.2.13

func (f *RBloomFilterNative) AddAll(ctx context.Context, elements ...any) ([]bool, error)

AddAll inserts many elements; returns per-element "newly set" flags.

func (*RBloomFilterNative) Card added in v0.2.13

func (f *RBloomFilterNative) Card(ctx context.Context) (int64, error)

Card returns BF.CARD (approximate item count).

func (*RBloomFilterNative) ClearExpire added in v0.2.13

func (o *RBloomFilterNative) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RBloomFilterNative) Contains added in v0.2.13

func (f *RBloomFilterNative) Contains(ctx context.Context, element any) (bool, error)

Contains reports whether element may be present.

func (*RBloomFilterNative) ContainsAll added in v0.2.13

func (f *RBloomFilterNative) ContainsAll(ctx context.Context, elements ...any) ([]bool, error)

ContainsAll returns per-element membership guesses.

func (*RBloomFilterNative) Delete added in v0.2.13

func (o *RBloomFilterNative) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RBloomFilterNative) Exists added in v0.2.13

func (o *RBloomFilterNative) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RBloomFilterNative) Expire added in v0.2.13

func (o *RBloomFilterNative) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RBloomFilterNative) ExpireAt added in v0.2.13

func (o *RBloomFilterNative) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RBloomFilterNative) Name added in v0.2.13

func (o *RBloomFilterNative) Name() string

Name returns the Redis key name of the object.

func (*RBloomFilterNative) RemainTTL added in v0.2.13

func (o *RBloomFilterNative) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RBloomFilterNative) Rename added in v0.2.13

func (o *RBloomFilterNative) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBloomFilterNative) Touch added in v0.2.13

func (o *RBloomFilterNative) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RBloomFilterNative) TryInit added in v0.2.13

func (f *RBloomFilterNative) TryInit(ctx context.Context, errorRate float64, capacity int64) (bool, error)

TryInit reserves the filter (BF.RESERVE). Returns false when the key already exists.

func (o *RBloomFilterNative) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBoundedBlockingQueue added in v0.2.13

type RBoundedBlockingQueue struct {
	*RQueue
	// contains filtered or unexported fields
}

RBoundedBlockingQueue is Redisson's capacity-bounded FIFO queue. Values live in the queue LIST and available capacity in redisson_bqs:{name}.

func (*RBoundedBlockingQueue) Clear added in v0.2.13

Clear removes all queued values and restores their capacity.

func (RBoundedBlockingQueue) ClearExpire added in v0.2.13

func (o RBoundedBlockingQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RBoundedBlockingQueue) Delete added in v0.2.13

func (q *RBoundedBlockingQueue) Delete(ctx context.Context) error

Delete removes both the queue and its capacity companion.

func (RBoundedBlockingQueue) Exists added in v0.2.13

func (o RBoundedBlockingQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RBoundedBlockingQueue) Expire added in v0.2.13

func (o RBoundedBlockingQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RBoundedBlockingQueue) ExpireAt added in v0.2.13

func (o RBoundedBlockingQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RBoundedBlockingQueue) Name added in v0.2.13

func (o RBoundedBlockingQueue) Name() string

Name returns the Redis key name of the object.

func (*RBoundedBlockingQueue) Offer added in v0.2.13

func (q *RBoundedBlockingQueue) Offer(ctx context.Context, value any) (bool, error)

Offer adds value when capacity is available and returns false when full.

func (*RBoundedBlockingQueue) OfferWait added in v0.2.13

func (q *RBoundedBlockingQueue) OfferWait(
	ctx context.Context, value any, wait time.Duration,
) (bool, error)

OfferWait waits up to wait for capacity and then atomically appends value.

func (*RBoundedBlockingQueue) Poll added in v0.2.13

func (q *RBoundedBlockingQueue) Poll(ctx context.Context) (any, error)

Poll removes the head and releases one capacity permit.

func (*RBoundedBlockingQueue) PollInto added in v0.2.13

func (q *RBoundedBlockingQueue) PollInto(
	ctx context.Context, target any,
) (bool, error)

PollInto removes the head and decodes it into target.

func (*RBoundedBlockingQueue) Put added in v0.2.13

func (q *RBoundedBlockingQueue) Put(ctx context.Context, value any) error

Put blocks until value is appended or ctx is cancelled.

func (RBoundedBlockingQueue) RemainTTL added in v0.2.13

func (o RBoundedBlockingQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RBoundedBlockingQueue) RemainingCapacity added in v0.2.13

func (q *RBoundedBlockingQueue) RemainingCapacity(ctx context.Context) (int64, error)

RemainingCapacity returns the number of values that can be added.

func (RBoundedBlockingQueue) Rename added in v0.2.13

func (o RBoundedBlockingQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBoundedBlockingQueue) Take added in v0.2.13

func (q *RBoundedBlockingQueue) Take(
	ctx context.Context, timeout time.Duration,
) (any, error)

Take blocks until an element is available or timeout elapses, then releases one capacity permit. A zero timeout blocks until ctx is cancelled.

func (RBoundedBlockingQueue) Touch added in v0.2.13

func (o RBoundedBlockingQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RBoundedBlockingQueue) TrySetCapacity added in v0.2.13

func (q *RBoundedBlockingQueue) TrySetCapacity(
	ctx context.Context, capacity int64,
) (bool, error)

TrySetCapacity initializes capacity once. Later calls leave it unchanged.

func (o RBoundedBlockingQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBucket

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

RBucket is a distributed object holder backed by a Redis String. The whole value is codec (JSON) encoded, Redisson-compatible.

func (*RBucket) ClearExpire

func (o *RBucket) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RBucket) CompareAndDelete added in v0.2.13

func (b *RBucket) CompareAndDelete(ctx context.Context, expect any) (bool, error)

CompareAndDelete atomically deletes the value when it equals expect.

func (*RBucket) CompareAndSet

func (b *RBucket) CompareAndSet(ctx context.Context, expect, update any) (bool, error)

CompareAndSet atomically replaces the value when it equals expect. expect == nil means "key must be absent".

func (*RBucket) Delete

func (o *RBucket) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RBucket) Exists

func (o *RBucket) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RBucket) Expire

func (o *RBucket) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RBucket) ExpireAt

func (o *RBucket) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RBucket) Get

func (b *RBucket) Get(ctx context.Context) (any, error)

Get returns the value, or (nil, nil) when absent.

func (*RBucket) GetAndDelete

func (b *RBucket) GetAndDelete(ctx context.Context) (any, error)

GetAndDelete removes and returns the value.

func (*RBucket) GetAndSet

func (b *RBucket) GetAndSet(ctx context.Context, value any) (any, error)

GetAndSet replaces the value and returns the previous one.

func (*RBucket) GetAndSetWithTTL added in v0.2.13

func (b *RBucket) GetAndSetWithTTL(ctx context.Context, value any, ttl time.Duration) (any, error)

GetAndSetWithTTL replaces the value with a TTL and returns the previous one.

func (*RBucket) GetInto

func (b *RBucket) GetInto(ctx context.Context, target any) (bool, error)

GetInto decodes the value into the pointer target. Returns false when absent.

Example
package main

import (
	"context"
	"fmt"

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		fmt.Println("skip:", err)
		return
	}
	defer client.Close() //nolint:errcheck // example
	ctx := context.Background()
	_, _ = client.GetKeys().Delete(ctx, "demo:bucket")

	type cfg struct {
		Host string `json:"host"`
		Port int    `json:"port"`
	}
	b := client.GetBucket("demo:bucket")
	_ = b.Set(ctx, cfg{Host: "redis", Port: 6379})

	var out cfg
	ok, _ := b.GetInto(ctx, &out)
	fmt.Println(ok, out.Host, out.Port)
}
Output:
true redis 6379

func (*RBucket) Name

func (o *RBucket) Name() string

Name returns the Redis key name of the object.

func (*RBucket) RemainTTL

func (o *RBucket) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RBucket) Rename

func (o *RBucket) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RBucket) Set

func (b *RBucket) Set(ctx context.Context, value any) error

Set replaces the value.

func (*RBucket) SetAndKeepTTL added in v0.2.13

func (b *RBucket) SetAndKeepTTL(ctx context.Context, value any) error

SetAndKeepTTL replaces the value without changing its existing TTL.

func (*RBucket) SetIfExists

func (b *RBucket) SetIfExists(ctx context.Context, value any) (bool, error)

SetIfExists sets the value only when the key exists (SET XX).

func (*RBucket) SetIfExistsWithTTL added in v0.2.13

func (b *RBucket) SetIfExistsWithTTL(ctx context.Context, value any, ttl time.Duration) (bool, error)

SetIfExistsWithTTL sets the value with a TTL only when the key exists.

func (*RBucket) SetWithTTL

func (b *RBucket) SetWithTTL(ctx context.Context, value any, ttl time.Duration) error

SetWithTTL replaces the value with millisecond-precision TTL.

func (*RBucket) Size added in v0.2.13

func (b *RBucket) Size(ctx context.Context) (int64, error)

Size returns the encoded value length in bytes (STRLEN).

func (*RBucket) Touch

func (o *RBucket) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RBucket) TrySet

func (b *RBucket) TrySet(ctx context.Context, value any) (bool, error)

TrySet sets the value only when absent (SET NX).

func (*RBucket) TrySetWithTTL added in v0.2.13

func (b *RBucket) TrySetWithTTL(ctx context.Context, value any, ttl time.Duration) (bool, error)

TrySetWithTTL sets the value with a TTL only when absent (SET NX).

func (o *RBucket) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RBuckets

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

RBuckets performs batch operations across multiple bucket keys (MGET / MSET / MSETNX), values codec-encoded like RBucket.

func (*RBuckets) Get

func (b *RBuckets) Get(ctx context.Context, keys ...string) (map[string]any, error)

Get returns the existing values for the given keys (missing keys omitted).

func (*RBuckets) Set

func (b *RBuckets) Set(ctx context.Context, mapping map[string]any, ttl time.Duration) error

Set stores the mapping (MSET), optionally with a millisecond TTL applied to every key (pipelined PSETEX when ttl > 0).

func (*RBuckets) SetIfAllKeysAbsent added in v0.2.13

func (b *RBuckets) SetIfAllKeysAbsent(ctx context.Context, mapping map[string]any) (bool, error)

SetIfAllKeysAbsent stores all values only when no key exists.

func (*RBuckets) SetIfAllKeysExist added in v0.2.13

func (b *RBuckets) SetIfAllKeysExist(ctx context.Context, mapping map[string]any) (bool, error)

SetIfAllKeysExist stores all values only when every key already exists.

func (*RBuckets) TrySet

func (b *RBuckets) TrySet(ctx context.Context, mapping map[string]any) (bool, error)

TrySet stores the mapping only when NONE of the keys exist (MSETNX). Returns false when any key is already present.

type RCircularBuffer added in v0.2.13

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

RCircularBuffer is a Redis 8.8+ ARRAY ring with stable slot indexes (RedissonCircularBuffer). Distinct from LIST-backed RRingBuffer.

func (*RCircularBuffer) Add added in v0.2.13

func (b *RCircularBuffer) Add(ctx context.Context, value any) error

Add appends value (ARRING).

func (*RCircularBuffer) AddAll added in v0.2.13

func (b *RCircularBuffer) AddAll(ctx context.Context, values ...any) error

AddAll appends values.

func (*RCircularBuffer) Capacity added in v0.2.13

func (b *RCircularBuffer) Capacity(ctx context.Context) (int, error)

Capacity returns configured capacity (0 when unset).

func (*RCircularBuffer) Clear added in v0.2.13

func (b *RCircularBuffer) Clear(ctx context.Context) error

Clear deletes data and capacity metadata.

func (*RCircularBuffer) ClearExpire added in v0.2.13

func (o *RCircularBuffer) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RCircularBuffer) Delete added in v0.2.13

func (o *RCircularBuffer) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RCircularBuffer) Exists added in v0.2.13

func (o *RCircularBuffer) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RCircularBuffer) Expire added in v0.2.13

func (o *RCircularBuffer) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RCircularBuffer) ExpireAt added in v0.2.13

func (o *RCircularBuffer) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RCircularBuffer) Get added in v0.2.13

func (b *RCircularBuffer) Get(ctx context.Context, index int64) (any, error)

Get returns the value at absolute slot index.

func (*RCircularBuffer) Name added in v0.2.13

func (o *RCircularBuffer) Name() string

Name returns the Redis key name of the object.

func (*RCircularBuffer) ReadAll added in v0.2.13

func (b *RCircularBuffer) ReadAll(ctx context.Context) ([]any, error)

ReadAll returns values in temporal order via ARLASTITEMS when available, else falls back to scanning slots 0..capacity-1.

func (*RCircularBuffer) RemainTTL added in v0.2.13

func (o *RCircularBuffer) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RCircularBuffer) Rename added in v0.2.13

func (o *RCircularBuffer) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RCircularBuffer) SetCapacity added in v0.2.13

func (b *RCircularBuffer) SetCapacity(ctx context.Context, capacity int) error

SetCapacity overwrites capacity metadata (applied on next write).

func (*RCircularBuffer) Size added in v0.2.13

func (b *RCircularBuffer) Size(ctx context.Context) (int64, error)

Size returns ARLEN.

func (*RCircularBuffer) Touch added in v0.2.13

func (o *RCircularBuffer) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RCircularBuffer) TrySetCapacity added in v0.2.13

func (b *RCircularBuffer) TrySetCapacity(ctx context.Context, capacity int) (bool, error)

TrySetCapacity sets capacity only when unset.

func (o *RCircularBuffer) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RClientSideCaching added in v0.2.13

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

RClientSideCaching mirrors Redisson getClientSideCaching: factories return structures whose Redis traffic may be served from go-redis RESP3 CLIENT TRACKING cache.

Two construction paths:

  1. Config.ClientSideCaching at NewClient — CSC on the shared pool; GetClientSideCaching() is a zero-cost facade over that Client.
  2. GetClientSideCachingWithOptions — Redisson-shaped runtime scope: a dedicated redis.Client (Protocol 3 + ClientSideCacheConfig) owned by this facade; Destroy() closes it.

Still PARTIAL vs Java: no in-process read-proxy with evictionPolicy LRU/LFU/SOFT/WEAK over method arguments; go-redis owns the reply cache.

Topology: Config.ClientSideCaching and GetClientSideCachingWithOptions require ModeSingle + DB 0 + RESP3. Cluster/Sentinel return ErrClientSideCachingUnavailable for the owned-options path; shared Config CSC is ignored outside ModeSingle.

func (*RClientSideCaching) Destroy added in v0.2.13

func (csc *RClientSideCaching) Destroy() error

Destroy closes an owned CSC client (GetClientSideCachingWithOptions). Shared-pool facades are a no-op (pool lives with Client.Close).

func (*RClientSideCaching) Enabled added in v0.2.13

func (csc *RClientSideCaching) Enabled() bool

Enabled reports whether this facade's Client has CSC configured.

func (*RClientSideCaching) GetAtomicDouble added in v0.2.13

func (csc *RClientSideCaching) GetAtomicDouble(name string) *RAtomicDouble

GetAtomicDouble forwards to the CSC-backed Client.

func (*RClientSideCaching) GetAtomicLong added in v0.2.13

func (csc *RClientSideCaching) GetAtomicLong(name string) *RAtomicLong

GetAtomicLong forwards to the CSC-backed Client.

func (*RClientSideCaching) GetBitSet added in v0.2.13

func (csc *RClientSideCaching) GetBitSet(name string) *RBitSet

GetBitSet forwards to the CSC-backed Client.

func (*RClientSideCaching) GetBlockingDeque added in v0.2.13

func (csc *RClientSideCaching) GetBlockingDeque(name string) *RBlockingDeque

GetBlockingDeque forwards to the CSC-backed Client.

func (*RClientSideCaching) GetBlockingQueue added in v0.2.13

func (csc *RClientSideCaching) GetBlockingQueue(name string) *RBlockingQueue

GetBlockingQueue forwards to the CSC-backed Client.

func (*RClientSideCaching) GetBucket added in v0.2.13

func (csc *RClientSideCaching) GetBucket(name string) *RBucket

GetBucket forwards to the CSC-backed Client.

func (*RClientSideCaching) GetDeque added in v0.2.13

func (csc *RClientSideCaching) GetDeque(name string) *RDeque

GetDeque forwards to the CSC-backed Client.

func (*RClientSideCaching) GetGeo added in v0.2.13

func (csc *RClientSideCaching) GetGeo(name string) *RGeo

GetGeo forwards to the CSC-backed Client.

func (*RClientSideCaching) GetHyperLogLog added in v0.2.13

func (csc *RClientSideCaching) GetHyperLogLog(name string) *RHyperLogLog

GetHyperLogLog forwards to the CSC-backed Client.

func (*RClientSideCaching) GetList added in v0.2.13

func (csc *RClientSideCaching) GetList(name string) *RList

GetList forwards to the CSC-backed Client.

func (*RClientSideCaching) GetMap added in v0.2.13

func (csc *RClientSideCaching) GetMap(name string) *RMap

GetMap forwards to the CSC-backed Client.

func (*RClientSideCaching) GetQueue added in v0.2.13

func (csc *RClientSideCaching) GetQueue(name string) *RQueue

GetQueue forwards to the CSC-backed Client.

func (*RClientSideCaching) GetScoredSortedSet added in v0.2.13

func (csc *RClientSideCaching) GetScoredSortedSet(name string) *RScoredSortedSet

GetScoredSortedSet forwards to the CSC-backed Client.

func (*RClientSideCaching) GetSet added in v0.2.13

func (csc *RClientSideCaching) GetSet(name string) *RSet

GetSet forwards to the CSC-backed Client.

func (*RClientSideCaching) GetStream added in v0.2.13

func (csc *RClientSideCaching) GetStream(name string) *RStream

GetStream forwards to the CSC-backed Client.

func (*RClientSideCaching) Owned added in v0.2.13

func (csc *RClientSideCaching) Owned() bool

Owned reports whether Destroy closes a dedicated CSC client.

type RCountDownLatch

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

RCountDownLatch is a distributed countdown latch backed by a Redis String counter, Redisson wire-compatible: channel redisson_countdownlatch__channel__{name} receives message 0 when the count reaches zero.

func (*RCountDownLatch) Await

func (l *RCountDownLatch) Await(ctx context.Context, timeout time.Duration) (bool, error)

Await blocks until the count reaches zero. A non-positive timeout waits indefinitely. Returns false on timeout.

func (*RCountDownLatch) ClearExpire

func (o *RCountDownLatch) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RCountDownLatch) CountDown

func (l *RCountDownLatch) CountDown(ctx context.Context) error

CountDown decrements the count, deleting the key at zero and publishing the wake-up message.

func (*RCountDownLatch) Delete

func (o *RCountDownLatch) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RCountDownLatch) Exists

func (o *RCountDownLatch) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RCountDownLatch) Expire

func (o *RCountDownLatch) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RCountDownLatch) ExpireAt

func (o *RCountDownLatch) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RCountDownLatch) GetCount

func (l *RCountDownLatch) GetCount(ctx context.Context) (int64, error)

GetCount returns the current count (0 when the latch is open/absent).

func (*RCountDownLatch) Name

func (o *RCountDownLatch) Name() string

Name returns the Redis key name of the object.

func (*RCountDownLatch) RemainTTL

func (o *RCountDownLatch) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RCountDownLatch) Rename

func (o *RCountDownLatch) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RCountDownLatch) Touch

func (o *RCountDownLatch) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RCountDownLatch) TrySetCount

func (l *RCountDownLatch) TrySetCount(ctx context.Context, count int64) (bool, error)

TrySetCount initializes the latch count only when it does not exist.

func (o *RCountDownLatch) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RCuckooFilter added in v0.2.13

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

RCuckooFilter wraps Redis CF.* commands.

func (*RCuckooFilter) Add added in v0.2.13

func (f *RCuckooFilter) Add(ctx context.Context, element any) (bool, error)

Add inserts element.

func (*RCuckooFilter) AddIfAbsent added in v0.2.13

func (f *RCuckooFilter) AddIfAbsent(ctx context.Context, element any) (bool, error)

AddIfAbsent inserts only when absent (CF.ADDNX).

func (*RCuckooFilter) ClearExpire added in v0.2.13

func (o *RCuckooFilter) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RCuckooFilter) Contains added in v0.2.13

func (f *RCuckooFilter) Contains(ctx context.Context, element any) (bool, error)

Contains reports possible membership.

func (*RCuckooFilter) Count added in v0.2.13

func (f *RCuckooFilter) Count(ctx context.Context, element any) (int64, error)

Count returns CF.COUNT for element.

func (*RCuckooFilter) Delete added in v0.2.13

func (f *RCuckooFilter) Delete(ctx context.Context, element any) (bool, error)

Delete removes one occurrence of element.

func (*RCuckooFilter) Exists added in v0.2.13

func (o *RCuckooFilter) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RCuckooFilter) Expire added in v0.2.13

func (o *RCuckooFilter) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RCuckooFilter) ExpireAt added in v0.2.13

func (o *RCuckooFilter) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RCuckooFilter) Name added in v0.2.13

func (o *RCuckooFilter) Name() string

Name returns the Redis key name of the object.

func (*RCuckooFilter) RemainTTL added in v0.2.13

func (o *RCuckooFilter) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RCuckooFilter) Rename added in v0.2.13

func (o *RCuckooFilter) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RCuckooFilter) Touch added in v0.2.13

func (o *RCuckooFilter) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RCuckooFilter) TryInit added in v0.2.13

func (f *RCuckooFilter) TryInit(ctx context.Context, capacity int64) (bool, error)

TryInit reserves capacity (CF.RESERVE).

func (o *RCuckooFilter) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RDelayedQueue

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

RDelayedQueue offers delayed delivery, wire-compatible with Redisson's RedissonDelayedQueue (verified against 4.6.1):

ZSET redisson_delay_queue_timeout:{name}  deadline index:
      member = struct.pack('Bc0Lc0', randomIdLen=8, randomId, encLen, encodedValue)
LIST redisson_delay_queue:{name}          the same packed members (ordering +
      lrem support); expired members are unpacked and RPUSHed onto {name}
LIST {name}                                the target queue consumers poll
PUB  redisson_delay_queue_channel:{name}   wake-up channel (head startTime)

A background goroutine migrates expired members (Redis TIME clock).

func (*RDelayedQueue) Clear added in v0.2.13

func (q *RDelayedQueue) Clear(ctx context.Context) error

Clear removes pending delayed elements without clearing the target queue.

func (*RDelayedQueue) ClearExpire

func (o *RDelayedQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RDelayedQueue) Contains added in v0.2.13

func (q *RDelayedQueue) Contains(ctx context.Context, element any) (bool, error)

Contains reports whether a pending delayed element equals element.

func (*RDelayedQueue) DelayedSize

func (q *RDelayedQueue) DelayedSize(ctx context.Context) (int64, error)

DelayedSize returns the number of elements still waiting.

func (*RDelayedQueue) Delete

func (q *RDelayedQueue) Delete(ctx context.Context) error

Delete removes the target queue and both internal keys.

func (*RDelayedQueue) Exists

func (o *RDelayedQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RDelayedQueue) Expire

func (o *RDelayedQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RDelayedQueue) ExpireAt

func (o *RDelayedQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RDelayedQueue) MigrateExpired

func (q *RDelayedQueue) MigrateExpired(ctx context.Context) (int64, error)

MigrateExpired moves all due members onto the target queue.

func (*RDelayedQueue) Name

func (o *RDelayedQueue) Name() string

Name returns the Redis key name of the object.

func (*RDelayedQueue) Offer

func (q *RDelayedQueue) Offer(ctx context.Context, element any, delay time.Duration) error

Offer adds element with the given delay.

func (*RDelayedQueue) Peek

func (q *RDelayedQueue) Peek(ctx context.Context) (any, error)

Peek returns the head of the ready queue without removing it.

func (*RDelayedQueue) Poll

func (q *RDelayedQueue) Poll(ctx context.Context) (any, error)

Poll removes and returns the head of the ready queue (nil when empty).

func (*RDelayedQueue) ReadAll added in v0.2.13

func (q *RDelayedQueue) ReadAll(ctx context.Context) ([]any, error)

ReadAll returns all pending delayed elements in insertion order.

func (*RDelayedQueue) ReadySize

func (q *RDelayedQueue) ReadySize(ctx context.Context) (int64, error)

ReadySize returns the number of immediately available elements.

func (*RDelayedQueue) RemainTTL

func (o *RDelayedQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RDelayedQueue) Remove added in v0.2.13

func (q *RDelayedQueue) Remove(ctx context.Context, element any) (bool, error)

Remove deletes one matching pending delayed element from both indexes.

func (*RDelayedQueue) Rename

func (o *RDelayedQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RDelayedQueue) Size

func (q *RDelayedQueue) Size(ctx context.Context) (int64, error)

Size returns ready + delayed counts.

func (*RDelayedQueue) Touch

func (o *RDelayedQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RDelayedQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RDeque

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

RDeque is a distributed double-ended queue backed by a Redis List.

func (*RDeque) AddFirst

func (d *RDeque) AddFirst(ctx context.Context, values ...any) error

AddFirst pushes values onto the head (LPUSH).

func (*RDeque) AddFirstIfExists added in v0.2.13

func (d *RDeque) AddFirstIfExists(
	ctx context.Context, values ...any,
) (int64, error)

AddFirstIfExists pushes values at the head only when the deque exists and returns the resulting length.

func (*RDeque) AddLast

func (d *RDeque) AddLast(ctx context.Context, values ...any) error

AddLast pushes values onto the tail (RPUSH).

func (*RDeque) AddLastIfExists added in v0.2.13

func (d *RDeque) AddLastIfExists(
	ctx context.Context, values ...any,
) (int64, error)

AddLastIfExists pushes values at the tail only when the deque exists and returns the resulting length.

func (*RDeque) Clear

func (d *RDeque) Clear(ctx context.Context) error

Clear removes all elements.

func (*RDeque) ClearExpire

func (o *RDeque) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RDeque) Delete

func (o *RDeque) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RDeque) Exists

func (o *RDeque) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RDeque) Expire

func (o *RDeque) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RDeque) ExpireAt

func (o *RDeque) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RDeque) Name

func (o *RDeque) Name() string

Name returns the Redis key name of the object.

func (*RDeque) PeekFirst

func (d *RDeque) PeekFirst(ctx context.Context) (any, error)

PeekFirst returns the head element without removing it.

func (*RDeque) PeekFirstInto added in v0.2.13

func (d *RDeque) PeekFirstInto(ctx context.Context, target any) (bool, error)

PeekFirstInto decodes the head into target without removing it. Returns false when the deque is empty.

func (*RDeque) PeekLast

func (d *RDeque) PeekLast(ctx context.Context) (any, error)

PeekLast returns the tail element without removing it.

func (*RDeque) PeekLastInto added in v0.2.13

func (d *RDeque) PeekLastInto(ctx context.Context, target any) (bool, error)

PeekLastInto decodes the tail into target without removing it. Returns false when the deque is empty.

func (*RDeque) ReadAll added in v0.2.13

func (d *RDeque) ReadAll(ctx context.Context) ([]any, error)

ReadAll returns all elements from head to tail without removing them.

func (*RDeque) RemainTTL

func (o *RDeque) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RDeque) RemoveFirst

func (d *RDeque) RemoveFirst(ctx context.Context) (any, error)

RemoveFirst pops the head element. Returns (nil, nil) when empty.

func (*RDeque) RemoveFirstInto added in v0.2.13

func (d *RDeque) RemoveFirstInto(ctx context.Context, target any) (bool, error)

RemoveFirstInto pops the head and decodes it into target. Returns false when the deque is empty.

func (*RDeque) RemoveLast

func (d *RDeque) RemoveLast(ctx context.Context) (any, error)

RemoveLast pops the tail element. Returns (nil, nil) when empty.

func (*RDeque) RemoveLastInto added in v0.2.13

func (d *RDeque) RemoveLastInto(ctx context.Context, target any) (bool, error)

RemoveLastInto pops the tail and decodes it into target. Returns false when the deque is empty.

func (*RDeque) Rename

func (o *RDeque) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RDeque) Size

func (d *RDeque) Size(ctx context.Context) (int64, error)

Size returns the number of elements.

func (*RDeque) Touch

func (o *RDeque) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RDeque) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RDoubleAdder added in v0.2.8

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

RDoubleAdder is the double variant of RLongAdder.

func (*RDoubleAdder) Add added in v0.2.8

func (a *RDoubleAdder) Add(x float64)

Add adds x to the local buffer.

func (*RDoubleAdder) Decrement added in v0.2.8

func (a *RDoubleAdder) Decrement()

Decrement subtracts 1.

func (*RDoubleAdder) Destroy added in v0.2.8

func (a *RDoubleAdder) Destroy()

Destroy unsubscribes this instance.

func (*RDoubleAdder) Increment added in v0.2.8

func (a *RDoubleAdder) Increment()

Increment adds 1.

func (*RDoubleAdder) Reset added in v0.2.8

func (a *RDoubleAdder) Reset(ctx context.Context) error

Reset clears every live instance's local buffer.

func (*RDoubleAdder) Sum added in v0.2.8

func (a *RDoubleAdder) Sum(ctx context.Context) (float64, error)

Sum flushes every live instance's buffer and returns the total.

type RFairLock added in v0.2.13

type RFairLock struct {
	*RLock
	// contains filtered or unexported fields
}

RFairLock is Redisson's FIFO, re-entrant distributed lock. The lock HASH uses the raw name; waiters use redisson_lock_queue:{name} (LIST) and redisson_lock_timeout:{name} (ZSET).

func (RFairLock) ClearExpire added in v0.2.13

func (o RFairLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RFairLock) Delete added in v0.2.13

func (o RFairLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (RFairLock) Exists added in v0.2.13

func (o RFairLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RFairLock) Expire added in v0.2.13

func (o RFairLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RFairLock) ExpireAt added in v0.2.13

func (o RFairLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RFairLock) ForceUnlock added in v0.2.13

func (l *RFairLock) ForceUnlock(ctx context.Context) (bool, error)

ForceUnlock deletes the lock regardless of owner and wakes the queue head.

func (*RFairLock) HoldCount added in v0.2.13

func (l *RFairLock) HoldCount(ctx context.Context, clientID string) (int64, error)

HoldCount returns the re-entrancy count held by clientID.

func (*RFairLock) IsHeldBy added in v0.2.13

func (l *RFairLock) IsHeldBy(ctx context.Context, clientID string) (bool, error)

IsHeldBy reports whether clientID holds the lock.

func (*RFairLock) IsLocked added in v0.2.13

func (l *RFairLock) IsLocked(ctx context.Context) (bool, error)

IsLocked reports whether anyone holds the lock.

func (*RFairLock) Lock added in v0.2.13

func (l *RFairLock) Lock(ctx context.Context, clientID string, ttl time.Duration) error

Lock acquires the lock in FIFO order, blocking until success or ctx cancellation.

func (RFairLock) Name added in v0.2.13

func (o RFairLock) Name() string

Name returns the Redis key name of the object.

func (RFairLock) RemainTTL added in v0.2.13

func (o RFairLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RFairLock) RemainTimeToLive added in v0.2.13

func (l *RFairLock) RemainTimeToLive(ctx context.Context) (time.Duration, error)

RemainTimeToLive returns the remaining lock lease.

func (RFairLock) Rename added in v0.2.13

func (o RFairLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RFairLock) Touch added in v0.2.13

func (o RFairLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RFairLock) TryLock added in v0.2.13

func (l *RFairLock) TryLock(ctx context.Context, clientID string, ttl time.Duration) (bool, error)

TryLock attempts one acquisition without joining the wait queue.

func (*RFairLock) TryLockWait added in v0.2.13

func (l *RFairLock) TryLockWait(
	ctx context.Context, clientID string, wait, ttl time.Duration,
) (bool, error)

TryLockWait joins the FIFO queue and waits up to wait for the lock.

func (o RFairLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RFairLock) Unlock added in v0.2.13

func (l *RFairLock) Unlock(ctx context.Context, clientID string) error

Unlock releases one hold and wakes only the current queue head.

type RFencedLock added in v0.2.10

type RFencedLock struct {
	*RLock
	// contains filtered or unexported fields
}

RFencedLock is a re-entrant distributed lock whose every acquisition increments a fencing token, wire-compatible with Redisson's RedissonFencedLock:

HASH {name}                       holder counts (same as RLock)
STRING redisson_lock_token:{name} monotonic fencing token (INCR per
                                 acquisition, INCLUDING re-entries)

The guarded service should reject operations carrying a token smaller than the last seen one (the classic fencing answer to lock expiry).

func (RFencedLock) ClearExpire added in v0.2.10

func (o RFencedLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RFencedLock) Delete added in v0.2.10

func (o RFencedLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (RFencedLock) Exists added in v0.2.10

func (o RFencedLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RFencedLock) Expire added in v0.2.10

func (o RFencedLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RFencedLock) ExpireAt added in v0.2.10

func (o RFencedLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RFencedLock) GetToken added in v0.2.10

func (l *RFencedLock) GetToken(ctx context.Context) (int64, error)

GetToken returns the current fencing token (0 when never acquired).

func (*RFencedLock) LockAndGetToken added in v0.2.10

func (l *RFencedLock) LockAndGetToken(ctx context.Context, clientID string, ttl time.Duration) (int64, error)

LockAndGetToken blocks until acquired, returning the fencing token.

func (RFencedLock) Name added in v0.2.10

func (o RFencedLock) Name() string

Name returns the Redis key name of the object.

func (RFencedLock) RemainTTL added in v0.2.10

func (o RFencedLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RFencedLock) Rename added in v0.2.10

func (o RFencedLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RFencedLock) Touch added in v0.2.10

func (o RFencedLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RFencedLock) TryLockAndGetToken added in v0.2.10

func (l *RFencedLock) TryLockAndGetToken(ctx context.Context, clientID string, ttl time.Duration) (int64, error)

TryLockAndGetToken attempts one acquisition, returning the new fencing token (0 when the lock is held by someone else).

func (o RFencedLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RFunction added in v0.2.12

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

RFunction manages Redis functions (FUNCTION LOAD / FCALL), mirroring Redisson's RFunction. Redis-native - wire-safe across languages.

func (*RFunction) Call added in v0.2.12

func (f *RFunction) Call(ctx context.Context, function string, keys []string, args ...any) (any, error)

Call invokes a registered function (FCALL). keys are the function's key arguments, args the remaining arguments.

func (*RFunction) CallReadOnly added in v0.2.12

func (f *RFunction) CallReadOnly(ctx context.Context, function string, keys []string, args ...any) (any, error)

CallReadOnly invokes via FCALL_RO (read-only replica routing).

func (*RFunction) Delete added in v0.2.12

func (f *RFunction) Delete(ctx context.Context, library string) error

Delete removes a library (FUNCTION DELETE).

func (*RFunction) Flush added in v0.2.12

func (f *RFunction) Flush(ctx context.Context) error

Flush removes every library (FUNCTION FLUSH).

func (*RFunction) List added in v0.2.12

func (f *RFunction) List(ctx context.Context, withCode bool) ([]redis.Library, error)

List returns registered libraries (FUNCTION LIST, with code).

func (*RFunction) Load added in v0.2.12

func (f *RFunction) Load(ctx context.Context, code string) error

Load registers a library (FUNCTION LOAD, replace=true).

type RGcra added in v0.2.13

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

RGcra is Redis GCRA rate limiting (RedissonGcra). Uses the GCRA command when available (Redis 8+); tests skip when the server lacks it.

func (*RGcra) ClearExpire added in v0.2.13

func (o *RGcra) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RGcra) Delete added in v0.2.13

func (o *RGcra) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RGcra) Exists added in v0.2.13

func (o *RGcra) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RGcra) Expire added in v0.2.13

func (o *RGcra) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RGcra) ExpireAt added in v0.2.13

func (o *RGcra) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RGcra) Name added in v0.2.13

func (o *RGcra) Name() string

Name returns the Redis key name of the object.

func (*RGcra) RemainTTL added in v0.2.13

func (o *RGcra) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RGcra) Rename added in v0.2.13

func (o *RGcra) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RGcra) Touch added in v0.2.13

func (o *RGcra) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RGcra) TryAcquire added in v0.2.13

func (g *RGcra) TryAcquire(ctx context.Context, maxBurst, tokensPerPeriod int64, period time.Duration, tokens int64) (*GcraResult, error)

TryAcquire attempts to take tokens under GCRA.

func (o *RGcra) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RGeo added in v0.2.2

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

RGeo is a distributed geospatial index (Redis GEO / sorted-set backed). Members are codec-encoded (Redisson JsonJacksonCodec interop); searches use GEOSEARCH (GEORADIUS is removed in Redis 8).

func (*RGeo) Add added in v0.2.2

func (g *RGeo) Add(ctx context.Context, longitude, latitude float64, member any) (bool, error)

Add stores a member at lon/lat. Returns true when newly added.

func (*RGeo) AddIfExists added in v0.2.13

func (g *RGeo) AddIfExists(ctx context.Context, longitude, latitude float64, member any) (bool, error)

AddIfExists updates a member only when it already exists (GEOADD XX).

func (*RGeo) AddMany added in v0.2.13

func (g *RGeo) AddMany(ctx context.Context, locations []GeoLocation) (int64, error)

AddMany stores all locations and returns the number of newly added members.

func (*RGeo) ClearExpire added in v0.2.2

func (o *RGeo) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RGeo) Delete added in v0.2.2

func (o *RGeo) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RGeo) Dist added in v0.2.2

func (g *RGeo) Dist(ctx context.Context, member1, member2 any, unit string) (float64, error)

Dist returns the distance between two members (-1 when either missing).

func (*RGeo) Exists added in v0.2.2

func (o *RGeo) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RGeo) Expire added in v0.2.2

func (o *RGeo) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RGeo) ExpireAt added in v0.2.2

func (o *RGeo) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RGeo) Hash added in v0.2.2

func (g *RGeo) Hash(ctx context.Context, member any) (string, error)

Hash returns the geohash of a member ("" when missing).

func (*RGeo) HashMany added in v0.2.13

func (g *RGeo) HashMany(ctx context.Context, members ...any) ([]string, error)

HashMany returns geohashes aligned with members; missing members yield "".

func (*RGeo) Name added in v0.2.2

func (o *RGeo) Name() string

Name returns the Redis key name of the object.

func (*RGeo) Pos added in v0.2.2

func (g *RGeo) Pos(ctx context.Context, member any) ([]float64, error)

Pos returns [lon, lat] of a member (nil when missing).

func (*RGeo) PosMany added in v0.2.13

func (g *RGeo) PosMany(ctx context.Context, members ...any) ([][]float64, error)

PosMany returns positions aligned with members; missing members yield nil.

func (*RGeo) RemainTTL added in v0.2.2

func (o *RGeo) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RGeo) Remove added in v0.2.2

func (g *RGeo) Remove(ctx context.Context, member any) error

Remove deletes a member.

func (*RGeo) Rename added in v0.2.2

func (o *RGeo) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RGeo) Search added in v0.2.2

func (g *RGeo) Search(ctx context.Context, longitude, latitude, radius float64, unit string,
	withDist, asc bool) ([]GeoEntry, error)

Search returns members within radius of lon/lat (GEOSEARCH), optionally with distances sorted ascending. WITHCOORD is always requested (go-redis cannot parse the reply shape without any WITH* flag).

func (*RGeo) SearchByMember added in v0.2.2

func (g *RGeo) SearchByMember(ctx context.Context, member any, radius float64, unit string,
	withDist, asc bool) ([]GeoEntry, error)

SearchByMember returns members within radius of an existing member.

func (*RGeo) Size added in v0.2.2

func (g *RGeo) Size(ctx context.Context) (int64, error)

Size returns the number of members.

func (*RGeo) StoreSearchTo added in v0.2.13

func (g *RGeo) StoreSearchTo(ctx context.Context, dest string, longitude, latitude, radius float64,
	unit string, count int) (int64, error)

StoreSearchTo stores members within radius in dest and returns the count.

func (*RGeo) Touch added in v0.2.2

func (o *RGeo) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RGeo) TryAdd added in v0.2.2

func (g *RGeo) TryAdd(ctx context.Context, longitude, latitude float64, member any) (bool, error)
func (o *RGeo) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RHyperLogLog added in v0.2.2

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

RHyperLogLog estimates cardinality (Redis PFADD/PFCOUNT/PFMERGE). Members are codec-encoded; the sketch itself is Redis-native so cross-language interop is automatic.

func (*RHyperLogLog) Add added in v0.2.2

func (h *RHyperLogLog) Add(ctx context.Context, element any) (bool, error)

Add adds an element. Returns true when the register was updated.

func (*RHyperLogLog) AddAll added in v0.2.2

func (h *RHyperLogLog) AddAll(ctx context.Context, elements ...any) (bool, error)

AddAll adds multiple elements. Returns true when any register changed.

func (*RHyperLogLog) ClearExpire added in v0.2.2

func (o *RHyperLogLog) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RHyperLogLog) Count added in v0.2.2

func (h *RHyperLogLog) Count(ctx context.Context) (int64, error)

Count returns the estimated cardinality.

func (*RHyperLogLog) CountWith added in v0.2.2

func (h *RHyperLogLog) CountWith(ctx context.Context, others ...string) (int64, error)

CountWith returns the union cardinality with other HLLs.

func (*RHyperLogLog) Delete added in v0.2.2

func (o *RHyperLogLog) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RHyperLogLog) Exists added in v0.2.2

func (o *RHyperLogLog) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RHyperLogLog) Expire added in v0.2.2

func (o *RHyperLogLog) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RHyperLogLog) ExpireAt added in v0.2.2

func (o *RHyperLogLog) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RHyperLogLog) MergeInto added in v0.2.2

func (h *RHyperLogLog) MergeInto(ctx context.Context, dest string, others ...string) error

MergeInto merges this HLL (and others) into a destination.

func (*RHyperLogLog) MergeWith added in v0.2.2

func (h *RHyperLogLog) MergeWith(ctx context.Context, others ...string) error

MergeWith merges the other HLLs into this one.

func (*RHyperLogLog) Name added in v0.2.2

func (o *RHyperLogLog) Name() string

Name returns the Redis key name of the object.

func (*RHyperLogLog) RemainTTL added in v0.2.2

func (o *RHyperLogLog) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RHyperLogLog) Rename added in v0.2.2

func (o *RHyperLogLog) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RHyperLogLog) Touch added in v0.2.2

func (o *RHyperLogLog) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RHyperLogLog) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RIdGenerator

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

RIdGenerator is a distributed id generator: each process caches a range of ids (allocation size persisted at {name}:allocation, Redisson-compatible) to keep Redis round-trips low.

func (*RIdGenerator) ClearExpire

func (o *RIdGenerator) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RIdGenerator) Delete

func (g *RIdGenerator) Delete(ctx context.Context) error

Delete removes both the counter and its allocation-size companion.

func (*RIdGenerator) Exists

func (o *RIdGenerator) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RIdGenerator) Expire

func (o *RIdGenerator) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RIdGenerator) ExpireAt

func (o *RIdGenerator) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RIdGenerator) Name

func (o *RIdGenerator) Name() string

Name returns the Redis key name of the object.

func (*RIdGenerator) NextID

func (g *RIdGenerator) NextID(ctx context.Context) (int64, error)

NextID returns the next unique id (unique, not strictly monotonic).

func (*RIdGenerator) NextIDs

func (g *RIdGenerator) NextIDs(ctx context.Context, count int) ([]int64, error)

NextIDs allocates count ids in batches.

func (*RIdGenerator) RemainTTL

func (o *RIdGenerator) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RIdGenerator) Rename

func (o *RIdGenerator) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RIdGenerator) Touch

func (o *RIdGenerator) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RIdGenerator) TryInit

func (g *RIdGenerator) TryInit(ctx context.Context, value, allocationSize int64) (bool, error)

TryInit sets the initial value and allocation size once.

func (o *RIdGenerator) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RJsonBucket added in v0.2.13

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

RJsonBucket stores a JSON document via RedisJSON (JSON.SET/GET/…). Requires the RedisJSON module; tests skip when commands are unavailable.

func (*RJsonBucket) ArrayAppend added in v0.2.13

func (b *RJsonBucket) ArrayAppend(ctx context.Context, path string, values ...any) (int64, error)

ArrayAppend appends values to the array at path.

func (*RJsonBucket) ArrayLen added in v0.2.13

func (b *RJsonBucket) ArrayLen(ctx context.Context, path string) (int64, error)

ArrayLen returns the array length at path.

func (*RJsonBucket) ArrayPop added in v0.2.13

func (b *RJsonBucket) ArrayPop(ctx context.Context, path string, index int64) (any, error)

ArrayPop pops an element from the array at path.

func (*RJsonBucket) ClearExpire added in v0.2.13

func (o *RJsonBucket) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RJsonBucket) Delete added in v0.2.13

func (o *RJsonBucket) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RJsonBucket) DeletePath added in v0.2.13

func (b *RJsonBucket) DeletePath(ctx context.Context, path string) (int64, error)

DeletePath deletes path (or the whole key when path is empty/$ with JSON.DEL).

func (*RJsonBucket) Exists added in v0.2.13

func (o *RJsonBucket) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RJsonBucket) Expire added in v0.2.13

func (o *RJsonBucket) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RJsonBucket) ExpireAt added in v0.2.13

func (o *RJsonBucket) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RJsonBucket) Get added in v0.2.13

func (b *RJsonBucket) Get(ctx context.Context) (any, error)

Get returns the document root.

func (*RJsonBucket) GetPath added in v0.2.13

func (b *RJsonBucket) GetPath(ctx context.Context, path string) (any, error)

GetPath returns the value at path (JSONPath).

func (*RJsonBucket) Name added in v0.2.13

func (o *RJsonBucket) Name() string

Name returns the Redis key name of the object.

func (*RJsonBucket) RemainTTL added in v0.2.13

func (o *RJsonBucket) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RJsonBucket) Rename added in v0.2.13

func (o *RJsonBucket) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RJsonBucket) Set added in v0.2.13

func (b *RJsonBucket) Set(ctx context.Context, value any) error

Set stores value at the document root ($).

func (*RJsonBucket) SetPath added in v0.2.13

func (b *RJsonBucket) SetPath(ctx context.Context, path string, value any) error

SetPath writes value at path.

func (*RJsonBucket) SetPathNX added in v0.2.13

func (b *RJsonBucket) SetPathNX(ctx context.Context, path string, value any) (bool, error)

SetPathNX sets path only when absent.

func (*RJsonBucket) Touch added in v0.2.13

func (o *RJsonBucket) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RJsonBucket) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RJsonBuckets added in v0.2.13

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

RJsonBuckets provides mass get/set for JSON buckets.

func (*RJsonBuckets) Get added in v0.2.13

func (b *RJsonBuckets) Get(ctx context.Context, names ...string) (map[string]any, error)

Get loads documents by name; missing keys are omitted.

func (*RJsonBuckets) Set added in v0.2.13

func (b *RJsonBuckets) Set(ctx context.Context, values map[string]any) error

Set stores each name→value document at root.

type RKeys

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

RKeys provides keyspace management (SCAN iteration, pattern deletion, counts), mirroring Redisson's RKeys.

func (*RKeys) ClearExpire added in v0.2.13

func (k *RKeys) ClearExpire(ctx context.Context, key string) (bool, error)

ClearExpire removes a key's TTL.

func (*RKeys) Copy

func (k *RKeys) Copy(ctx context.Context, key, newKey string, replace bool) (bool, error)

Copy copies a key (Redis COPY).

func (*RKeys) Count

func (k *RKeys) Count(ctx context.Context) (int64, error)

Count returns the total number of keys in the database (DBSIZE).

func (*RKeys) CountExists

func (k *RKeys) CountExists(ctx context.Context, names ...string) (int64, error)

CountExists returns how many of the given keys exist.

func (*RKeys) Delete

func (k *RKeys) Delete(ctx context.Context, keys ...string) (int64, error)

Delete removes keys, returning the count removed.

func (*RKeys) DeleteByPattern

func (k *RKeys) DeleteByPattern(ctx context.Context, pattern string) (int64, error)

DeleteByPattern removes every key matching a glob pattern (SCAN + DEL batches), returning the count removed.

func (*RKeys) Expire added in v0.2.13

func (k *RKeys) Expire(ctx context.Context, key string, ttl time.Duration) (bool, error)

Expire sets a TTL on a key.

func (*RKeys) ExpireAt added in v0.2.13

func (k *RKeys) ExpireAt(ctx context.Context, key string, at time.Time) (bool, error)

ExpireAt sets an absolute expiry time on a key.

func (*RKeys) FlushAll added in v0.2.13

func (k *RKeys) FlushAll(ctx context.Context) error

FlushAll empties every database. In cluster mode it runs on every master.

func (*RKeys) FlushDB

func (k *RKeys) FlushDB(ctx context.Context) error

FlushDB empties the current database.

func (*RKeys) ForEachKey

func (k *RKeys) ForEachKey(ctx context.Context, pattern string, fn func(key string) error) error

ForEachKey iterates every key (optionally matching a glob pattern) via SCAN, invoking fn for each. SCAN is incremental and safe for live use; fn returning an error stops the iteration and propagates it.

func (*RKeys) Keys

func (k *RKeys) Keys(ctx context.Context, pattern string) ([]string, error)

Keys collects up to the first 10000 keys matching a pattern.

func (*RKeys) Migrate added in v0.2.13

func (k *RKeys) Migrate(
	ctx context.Context,
	key, host string,
	port, db int,
	timeout time.Duration,
) error

Migrate atomically moves key to another Redis instance.

func (*RKeys) Move added in v0.2.13

func (k *RKeys) Move(ctx context.Context, key string, db int) (bool, error)

Move moves a key to another Redis database.

func (*RKeys) RandomKey

func (k *RKeys) RandomKey(ctx context.Context) (string, error)

RandomKey returns a random key ("" when the db is empty).

func (*RKeys) RemainTTL added in v0.2.13

func (k *RKeys) RemainTTL(ctx context.Context, key string) (time.Duration, error)

RemainTTL returns the remaining TTL with millisecond precision (-1 no expiry, -2 missing).

func (*RKeys) Rename added in v0.2.13

func (k *RKeys) Rename(ctx context.Context, key, newKey string) error

Rename renames a key.

func (*RKeys) RenameNX added in v0.2.13

func (k *RKeys) RenameNX(ctx context.Context, key, newKey string) (bool, error)

RenameNX renames a key only when newKey does not exist.

func (*RKeys) SwapDB added in v0.2.13

func (k *RKeys) SwapDB(ctx context.Context, db1, db2 int) error

SwapDB swaps two databases on the connected Redis server.

func (*RKeys) Touch added in v0.2.13

func (k *RKeys) Touch(ctx context.Context, keys ...string) (int64, error)

Touch updates the last-access time of keys.

func (*RKeys) Type

func (k *RKeys) Type(ctx context.Context, key string) (string, error)

Type returns the type of a key ("none" when missing).

func (k *RKeys) Unlink(ctx context.Context, keys ...string) (int64, error)

Unlink removes keys asynchronously, returning the count unlinked.

func (*RKeys) UnlinkByPattern

func (k *RKeys) UnlinkByPattern(ctx context.Context, pattern string) (int64, error)

UnlinkByPattern is DeleteByPattern with async UNLINK.

type RLexSortedSet

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

RLexSortedSet is a lexicographically sorted set. Members are stored RAW (not codec-encoded), matching Redisson's RLexSortedSet which bypasses the codec so lexicographic ordering uses the natural byte form (redi.py verified this Redisson special case).

func (*RLexSortedSet) Add

func (s *RLexSortedSet) Add(ctx context.Context, element string) (bool, error)

Add adds a raw string member (score 0).

func (*RLexSortedSet) Clear

func (s *RLexSortedSet) Clear(ctx context.Context) error

Clear removes the set.

func (*RLexSortedSet) ClearExpire

func (o *RLexSortedSet) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RLexSortedSet) Contains

func (s *RLexSortedSet) Contains(ctx context.Context, element string) (bool, error)

Contains reports membership.

func (*RLexSortedSet) CountHead

func (s *RLexSortedSet) CountHead(ctx context.Context, toValue string) (int64, error)

CountHead counts members before toValue (open range).

func (*RLexSortedSet) CountRange

func (s *RLexSortedSet) CountRange(ctx context.Context, min, max string) (int64, error)

CountRange counts members in the inclusive [min, max] range.

func (*RLexSortedSet) CountTail

func (s *RLexSortedSet) CountTail(ctx context.Context, fromValue string) (int64, error)

CountTail counts members after fromValue (open range).

func (*RLexSortedSet) Delete

func (o *RLexSortedSet) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RLexSortedSet) Exists

func (o *RLexSortedSet) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RLexSortedSet) Expire

func (o *RLexSortedSet) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RLexSortedSet) ExpireAt

func (o *RLexSortedSet) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RLexSortedSet) First

func (s *RLexSortedSet) First(ctx context.Context) (string, error)

First returns the smallest member ("" when empty).

func (*RLexSortedSet) Last

func (s *RLexSortedSet) Last(ctx context.Context) (string, error)

Last returns the largest member ("" when empty).

func (*RLexSortedSet) Name

func (o *RLexSortedSet) Name() string

Name returns the Redis key name of the object.

func (*RLexSortedSet) PollFirst

func (s *RLexSortedSet) PollFirst(ctx context.Context) (string, error)

PollFirst removes and returns the smallest member ("" when empty).

func (*RLexSortedSet) PollLast

func (s *RLexSortedSet) PollLast(ctx context.Context) (string, error)

PollLast removes and returns the largest member ("" when empty).

func (*RLexSortedSet) Random added in v0.2.13

func (s *RLexSortedSet) Random(ctx context.Context) (string, error)

Random returns one random member, or "" when empty.

func (*RLexSortedSet) RandomN added in v0.2.13

func (s *RLexSortedSet) RandomN(ctx context.Context, count int) ([]string, error)

RandomN returns random members using Redis ZRANDMEMBER count semantics.

func (*RLexSortedSet) Range

func (s *RLexSortedSet) Range(ctx context.Context, start, stop int64) ([]string, error)

Range returns members by rank [start, stop].

func (*RLexSortedSet) RangeByLex

func (s *RLexSortedSet) RangeByLex(ctx context.Context, min, max string, offset, count int64) ([]string, error)

RangeByLex returns members in the inclusive [min, max] lex range.

func (*RLexSortedSet) RangeByLexReversed added in v0.2.13

func (s *RLexSortedSet) RangeByLexReversed(
	ctx context.Context, min, max string, offset, count int64,
) ([]string, error)

RangeByLexReversed returns the inclusive [min, max] range in reverse order.

func (*RLexSortedSet) RangeHead

func (s *RLexSortedSet) RangeHead(ctx context.Context, toValue string, offset, count int64) ([]string, error)

RangeHead returns members lexicographically before toValue (open range).

func (*RLexSortedSet) RangeHeadReversed added in v0.2.13

func (s *RLexSortedSet) RangeHeadReversed(
	ctx context.Context, toValue string, offset, count int64,
) ([]string, error)

RangeHeadReversed returns members before toValue in reverse order.

func (*RLexSortedSet) RangeReversed added in v0.2.13

func (s *RLexSortedSet) RangeReversed(ctx context.Context, start, stop int64) ([]string, error)

RangeReversed returns members by descending rank [start, stop].

func (*RLexSortedSet) RangeTail

func (s *RLexSortedSet) RangeTail(ctx context.Context, fromValue string, offset, count int64) ([]string, error)

RangeTail returns members lexicographically after fromValue (open range).

func (*RLexSortedSet) RangeTailReversed added in v0.2.13

func (s *RLexSortedSet) RangeTailReversed(
	ctx context.Context, fromValue string, offset, count int64,
) ([]string, error)

RangeTailReversed returns members after fromValue in reverse order.

func (*RLexSortedSet) Rank added in v0.2.13

func (s *RLexSortedSet) Rank(ctx context.Context, element string) (int64, error)

Rank returns the 0-based ascending rank, or -1 when absent.

func (*RLexSortedSet) RemainTTL

func (o *RLexSortedSet) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RLexSortedSet) Remove

func (s *RLexSortedSet) Remove(ctx context.Context, element string) (bool, error)

Remove removes a raw member.

func (*RLexSortedSet) RemoveRangeByLex

func (s *RLexSortedSet) RemoveRangeByLex(ctx context.Context, min, max string) (int64, error)

RemoveRangeByLex removes members in the inclusive [min, max] range.

func (*RLexSortedSet) RemoveRangeHead

func (s *RLexSortedSet) RemoveRangeHead(ctx context.Context, toValue string) (int64, error)

RemoveRangeHead removes members before toValue (open range).

func (*RLexSortedSet) RemoveRangeTail

func (s *RLexSortedSet) RemoveRangeTail(ctx context.Context, fromValue string) (int64, error)

RemoveRangeTail removes members after fromValue (open range).

func (*RLexSortedSet) Rename

func (o *RLexSortedSet) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RLexSortedSet) RevRank added in v0.2.13

func (s *RLexSortedSet) RevRank(ctx context.Context, element string) (int64, error)

RevRank returns the 0-based descending rank, or -1 when absent.

func (*RLexSortedSet) Size

func (s *RLexSortedSet) Size(ctx context.Context) (int64, error)

Size returns the member count.

func (*RLexSortedSet) Touch

func (o *RLexSortedSet) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RLexSortedSet) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RList

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

RList is a distributed list backed by a Redis List (RPUSH / LPOP). Elements are codec (JSON) encoded, Redisson-compatible.

func (*RList) Add

func (l *RList) Add(ctx context.Context, values ...any) error

Add appends values to the tail of the list.

func (*RList) AddAfter added in v0.2.13

func (l *RList) AddAfter(ctx context.Context, pivot, element any) (int64, error)

AddAfter inserts element after pivot (LINSERT AFTER). Returns the list length after insert, or -1 when pivot is missing.

func (*RList) AddBefore added in v0.2.13

func (l *RList) AddBefore(ctx context.Context, pivot, element any) (int64, error)

AddBefore inserts element before pivot (LINSERT BEFORE). Returns the list length after insert, or -1 when pivot is missing.

func (*RList) AddCounted added in v0.2.13

func (l *RList) AddCounted(ctx context.Context, values ...any) (int64, error)

AddCounted appends values and returns the list length after the push (Redis RPUSH).

func (*RList) Clear

func (l *RList) Clear(ctx context.Context) error

Clear removes the entire list.

func (*RList) ClearExpire

func (o *RList) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RList) Contains added in v0.2.13

func (l *RList) Contains(ctx context.Context, value any) (bool, error)

Contains reports whether value appears in the list.

func (*RList) Delete

func (o *RList) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RList) Exists

func (o *RList) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RList) Expire

func (o *RList) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RList) ExpireAt

func (o *RList) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RList) FastRemoveByIndex added in v0.2.13

func (l *RList) FastRemoveByIndex(ctx context.Context, index int64) error

FastRemoveByIndex removes the element at index without returning it (Redisson fastRemove).

func (*RList) FastSet added in v0.2.13

func (l *RList) FastSet(ctx context.Context, index int64, value any) error

FastSet is the Redisson-style alias of Set.

func (*RList) Get

func (l *RList) Get(ctx context.Context, index int64) (any, error)

Get returns the element at the given index (0-based). Returns (nil, nil) when the index is out of range.

func (*RList) GetInto added in v0.2.13

func (l *RList) GetInto(ctx context.Context, index int64, target any) (bool, error)

GetInto decodes the element at index into target. Returns false when the index is out of range.

func (*RList) IndexOf added in v0.2.13

func (l *RList) IndexOf(ctx context.Context, value any) (int64, error)

IndexOf returns the first index of value, or -1 when absent.

func (*RList) LastIndexOf added in v0.2.13

func (l *RList) LastIndexOf(ctx context.Context, value any) (int64, error)

LastIndexOf returns the last index of value, or -1 when absent.

func (*RList) Name

func (o *RList) Name() string

Name returns the Redis key name of the object.

func (*RList) Range

func (l *RList) Range(ctx context.Context, start, stop int64) ([]any, error)

Range returns all elements in [start, stop] (decoded).

func (*RList) ReadAll added in v0.2.13

func (l *RList) ReadAll(ctx context.Context) ([]any, error)

ReadAll returns the entire list (Redisson readAll).

func (*RList) RemainTTL

func (o *RList) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RList) Remove

func (l *RList) Remove(ctx context.Context, count int64, value any) error

Remove removes up to count occurrences of value (count semantics match Redis LREM). Prefer RemoveCounted when you need the removed tally.

func (*RList) RemoveByIndex added in v0.2.13

func (l *RList) RemoveByIndex(ctx context.Context, index int64) (any, error)

RemoveByIndex removes and returns the element at index (Redisson remove(int) / fastRemove tombstone path). Returns (nil, nil) when out of range.

func (*RList) RemoveCounted added in v0.2.13

func (l *RList) RemoveCounted(ctx context.Context, count int64, value any) (int64, error)

RemoveCounted is LREM and returns how many elements were removed.

func (*RList) Rename

func (o *RList) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RList) Set

func (l *RList) Set(ctx context.Context, index int64, value any) error

Set replaces the element at index with value (LSET).

func (*RList) Size

func (l *RList) Size(ctx context.Context) (int64, error)

Size returns the number of elements in the list.

func (*RList) Touch

func (o *RList) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RList) Trim added in v0.2.13

func (l *RList) Trim(ctx context.Context, start, stop int64) error

Trim keeps only elements in [start, stop] (LTRIM, inclusive).

func (o *RList) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RListMultimap

type RListMultimap struct{ RMultimap }

RListMultimap stores an ordered value list per key.

func (*RListMultimap) ClearExpire

func (o *RListMultimap) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RListMultimap) Delete

func (o *RListMultimap) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RListMultimap) Exists

func (o *RListMultimap) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RListMultimap) Expire

func (o *RListMultimap) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RListMultimap) ExpireAt

func (o *RListMultimap) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RListMultimap) Name

func (o *RListMultimap) Name() string

Name returns the Redis key name of the object.

func (*RListMultimap) RemainTTL

func (o *RListMultimap) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RListMultimap) Rename

func (o *RListMultimap) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RListMultimap) Touch

func (o *RListMultimap) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RListMultimap) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RListMultimapCache added in v0.2.13

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

RListMultimapCache stores an ordered value list per key with Redisson's per-key expiration metadata.

func (RListMultimapCache) Clear added in v0.2.13

func (m RListMultimapCache) Clear(ctx context.Context) error

Clear removes the index, timeout metadata and every per-key collection.

func (RListMultimapCache) ContainsEntry added in v0.2.13

func (m RListMultimapCache) ContainsEntry(
	ctx context.Context, key, value any,
) (bool, error)

ContainsEntry reports whether the current key contains value.

func (RListMultimapCache) ContainsKey added in v0.2.13

func (m RListMultimapCache) ContainsKey(ctx context.Context, key any) (bool, error)

ContainsKey reports whether key currently has values.

func (RListMultimapCache) ContainsValue added in v0.2.13

func (m RListMultimapCache) ContainsValue(ctx context.Context, value any) (bool, error)

ContainsValue reports whether any live key is associated with value.

func (RListMultimapCache) Delete added in v0.2.13

func (m RListMultimapCache) Delete(ctx context.Context) error

Delete removes the whole multimap cache.

func (RListMultimapCache) Entries added in v0.2.13

func (m RListMultimapCache) Entries(ctx context.Context) ([]MultimapEntry, error)

Entries returns every live key/value association.

func (RListMultimapCache) Expire added in v0.2.13

func (m RListMultimapCache) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire applies ttl to the index, timeout metadata and every per-key collection, matching RedissonMultimapCache's whole-object expiration.

func (RListMultimapCache) ExpireKey added in v0.2.13

func (m RListMultimapCache) ExpireKey(
	ctx context.Context, key any, ttl time.Duration,
) (bool, error)

ExpireKey sets the lifetime of every value associated with key.

func (RListMultimapCache) Get added in v0.2.13

func (m RListMultimapCache) Get(ctx context.Context, key any) ([]any, error)

Get returns the current values. Expired keys are hidden and lazily removed from the HASH, timeout ZSET and per-key collection.

func (RListMultimapCache) GetFairLock added in v0.2.13

func (m RListMultimapCache) GetFairLock(key any) *RFairLock

GetFairLock returns the Redisson fair lock for a multimap-cache key.

func (RListMultimapCache) GetLock added in v0.2.13

func (m RListMultimapCache) GetLock(key any) *RLock

GetLock returns the Redisson lock associated with a multimap-cache key.

func (RListMultimapCache) GetReadWriteLock added in v0.2.13

func (m RListMultimapCache) GetReadWriteLock(key any) *RReadWriteLock

GetReadWriteLock returns the Redisson read-write lock for a cache key.

func (RListMultimapCache) GetSemaphore added in v0.2.13

func (m RListMultimapCache) GetSemaphore(key any) *RSemaphore

GetSemaphore returns the Redisson semaphore for a multimap-cache key.

func (RListMultimapCache) IsEmpty added in v0.2.13

func (m RListMultimapCache) IsEmpty(ctx context.Context) (bool, error)

IsEmpty reports whether the cache has no live associations.

func (RListMultimapCache) KeySet added in v0.2.13

func (m RListMultimapCache) KeySet(ctx context.Context) ([]any, error)

KeySet returns every live key.

func (RListMultimapCache) KeySize added in v0.2.13

func (m RListMultimapCache) KeySize(ctx context.Context) (int64, error)

KeySize returns the number of live keys.

func (RListMultimapCache) Put added in v0.2.13

func (m RListMultimapCache) Put(
	ctx context.Context, key, value any,
) (bool, error)

Put associates value with key. For an expired key it first removes the old collection, so a new association starts a fresh non-expiring key.

func (RListMultimapCache) PutAll added in v0.2.13

func (m RListMultimapCache) PutAll(
	ctx context.Context, key any, values ...any,
) (bool, error)

PutAll associates all values with key.

func (RListMultimapCache) ReadAllKeySet added in v0.2.13

func (m RListMultimapCache) ReadAllKeySet(ctx context.Context) ([]any, error)

ReadAllKeySet is the eager Redisson-style alias of KeySet.

func (RListMultimapCache) RemoveAll added in v0.2.13

func (m RListMultimapCache) RemoveAll(ctx context.Context, key any) (bool, error)

RemoveAll removes key, its values and expiration metadata.

func (RListMultimapCache) ReplaceValues added in v0.2.13

func (m RListMultimapCache) ReplaceValues(
	ctx context.Context, key any, values ...any,
) ([]any, error)

ReplaceValues replaces all live values associated with key and returns the previous values. The key keeps its existing per-key expiration.

func (RListMultimapCache) Size added in v0.2.13

func (m RListMultimapCache) Size(ctx context.Context) (int64, error)

Size returns the number of live key/value associations.

func (RListMultimapCache) StartAutoEviction added in v0.2.13

func (m RListMultimapCache) StartAutoEviction(interval time.Duration)

StartAutoEviction periodically runs lazy expiry cleanup until the client closes (optional; default access paths already clean lazily).

func (RListMultimapCache) Values added in v0.2.13

func (m RListMultimapCache) Values(ctx context.Context) ([]any, error)

Values returns values across all live keys.

type RListMultimapCacheNative added in v0.2.13

type RListMultimapCacheNative struct{ *RListMultimap }

func (RListMultimapCacheNative) ClearExpire added in v0.2.13

func (o RListMultimapCacheNative) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RListMultimapCacheNative) Delete added in v0.2.13

func (o RListMultimapCacheNative) Delete(ctx context.Context) error

Delete removes the object's key.

func (RListMultimapCacheNative) Exists added in v0.2.13

func (o RListMultimapCacheNative) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RListMultimapCacheNative) Expire added in v0.2.13

func (o RListMultimapCacheNative) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RListMultimapCacheNative) ExpireAt added in v0.2.13

func (o RListMultimapCacheNative) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RListMultimapCacheNative) ExpireKey added in v0.2.13

func (m *RListMultimapCacheNative) ExpireKey(ctx context.Context, key any, ttl time.Duration) (bool, error)

func (RListMultimapCacheNative) Name added in v0.2.13

func (o RListMultimapCacheNative) Name() string

Name returns the Redis key name of the object.

func (RListMultimapCacheNative) RemainTTL added in v0.2.13

func (o RListMultimapCacheNative) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RListMultimapCacheNative) Rename added in v0.2.13

func (o RListMultimapCacheNative) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RListMultimapCacheNative) Touch added in v0.2.13

func (o RListMultimapCacheNative) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RListMultimapCacheNative) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RLocalCachedMap added in v0.2.5

type RLocalCachedMap struct {
	*RMap
	// contains filtered or unexported fields
}

RLocalCachedMap is an RMap with an in-process near cache.

Data interoperability: the Redis-backed map uses the exact RMap wire format, so Java Redisson / redi.py can read and write the same entries.

Invalidation interoperability: Java's LocalCachedMapInvalidation protocol (key-hash byte arrays + updates log + Java object encoding) is NOT replicated; invalidation broadcast uses a Go-internal channel `{name}:inval` (JSON messages). Go instances invalidate each other; Java writers are not broadcast to Go caches (documented in COMPATIBILITY.md). Reads always have the Redis fallback, so Java writes are picked up by Go after the local entry is evicted or the cache is cleared.

func (*RLocalCachedMap) CachedKeys added in v0.2.5

func (m *RLocalCachedMap) CachedKeys() []string

CachedKeys returns the keys currently held in the local cache.

func (*RLocalCachedMap) CachedValues added in v0.2.13

func (m *RLocalCachedMap) CachedValues() []any

CachedValues returns a snapshot of values currently held locally.

func (*RLocalCachedMap) Clear added in v0.2.5

func (m *RLocalCachedMap) Clear(ctx context.Context) error

Clear deletes the Redis map, empties the local cache and broadcasts a full invalidation.

func (RLocalCachedMap) ClearExpire added in v0.2.5

func (o RLocalCachedMap) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RLocalCachedMap) ClearLocalCache added in v0.2.5

func (m *RLocalCachedMap) ClearLocalCache()

ClearLocalCache empties only the local cache (no Redis writes).

func (*RLocalCachedMap) Destroy added in v0.2.5

func (m *RLocalCachedMap) Destroy()

Destroy stops the listener goroutine (also triggered by Client.Close).

func (RLocalCachedMap) Exists added in v0.2.5

func (o RLocalCachedMap) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RLocalCachedMap) Expire added in v0.2.5

func (o RLocalCachedMap) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RLocalCachedMap) ExpireAt added in v0.2.5

func (o RLocalCachedMap) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RLocalCachedMap) FastPut added in v0.2.13

func (m *RLocalCachedMap) FastPut(ctx context.Context, field string, value any) (bool, error)

FastPut write-throughs like Put and returns whether the field was new.

func (*RLocalCachedMap) FastPutIfExists added in v0.2.13

func (m *RLocalCachedMap) FastPutIfExists(ctx context.Context, field string, value any) (bool, error)

FastPutIfExists write-throughs when the field already exists.

func (*RLocalCachedMap) FastRemove added in v0.2.13

func (m *RLocalCachedMap) FastRemove(ctx context.Context, fields ...string) (int64, error)

FastRemove deletes fields, drops them from the local cache, and broadcasts.

func (*RLocalCachedMap) FastReplace added in v0.2.13

func (m *RLocalCachedMap) FastReplace(ctx context.Context, field string, value any) (bool, error)

FastReplace is an alias of FastPutIfExists with local-cache update.

func (*RLocalCachedMap) Get added in v0.2.5

func (m *RLocalCachedMap) Get(ctx context.Context, field string) (any, error)

Get returns the value for field, serving from the local cache when present (a hit makes NO Redis round-trip).

func (*RLocalCachedMap) GetCachedMap added in v0.2.13

func (m *RLocalCachedMap) GetCachedMap() map[string]any

GetCachedMap returns a decoded snapshot of the local cache.

func (*RLocalCachedMap) GetInto added in v0.2.13

func (m *RLocalCachedMap) GetInto(ctx context.Context, field string, target any) (bool, error)

GetInto decodes the value into target, serving from the local cache on hit.

func (RLocalCachedMap) Name added in v0.2.5

func (o RLocalCachedMap) Name() string

Name returns the Redis key name of the object.

func (*RLocalCachedMap) PreloadCache added in v0.2.13

func (m *RLocalCachedMap) PreloadCache(ctx context.Context, count ...int) error

PreloadCache warms the local cache with all current Redis entries. The optional count is accepted as the Redisson scan-batch hint.

func (*RLocalCachedMap) Put added in v0.2.5

func (m *RLocalCachedMap) Put(ctx context.Context, field string, value any) error

Put writes through to Redis, updates the local cache and broadcasts invalidation to the other Go instances.

func (*RLocalCachedMap) PutAll added in v0.2.13

func (m *RLocalCachedMap) PutAll(ctx context.Context, entries map[string]any) error

PutAll write-throughs every entry, updates the local cache, and broadcasts one invalidation per field (same granularity as Put).

func (*RLocalCachedMap) PutIfAbsent added in v0.2.5

func (m *RLocalCachedMap) PutIfAbsent(ctx context.Context, field string, value any) (bool, error)

PutIfAbsent writes only when absent; on success the local cache is updated and the invalidation broadcast fires.

func (RLocalCachedMap) RemainTTL added in v0.2.5

func (o RLocalCachedMap) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RLocalCachedMap) Remove added in v0.2.5

func (m *RLocalCachedMap) Remove(ctx context.Context, field string) error

Remove deletes the field everywhere and broadcasts.

func (RLocalCachedMap) Rename added in v0.2.5

func (o RLocalCachedMap) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RLocalCachedMap) Replace added in v0.2.13

func (m *RLocalCachedMap) Replace(ctx context.Context, field string, value any) (any, error)

Replace write-throughs when the field exists; updates local cache and broadcasts on success.

func (*RLocalCachedMap) ReplaceIf added in v0.2.13

func (m *RLocalCachedMap) ReplaceIf(ctx context.Context, field string, oldValue, newValue any) (bool, error)

ReplaceIf write-throughs on compare-and-set success.

func (*RLocalCachedMap) SetLocalCacheLimit added in v0.2.5

func (m *RLocalCachedMap) SetLocalCacheLimit(ttl time.Duration, maxEntries int)

SetLocalCacheLimit configures local eviction: entries older than ttl are dropped on access, and the cache stops caching beyond maxEntries (0 = unlimited). Call before first use.

func (RLocalCachedMap) Touch added in v0.2.5

func (o RLocalCachedMap) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RLocalCachedMap) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RLock

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

RLock is a distributed re-entrant lock, wire-compatible with Redisson's RLock: a Redis HASH at the raw name whose fields are holder ids with re-entrancy counts, and a pub/sub channel redisson_lock__channel:{name} used to wake up waiting acquirers on release (~0ms wakeup vs 50-100ms polling).

The caller-supplied clientID is used as the HASH field directly. Prefer Client.HolderID(threadID) for a Redisson-shaped "uuid:threadId" field that stays stable across re-entry and Unlock.

Lock semantics (matching Redisson):

  • ttl <= 0: watchdog mode – lease = Config.LockWatchdogTimeout (30s default), renewed every lease/3 until Unlock.
  • ttl > 0: fixed lease, no renewal, lock expires on its own.
Example
package main

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

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		fmt.Println("skip:", err)
		return
	}
	defer client.Close() //nolint:errcheck // example

	ctx := context.Background()
	_, _ = client.GetKeys().Delete(ctx, "demo:try-lock")
	lock := client.GetRLock("demo:try-lock")

	// One-shot acquisition without blocking.
	ok, err := lock.TryLock(ctx, "app:42", time.Minute)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("first acquire:", ok)

	// Re-entry by the same holder increments the counter.
	if err := lock.Lock(ctx, "app:42", time.Minute); err != nil {
		log.Fatal(err)
	}
	n, _ := lock.HoldCount(ctx, "app:42")
	fmt.Println("hold count:", n)

	_ = lock.Unlock(ctx, "app:42")
	_ = lock.Unlock(ctx, "app:42")
}
Output:
first acquire: true
hold count: 2

func (*RLock) ClearExpire

func (o *RLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RLock) Delete

func (o *RLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RLock) Exists

func (o *RLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RLock) Expire

func (o *RLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RLock) ExpireAt

func (o *RLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RLock) ForceUnlock

func (l *RLock) ForceUnlock(ctx context.Context) (bool, error)

ForceUnlock deletes the lock regardless of owner and wakes all waiters.

func (*RLock) HoldCount

func (l *RLock) HoldCount(ctx context.Context, clientID string) (int64, error)

HoldCount returns the re-entrancy count held by clientID (0 if none).

func (*RLock) IsHeldBy

func (l *RLock) IsHeldBy(ctx context.Context, clientID string) (bool, error)

IsHeldBy reports whether clientID holds the lock.

func (*RLock) IsLocked

func (l *RLock) IsLocked(ctx context.Context) (bool, error)

IsLocked reports whether the lock is held by anyone.

func (*RLock) Lock

func (l *RLock) Lock(ctx context.Context, clientID string, ttl time.Duration) error

Lock acquires the lock, blocking until success or ctx cancellation. See the RLock doc for ttl semantics.

func (*RLock) Name

func (o *RLock) Name() string

Name returns the Redis key name of the object.

func (*RLock) RemainTTL

func (o *RLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RLock) RemainTimeToLive added in v0.2.13

func (l *RLock) RemainTimeToLive(ctx context.Context) (time.Duration, error)

RemainTimeToLive returns the remaining lease. Negative durations follow go-redis PTTL conventions (approximately -2ns when the key is absent, -1ns when present without expiry).

func (*RLock) Rename

func (o *RLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RLock) Touch

func (o *RLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RLock) TryLock

func (l *RLock) TryLock(ctx context.Context, clientID string, ttl time.Duration) (bool, error)

TryLock attempts to acquire the lock once, returning false immediately when held by someone else.

func (*RLock) TryLockWait added in v0.2.13

func (l *RLock) TryLockWait(ctx context.Context, clientID string, wait, ttl time.Duration) (bool, error)

TryLockWait tries to acquire until wait elapses or ctx is cancelled. lease/ttl semantics match Lock (ttl<=0 enables watchdog).

func (o *RLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RLock) Unlock

func (l *RLock) Unlock(ctx context.Context, clientID string) error

Unlock releases one hold. When the hold count reaches zero the key is deleted and waiting acquirers are woken. The watchdog (if any) is only cancelled after ownership is verified, so a stray Unlock by a non-owner cannot kill the real holder's renewal.

type RLongAdder added in v0.2.8

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

RLongAdder is a high-contention distributed counter: writes accumulate in a local atomic (zero network), Sum() coordinates a flush across all live instances (Go and Java alike) and returns the grand total. Wire-compatible with Redisson's RedissonLongAdder.

func (*RLongAdder) Add added in v0.2.8

func (a *RLongAdder) Add(x int64)

Add adds x to the local buffer (no network round-trip).

func (*RLongAdder) Decrement added in v0.2.8

func (a *RLongAdder) Decrement()

Decrement subtracts 1.

func (*RLongAdder) Destroy added in v0.2.8

func (a *RLongAdder) Destroy()

Destroy unsubscribes this instance (also triggered by Client.Close).

func (*RLongAdder) Increment added in v0.2.8

func (a *RLongAdder) Increment()

Increment adds 1.

func (*RLongAdder) Reset added in v0.2.8

func (a *RLongAdder) Reset(ctx context.Context) error

Reset clears every live instance's local buffer.

func (*RLongAdder) Sum added in v0.2.8

func (a *RLongAdder) Sum(ctx context.Context) (int64, error)

Sum flushes every live instance's buffer and returns the total (non-destructive, matching Java).

type RMap

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

RMap is a distributed map backed by a Redis Hash, wire-compatible with Redisson's RMap using JsonJacksonCodec: both fields and values are JSON encoded by the client Codec.

func (*RMap) AddAndGet

func (m *RMap) AddAndGet(ctx context.Context, field string, delta int64) (int64, error)

AddAndGet atomically adds delta to the numeric value of field and returns the new value. The stored value must be a bare JSON number.

func (*RMap) Clear

func (m *RMap) Clear(ctx context.Context) error

Clear removes the entire map key (DEL), not individual fields. Must not call Delete with no fields — that path is a no-op by design.

func (*RMap) ClearExpire

func (o *RMap) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RMap) ContainsKey

func (m *RMap) ContainsKey(ctx context.Context, field string) (bool, error)

ContainsKey reports whether the map contains the given field.

func (*RMap) ContainsValue added in v0.2.13

func (m *RMap) ContainsValue(ctx context.Context, value any) (bool, error)

ContainsValue reports whether any field stores value (codec equality).

func (*RMap) Delete

func (m *RMap) Delete(ctx context.Context, fields ...string) error

Delete removes one or more fields from the map.

func (*RMap) Exists

func (o *RMap) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RMap) Expire

func (o *RMap) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RMap) ExpireAt

func (o *RMap) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RMap) FastPut added in v0.2.13

func (m *RMap) FastPut(ctx context.Context, field string, value any) (bool, error)

FastPut sets field and reports whether it was a new field (true) or an update of an existing one (false) — Redisson fastPut semantics (HSET).

func (*RMap) FastPutIfAbsent added in v0.2.13

func (m *RMap) FastPutIfAbsent(ctx context.Context, field string, value any) (bool, error)

FastPutIfAbsent is the Redisson-style alias of PutIfAbsent.

func (*RMap) FastPutIfExists added in v0.2.13

func (m *RMap) FastPutIfExists(ctx context.Context, field string, value any) (bool, error)

FastPutIfExists sets field only when it already exists. Returns true when written — Redisson fastPutIfExists.

func (*RMap) FastRemove added in v0.2.13

func (m *RMap) FastRemove(ctx context.Context, fields ...string) (int64, error)

FastRemove deletes fields and returns how many were actually removed (Redisson fastRemove / HDEL).

func (*RMap) FastReplace added in v0.2.13

func (m *RMap) FastReplace(ctx context.Context, field string, value any) (bool, error)

FastReplace is an alias of FastPutIfExists (Redisson fastReplace).

func (*RMap) Get

func (m *RMap) Get(ctx context.Context, field string) (any, error)

Get retrieves the value for field. Returns (nil, nil) when absent.

func (*RMap) GetAll

func (m *RMap) GetAll(ctx context.Context) (map[string]any, error)

GetAll returns all field-value pairs (values decoded).

func (*RMap) GetAllKeys added in v0.2.13

func (m *RMap) GetAllKeys(ctx context.Context, fields ...string) (map[string]any, error)

GetAllKeys returns values for the given fields (missing fields omitted).

func (*RMap) GetCountDownLatch added in v0.2.13

func (m *RMap) GetCountDownLatch(key any) *RCountDownLatch

GetCountDownLatch returns the Redisson latch associated with a map key.

func (*RMap) GetFairLock added in v0.2.13

func (m *RMap) GetFairLock(key any) *RFairLock

GetFairLock returns the Redisson fair lock associated with a map key.

func (*RMap) GetInto added in v0.2.13

func (m *RMap) GetInto(ctx context.Context, field string, target any) (bool, error)

GetInto decodes the value for field into target. Returns false when absent.

Example
package main

import (
	"context"
	"fmt"

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		fmt.Println("skip:", err)
		return
	}
	defer client.Close() //nolint:errcheck // example
	ctx := context.Background()
	_, _ = client.GetKeys().Delete(ctx, "demo:into-map")

	type user struct {
		Name string `json:"name"`
	}
	m := client.GetMap("demo:into-map")
	_ = m.Put(ctx, "u1", user{Name: "ada"})

	var u user
	ok, _ := m.GetInto(ctx, "u1", &u)
	fmt.Println(ok, u.Name)
	_ = m.Clear(ctx)
}
Output:
true ada

func (*RMap) GetLock added in v0.2.13

func (m *RMap) GetLock(key any) *RLock

GetLock returns the Redisson lock associated with a map key.

func (*RMap) GetPermitExpirableSemaphore added in v0.2.13

func (m *RMap) GetPermitExpirableSemaphore(key any) *RPermitExpirableSemaphore

GetPermitExpirableSemaphore returns the Redisson expirable semaphore for a map key.

func (*RMap) GetReadWriteLock added in v0.2.13

func (m *RMap) GetReadWriteLock(key any) *RReadWriteLock

GetReadWriteLock returns the Redisson read-write lock for a map key.

func (*RMap) GetSemaphore added in v0.2.13

func (m *RMap) GetSemaphore(key any) *RSemaphore

GetSemaphore returns the Redisson semaphore associated with a map key.

func (*RMap) Keys added in v0.2.13

func (m *RMap) Keys(ctx context.Context) ([]string, error)

Keys returns all map fields (decoded). Order is undefined.

func (*RMap) Name

func (o *RMap) Name() string

Name returns the Redis key name of the object.

func (*RMap) Put

func (m *RMap) Put(ctx context.Context, field string, value any) error

Put sets field in the map to value.

func (*RMap) PutAll added in v0.2.13

func (m *RMap) PutAll(ctx context.Context, entries map[string]any) error

PutAll writes every entry in a single HSET (empty map is a no-op).

func (*RMap) PutIfAbsent

func (m *RMap) PutIfAbsent(ctx context.Context, field string, value any) (bool, error)

PutIfAbsent sets field only when absent. Returns true when set.

func (*RMap) PutIfExists added in v0.2.13

func (m *RMap) PutIfExists(ctx context.Context, field string, value any) (bool, error)

PutIfExists sets field only when it already exists. Returns true when written.

func (*RMap) RandomEntries added in v0.2.13

func (m *RMap) RandomEntries(
	ctx context.Context, count int64,
) (map[string]any, error)

RandomEntries returns up to count random distinct field-value pairs.

func (*RMap) RandomKeys added in v0.2.13

func (m *RMap) RandomKeys(ctx context.Context, count int64) ([]string, error)

RandomKeys returns up to count random distinct fields.

func (*RMap) RemainTTL

func (o *RMap) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RMap) Rename

func (o *RMap) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RMap) Replace added in v0.2.13

func (m *RMap) Replace(ctx context.Context, field string, value any) (any, error)

Replace sets field only when it already exists. Returns the previous value, or (nil, nil) when the field was absent (unchanged).

func (*RMap) ReplaceIf added in v0.2.13

func (m *RMap) ReplaceIf(ctx context.Context, field string, oldValue, newValue any) (bool, error)

ReplaceIf sets field to newValue only when the current value equals oldValue (codec-encoded equality). Returns true when replaced.

func (*RMap) Size

func (m *RMap) Size(ctx context.Context) (int64, error)

Size returns the number of fields in the map.

func (*RMap) Touch

func (o *RMap) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RMap) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RMap) ValueSize added in v0.2.13

func (m *RMap) ValueSize(ctx context.Context, field string) (int64, error)

ValueSize returns the encoded value size in bytes (HSTRLEN).

func (*RMap) Values added in v0.2.13

func (m *RMap) Values(ctx context.Context) ([]any, error)

Values returns all map values (decoded). Order is undefined.

type RMapCache

type RMapCache struct {
	*RMap
	// contains filtered or unexported fields
}

RMapCache is an RMap with per-entry TTL and maxIdle, wire-compatible with Redisson's RedissonMapCache:

HASH {name}                              field -> packed value
ZSET  redisson__timeout__set:{name}      expiry deadlines (score = ts ms)
ZSET  redisson__idle__set:{name}         idle deadlines (score = ts ms)

The packed value format is Redisson's struct layout: little-endian float64 (maxIdle ms) + little-endian uint64 (codec length) + codec bytes.

Expired entries are purged lazily on access and by an optional background sweeper (StartAutoEviction). Entry events (created/updated/removed/expired) are published on Redisson-compatible channels and can be consumed with AddListener.

func (*RMapCache) AddListener

func (m *RMapCache) AddListener(kind string, cb func(kind, key, value, oldValue any)) (int, error)

AddListener registers an entry event listener for the given kind (EventCreated/EventUpdated/EventRemoved/EventExpired). The callback receives (kind, key, value, oldValue); oldValue is non-nil only for EventUpdated. Returns the listener id for RemoveListener.

func (*RMapCache) Clear

func (m *RMapCache) Clear(ctx context.Context) error

Clear removes the map and all deadline, access, and options companions.

func (RMapCache) ClearExpire

func (o RMapCache) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RMapCache) ContainsKey added in v0.2.13

func (m *RMapCache) ContainsKey(ctx context.Context, field string) (bool, error)

ContainsKey reports whether the cache contains a live field.

func (*RMapCache) ContainsValue added in v0.2.13

func (m *RMapCache) ContainsValue(ctx context.Context, value any) (bool, error)

ContainsValue reports whether a live field stores value (codec equality).

func (*RMapCache) Delete added in v0.2.13

func (m *RMapCache) Delete(ctx context.Context, fields ...string) error

Delete removes fields, or the cache and companions when no fields are given.

func (*RMapCache) EvictExpired

func (m *RMapCache) EvictExpired(ctx context.Context) (int, error)

EvictExpired purges expired entries now, returning how many were removed.

func (RMapCache) Exists

func (o RMapCache) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RMapCache) Expire

func (o RMapCache) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RMapCache) ExpireAt

func (o RMapCache) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RMapCache) ExpireEntries added in v0.2.13

func (m *RMapCache) ExpireEntries(
	ctx context.Context, fields []string, ttl, maxIdle time.Duration,
) (int, error)

ExpireEntries replaces the TTL/maxIdle policy for live fields.

func (*RMapCache) ExpireEntriesIfNotSet added in v0.2.13

func (m *RMapCache) ExpireEntriesIfNotSet(
	ctx context.Context, fields []string, ttl, maxIdle time.Duration,
) (int, error)

ExpireEntriesIfNotSet sets expiration only on fields without a policy.

func (*RMapCache) ExpireEntry added in v0.2.13

func (m *RMapCache) ExpireEntry(
	ctx context.Context, field string, ttl, maxIdle time.Duration,
) (bool, error)

ExpireEntry replaces the TTL/maxIdle policy of an existing live entry. A non-positive duration disables that expiration dimension.

func (*RMapCache) ExpireEntryIfNotSet added in v0.2.13

func (m *RMapCache) ExpireEntryIfNotSet(
	ctx context.Context, field string, ttl, maxIdle time.Duration,
) (bool, error)

ExpireEntryIfNotSet sets expiration only when the entry has no TTL/maxIdle.

func (*RMapCache) FastPut added in v0.2.13

func (m *RMapCache) FastPut(
	ctx context.Context, field string, value any, durations ...time.Duration,
) (bool, error)

FastPut stores an entry with optional ttl/maxIdle and reports whether new.

func (*RMapCache) FastPutIfAbsent added in v0.2.13

func (m *RMapCache) FastPutIfAbsent(
	ctx context.Context, field string, value any, durations ...time.Duration,
) (bool, error)

FastPutIfAbsent stores only when absent, with optional ttl/maxIdle.

func (*RMapCache) FastPutIfExists added in v0.2.13

func (m *RMapCache) FastPutIfExists(ctx context.Context, field string, value any) (bool, error)

FastPutIfExists is the Redisson-style alias of PutIfExists.

func (*RMapCache) FastRemove added in v0.2.13

func (m *RMapCache) FastRemove(ctx context.Context, fields ...string) (int64, error)

FastRemove deletes fields and their deadline entries.

func (*RMapCache) FastReplace added in v0.2.13

func (m *RMapCache) FastReplace(ctx context.Context, field string, value any) (bool, error)

FastReplace is the Redisson-style alias of PutIfExists.

func (*RMapCache) Get

func (m *RMapCache) Get(ctx context.Context, field string) (any, error)

Get returns the value for field (nil when absent or expired). Access refreshes the maxIdle deadline.

func (*RMapCache) GetAll added in v0.2.13

func (m *RMapCache) GetAll(ctx context.Context) (map[string]any, error)

GetAll returns all live field-value pairs with packed values decoded.

func (*RMapCache) GetAllKeys added in v0.2.13

func (m *RMapCache) GetAllKeys(ctx context.Context, fields ...string) (map[string]any, error)

GetAllKeys returns live values for the requested fields.

func (*RMapCache) GetAllWithTTLOnly added in v0.2.13

func (m *RMapCache) GetAllWithTTLOnly(
	ctx context.Context, fields ...string,
) (map[string]any, error)

GetAllWithTTLOnly returns requested entries after checking only their explicit TTL. Max-idle expiration is intentionally ignored and not renewed.

func (*RMapCache) GetInto added in v0.2.13

func (m *RMapCache) GetInto(ctx context.Context, field string, target any) (bool, error)

GetInto decodes the value for field into target. Returns false when absent.

func (*RMapCache) Keys added in v0.2.13

func (m *RMapCache) Keys(ctx context.Context) ([]string, error)

Keys returns all live map fields. Order is undefined.

func (RMapCache) Name

func (o RMapCache) Name() string

Name returns the Redis key name of the object.

func (*RMapCache) Put

func (m *RMapCache) Put(ctx context.Context, field string, value any, durations ...time.Duration) error

Put sets field with optional per-entry ttl and maxIdle (0 = disabled). Omitting both durations stores an entry without expiry. Publishes a created or updated entry event.

func (*RMapCache) PutAll added in v0.2.13

func (m *RMapCache) PutAll(ctx context.Context, entries map[string]any) error

PutAll writes entries without expiry using the map-cache packed format.

func (*RMapCache) PutIfAbsent

func (m *RMapCache) PutIfAbsent(ctx context.Context, field string, value any, durations ...time.Duration) (bool, error)

PutIfAbsent sets field only when absent, with optional ttl/maxIdle. Returns true when set.

func (*RMapCache) PutIfExists added in v0.2.13

func (m *RMapCache) PutIfExists(ctx context.Context, field string, value any) (bool, error)

PutIfExists stores value without expiry only when field exists.

func (RMapCache) RemainTTL

func (o RMapCache) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RMapCache) RemainTTLForKey

func (m *RMapCache) RemainTTLForKey(ctx context.Context, field string) (time.Duration, error)

RemainTTLForKey returns the remaining per-entry TTL (-2 when absent).

func (*RMapCache) Remove

func (m *RMapCache) Remove(ctx context.Context, field string) error

Remove deletes field and its deadline entries, publishing a removed event.

func (*RMapCache) RemoveListener

func (m *RMapCache) RemoveListener(kind string, id int) bool

RemoveListener unregisters a listener.

func (RMapCache) Rename

func (o RMapCache) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RMapCache) Replace added in v0.2.13

func (m *RMapCache) Replace(ctx context.Context, field string, value any) (any, error)

Replace updates an existing live field without expiry and returns its old value.

func (*RMapCache) ReplaceIf added in v0.2.13

func (m *RMapCache) ReplaceIf(ctx context.Context, field string, oldValue, newValue any) (bool, error)

ReplaceIf updates an existing live field when its decoded value matches.

func (*RMapCache) SetMaxSize added in v0.2.13

func (m *RMapCache) SetMaxSize(ctx context.Context, size int) error

SetMaxSize configures LRU eviction when the cache grows beyond size. A size of zero disables capacity eviction.

func (*RMapCache) SetMaxSizeMode added in v0.2.13

func (m *RMapCache) SetMaxSizeMode(ctx context.Context, size int, mode EvictionMode) error

SetMaxSizeMode configures the maximum size and LRU or LFU eviction.

func (*RMapCache) Size

func (m *RMapCache) Size(ctx context.Context) (int64, error)

Size returns the live entry count (after eviction).

func (*RMapCache) StartAutoEviction

func (m *RMapCache) StartAutoEviction(interval time.Duration)

StartAutoEviction runs a background sweeper every interval until the client closes. Repeated calls are no-ops.

func (RMapCache) Touch

func (o RMapCache) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RMapCache) TrySetMaxSize added in v0.2.13

func (m *RMapCache) TrySetMaxSize(ctx context.Context, size int) (bool, error)

TrySetMaxSize sets the maximum size with LRU eviction only when no size policy has been configured yet.

func (*RMapCache) TrySetMaxSizeMode added in v0.2.13

func (m *RMapCache) TrySetMaxSizeMode(
	ctx context.Context, size int, mode EvictionMode,
) (bool, error)

TrySetMaxSizeMode sets the maximum size and eviction mode once.

func (m *RMapCache) Unlink(ctx context.Context) error

Unlink asynchronously removes the cache and all companions.

func (*RMapCache) UpdateEntryExpiration added in v0.2.13

func (m *RMapCache) UpdateEntryExpiration(
	ctx context.Context, field string, ttl, maxIdle time.Duration,
) (bool, error)

UpdateEntryExpiration is the Redisson-style alias of ExpireEntry.

func (*RMapCache) Values added in v0.2.13

func (m *RMapCache) Values(ctx context.Context) ([]any, error)

Values returns all live map values with their packed headers removed.

type RMapCacheNative added in v0.2.13

type RMapCacheNative struct {
	*RMap
}

RMapCacheNative is a map with per-entry TTL using Redis hash-field expiration (HPEXPIRE / HPEXPIREAT / HPTTL), wire-compatible with RedissonMapCacheNative 4.6.1. Values are plain codec bytes (no MapCache packed header). Requires Redis ≥ 7.4 / 8.x field TTL support.

func (RMapCacheNative) ClearExpire added in v0.2.13

func (o RMapCacheNative) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RMapCacheNative) Exists added in v0.2.13

func (o RMapCacheNative) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RMapCacheNative) Expire added in v0.2.13

func (o RMapCacheNative) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RMapCacheNative) ExpireAt added in v0.2.13

func (o RMapCacheNative) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RMapCacheNative) ExpireEntry added in v0.2.13

func (m *RMapCacheNative) ExpireEntry(ctx context.Context, field string, ttl time.Duration) (bool, error)

ExpireEntry sets a relative TTL on an existing field.

func (*RMapCacheNative) ExpireEntryIfNotSet added in v0.2.13

func (m *RMapCacheNative) ExpireEntryIfNotSet(ctx context.Context, field string, ttl time.Duration) (bool, error)

ExpireEntryIfNotSet sets TTL only when the field has no expiration (NX).

func (*RMapCacheNative) FastPutIfAbsentWithTTL added in v0.2.13

func (m *RMapCacheNative) FastPutIfAbsentWithTTL(ctx context.Context, field string, value any, ttl time.Duration) (bool, error)

FastPutIfAbsentWithTTL returns true when the field was inserted with TTL.

func (*RMapCacheNative) FastPutWithTTL added in v0.2.13

func (m *RMapCacheNative) FastPutWithTTL(ctx context.Context, field string, value any, ttl time.Duration) (bool, error)

FastPutWithTTL sets field with TTL and reports whether the field was new.

func (RMapCacheNative) Name added in v0.2.13

func (o RMapCacheNative) Name() string

Name returns the Redis key name of the object.

func (*RMapCacheNative) PutIfAbsentWithTTL added in v0.2.13

func (m *RMapCacheNative) PutIfAbsentWithTTL(ctx context.Context, field string, value any, ttl time.Duration) (any, error)

PutIfAbsentWithTTL sets field only when absent, applying TTL on insert.

func (*RMapCacheNative) PutUntil added in v0.2.13

func (m *RMapCacheNative) PutUntil(ctx context.Context, field string, value any, at time.Time) (any, error)

PutUntil stores field with an absolute expiry (HPEXPIREAT, unix ms).

func (*RMapCacheNative) PutWithTTL added in v0.2.13

func (m *RMapCacheNative) PutWithTTL(ctx context.Context, field string, value any, ttl time.Duration) (any, error)

PutWithTTL stores field with a relative TTL (HPEXPIRE).

func (RMapCacheNative) RemainTTL added in v0.2.13

func (o RMapCacheNative) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RMapCacheNative) RemainTTLForKey added in v0.2.13

func (m *RMapCacheNative) RemainTTLForKey(ctx context.Context, field string) (time.Duration, error)

RemainTTLForKey returns remaining field TTL. -2 absent, -1 no expiry.

func (RMapCacheNative) Rename added in v0.2.13

func (o RMapCacheNative) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RMapCacheNative) Touch added in v0.2.13

func (o RMapCacheNative) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RMapCacheNative) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RMaps added in v0.2.13

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

RMaps performs mass HASH replacements (RedissonMaps set semantics via DEL+HSET).

func (*RMaps) Set added in v0.2.13

func (m *RMaps) Set(ctx context.Context, maps map[string]map[string]any) error

Set replaces each named map entirely.

func (*RMaps) SetBatch added in v0.2.13

func (m *RMaps) SetBatch(ctx context.Context, maps map[string]map[string]any, batchSize int) error

SetBatch is Set with an optional batchSize (keys per pipeline flush; 0 = all).

type RMultiLock added in v0.2.10

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

RMultiLock groups RLocks into one all-or-nothing lock, mirroring Redisson's RedissonMultiLock orchestration: acquire members in order within the wait budget; on any failure roll back every lock this call acquired. Wire-compatible by construction (plain RLock members).

func (*RMultiLock) Lock added in v0.2.10

func (m *RMultiLock) Lock(ctx context.Context, clientID string, ttl, waitTime time.Duration) error

Lock blocks until every member is acquired, the wait budget expires (ErrMultiLockFailed) or ctx ends. Reuses the Redisson lease-time convention: the effective per-member wait is bounded by waitTime.

func (*RMultiLock) TryLock added in v0.2.10

func (m *RMultiLock) TryLock(ctx context.Context, clientID string, ttl time.Duration) (bool, error)

TryLock attempts to acquire every member once (no waiting). All acquired members are rolled back on the first failure.

func (*RMultiLock) Unlock added in v0.2.10

func (m *RMultiLock) Unlock(ctx context.Context, clientID string) error

Unlock releases every member.

type RMultimap

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

RMultimap is the shared base for RSetMultimap / RListMultimap, wire-compatible with Redisson 4.6.x:

HASH {name}           field = codec(JSON) key, value = internal id
SET/LIST {name}:{id}  per-key collection

The internal id is deterministic: HighwayHash-128 (Redisson fixed key) over the codec-encoded key, packed big-endian, unpadded base64 — matching Java's Hash.hash128toBase64 byte-for-byte (redi.py-verified).

func (*RMultimap) Clear

func (m *RMultimap) Clear(ctx context.Context) error

Clear removes the multimap (hash + every collection).

func (*RMultimap) ClearExpire

func (o *RMultimap) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RMultimap) ContainsEntry

func (m *RMultimap) ContainsEntry(ctx context.Context, key, value any) (bool, error)

ContainsEntry reports whether (key, value) is associated.

func (*RMultimap) ContainsKey

func (m *RMultimap) ContainsKey(ctx context.Context, key any) (bool, error)

ContainsKey reports whether key has any association.

func (*RMultimap) ContainsValue added in v0.2.13

func (m *RMultimap) ContainsValue(ctx context.Context, value any) (bool, error)

ContainsValue reports whether any key is associated with value.

func (*RMultimap) Delete

func (o *RMultimap) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RMultimap) Entries added in v0.2.13

func (m *RMultimap) Entries(ctx context.Context) ([]MultimapEntry, error)

Entries returns every key/value association.

func (*RMultimap) Exists

func (o *RMultimap) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RMultimap) Expire

func (o *RMultimap) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RMultimap) ExpireAt

func (o *RMultimap) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RMultimap) FastRemove added in v0.2.13

func (m *RMultimap) FastRemove(ctx context.Context, keys ...any) (int64, error)

FastRemove drops keys and their value collections in one operation.

func (*RMultimap) FastRemoveValue added in v0.2.13

func (m *RMultimap) FastRemoveValue(ctx context.Context, values ...any) (int64, error)

FastRemoveValue removes one occurrence of each value from every key.

func (*RMultimap) FastReplaceValues added in v0.2.13

func (m *RMultimap) FastReplaceValues(ctx context.Context, key any, values ...any) error

FastReplaceValues replaces all values associated with key without returning the old values.

func (*RMultimap) Get

func (m *RMultimap) Get(ctx context.Context, key any) ([]any, error)

Get returns all values associated with key (decoded).

func (*RMultimap) GetFairLock added in v0.2.13

func (m *RMultimap) GetFairLock(key any) *RFairLock

GetFairLock returns the Redisson fair lock associated with a multimap key.

func (*RMultimap) GetLock added in v0.2.13

func (m *RMultimap) GetLock(key any) *RLock

GetLock returns the Redisson lock associated with a multimap key.

func (*RMultimap) GetReadWriteLock added in v0.2.13

func (m *RMultimap) GetReadWriteLock(key any) *RReadWriteLock

GetReadWriteLock returns the Redisson read-write lock for a multimap key.

func (*RMultimap) GetSemaphore added in v0.2.13

func (m *RMultimap) GetSemaphore(key any) *RSemaphore

GetSemaphore returns the Redisson semaphore associated with a multimap key.

func (*RMultimap) IsEmpty added in v0.2.13

func (m *RMultimap) IsEmpty(ctx context.Context) (bool, error)

IsEmpty reports whether the multimap has no associations.

func (*RMultimap) KeySet

func (m *RMultimap) KeySet(ctx context.Context) ([]any, error)

KeySet returns all keys (decoded).

func (*RMultimap) KeySize added in v0.2.13

func (m *RMultimap) KeySize(ctx context.Context) (int64, error)

KeySize returns the number of keys in the multimap index.

func (*RMultimap) Name

func (o *RMultimap) Name() string

Name returns the Redis key name of the object.

func (*RMultimap) Put

func (m *RMultimap) Put(ctx context.Context, key, value any) (bool, error)

Put associates value with key. Returns true when a new association was created.

func (*RMultimap) PutAll

func (m *RMultimap) PutAll(ctx context.Context, key any, values ...any) (bool, error)

PutAll associates multiple values with key.

func (*RMultimap) ReadAllKeySet added in v0.2.13

func (m *RMultimap) ReadAllKeySet(ctx context.Context) ([]any, error)

ReadAllKeySet is the eager KeySet alias used by Redisson.

func (*RMultimap) RemainTTL

func (o *RMultimap) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RMultimap) RemoveAll

func (m *RMultimap) RemoveAll(ctx context.Context, key any) (bool, error)

RemoveAll drops every association of key.

func (*RMultimap) RemoveEntry

func (m *RMultimap) RemoveEntry(ctx context.Context, key, value any) (bool, error)

RemoveEntry removes one association (key, value). When the collection becomes empty it is deleted along with the hash entry.

func (*RMultimap) Rename

func (o *RMultimap) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RMultimap) ReplaceValues added in v0.2.13

func (m *RMultimap) ReplaceValues(ctx context.Context, key any, values ...any) ([]any, error)

ReplaceValues replaces all values associated with key and returns the old values.

func (*RMultimap) Size

func (m *RMultimap) Size(ctx context.Context) (int64, error)

Size returns the total number of associations across all keys.

func (*RMultimap) Touch

func (o *RMultimap) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RMultimap) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RMultimap) Values added in v0.2.13

func (m *RMultimap) Values(ctx context.Context) ([]any, error)

Values returns all values across all keys.

type RNonReentrantFairLock added in v0.2.13

type RNonReentrantFairLock struct {
	*RFairLock
}

RNonReentrantFairLock is Redisson's FIFO lock variant that rejects a second acquisition by its current holder with ErrLockReentrant.

func (RNonReentrantFairLock) ClearExpire added in v0.2.13

func (o RNonReentrantFairLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RNonReentrantFairLock) Delete added in v0.2.13

func (o RNonReentrantFairLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (RNonReentrantFairLock) Exists added in v0.2.13

func (o RNonReentrantFairLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RNonReentrantFairLock) Expire added in v0.2.13

func (o RNonReentrantFairLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RNonReentrantFairLock) ExpireAt added in v0.2.13

func (o RNonReentrantFairLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RNonReentrantFairLock) Name added in v0.2.13

func (o RNonReentrantFairLock) Name() string

Name returns the Redis key name of the object.

func (RNonReentrantFairLock) RemainTTL added in v0.2.13

func (o RNonReentrantFairLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RNonReentrantFairLock) Rename added in v0.2.13

func (o RNonReentrantFairLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RNonReentrantFairLock) Touch added in v0.2.13

func (o RNonReentrantFairLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RNonReentrantFairLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RNonReentrantLock added in v0.2.13

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

RNonReentrantLock is a distributed lock that refuses re-entry by the same holder (Redisson NonReentrantLock). HASH field still stores the holder id with count always 1.

func (*RNonReentrantLock) ClearExpire added in v0.2.13

func (o *RNonReentrantLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RNonReentrantLock) Delete added in v0.2.13

func (o *RNonReentrantLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RNonReentrantLock) Exists added in v0.2.13

func (o *RNonReentrantLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RNonReentrantLock) Expire added in v0.2.13

func (o *RNonReentrantLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RNonReentrantLock) ExpireAt added in v0.2.13

func (o *RNonReentrantLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RNonReentrantLock) ForceUnlock added in v0.2.13

func (l *RNonReentrantLock) ForceUnlock(ctx context.Context) (bool, error)

ForceUnlock deletes the lock regardless of owner and wakes waiters.

func (*RNonReentrantLock) IsHeldBy added in v0.2.13

func (l *RNonReentrantLock) IsHeldBy(ctx context.Context, clientID string) (bool, error)

IsHeldBy reports whether clientID holds the lock.

func (*RNonReentrantLock) IsLocked added in v0.2.13

func (l *RNonReentrantLock) IsLocked(ctx context.Context) (bool, error)

IsLocked reports whether anyone holds the lock.

func (*RNonReentrantLock) Lock added in v0.2.13

func (l *RNonReentrantLock) Lock(ctx context.Context, clientID string, ttl time.Duration) error

Lock blocks until acquired or ctx cancelled.

func (*RNonReentrantLock) Name added in v0.2.13

func (o *RNonReentrantLock) Name() string

Name returns the Redis key name of the object.

func (*RNonReentrantLock) RemainTTL added in v0.2.13

func (o *RNonReentrantLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RNonReentrantLock) RemainTimeToLive added in v0.2.13

func (l *RNonReentrantLock) RemainTimeToLive(ctx context.Context) (time.Duration, error)

RemainTimeToLive returns the remaining lock lease.

func (*RNonReentrantLock) Rename added in v0.2.13

func (o *RNonReentrantLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RNonReentrantLock) Touch added in v0.2.13

func (o *RNonReentrantLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RNonReentrantLock) TryLock added in v0.2.13

func (l *RNonReentrantLock) TryLock(ctx context.Context, clientID string, ttl time.Duration) (bool, error)

TryLock attempts one acquisition.

func (*RNonReentrantLock) TryLockWait added in v0.2.13

func (l *RNonReentrantLock) TryLockWait(ctx context.Context, clientID string, wait, ttl time.Duration) (bool, error)

TryLockWait waits up to wait for the lock.

func (o *RNonReentrantLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RNonReentrantLock) Unlock added in v0.2.13

func (l *RNonReentrantLock) Unlock(ctx context.Context, clientID string) error

Unlock releases the lock when held by clientID.

type RPatternTopic

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

RPatternTopic subscribes to a glob pattern (PSUBSCRIBE).

func (*RPatternTopic) ClearExpire

func (o *RPatternTopic) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RPatternTopic) CountListeners added in v0.2.13

func (t *RPatternTopic) CountListeners() int

CountListeners returns the number of local pattern listeners.

func (*RPatternTopic) Delete

func (o *RPatternTopic) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RPatternTopic) Exists

func (o *RPatternTopic) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RPatternTopic) Expire

func (o *RPatternTopic) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RPatternTopic) ExpireAt

func (o *RPatternTopic) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RPatternTopic) Name

func (o *RPatternTopic) Name() string

Name returns the Redis key name of the object.

func (*RPatternTopic) RemainTTL

func (o *RPatternTopic) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RPatternTopic) RemoveAllListeners added in v0.2.13

func (t *RPatternTopic) RemoveAllListeners()

RemoveAllListeners unregisters every local pattern listener.

func (*RPatternTopic) Rename

func (o *RPatternTopic) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RPatternTopic) Subscribe

func (t *RPatternTopic) Subscribe(listener func(channel string, msg any)) (int, error)

Subscribe registers a pattern listener, blocking until confirmed.

func (*RPatternTopic) Touch

func (o *RPatternTopic) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RPatternTopic) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RPatternTopic) Unsubscribe

func (t *RPatternTopic) Unsubscribe(id int) bool

Unsubscribe removes a pattern listener.

type RPermitExpirableSemaphore added in v0.2.4

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

RPermitExpirableSemaphore is a semaphore whose permits are individually leased and expire on their own, wire-compatible with Redisson's RedissonPermitExpirableSemaphore:

STRING {name}             available permit counter
ZSET   {name}:timeout     issued permits (member = opaque permit id,
                          score = absolute expiry epoch ms)
PUBSUB redisson_sc:{name} release wake-up channel

Each acquire returns a unique permit id; only that id can release the permit. Expired permits are reclaimed into the pool atomically on the next acquire (Lua).

func (*RPermitExpirableSemaphore) Acquire added in v0.2.4

Acquire blocks until a permit is leased or ctx ends (ErrNoPermit). Wakes on release via the redisson_sc channel with a 1s fallback.

func (*RPermitExpirableSemaphore) AcquireN added in v0.2.13

func (s *RPermitExpirableSemaphore) AcquireN(
	ctx context.Context,
	permits int,
	lease time.Duration,
) ([]string, error)

AcquireN blocks until all requested permits can be leased atomically.

func (*RPermitExpirableSemaphore) AcquiredPermits added in v0.2.4

func (s *RPermitExpirableSemaphore) AcquiredPermits(ctx context.Context) (int64, error)

AcquiredPermits returns the currently leased permit count.

func (*RPermitExpirableSemaphore) AddPermits added in v0.2.13

func (s *RPermitExpirableSemaphore) AddPermits(ctx context.Context, permits int64) error

AddPermits adjusts the available counter by permits.

func (*RPermitExpirableSemaphore) AvailablePermits added in v0.2.4

func (s *RPermitExpirableSemaphore) AvailablePermits(ctx context.Context) (int64, error)

AvailablePermits returns the free permit count.

func (*RPermitExpirableSemaphore) ClearExpire added in v0.2.4

func (o *RPermitExpirableSemaphore) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RPermitExpirableSemaphore) Delete added in v0.2.4

Delete removes the counter and the permit zset.

func (*RPermitExpirableSemaphore) Exists added in v0.2.4

func (o *RPermitExpirableSemaphore) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RPermitExpirableSemaphore) Expire added in v0.2.4

func (o *RPermitExpirableSemaphore) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RPermitExpirableSemaphore) ExpireAt added in v0.2.4

func (o *RPermitExpirableSemaphore) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RPermitExpirableSemaphore) GetPermits added in v0.2.13

func (s *RPermitExpirableSemaphore) GetPermits(ctx context.Context) (int64, error)

GetPermits returns the configured pool size (available plus acquired).

func (*RPermitExpirableSemaphore) LeaseTime added in v0.2.4

func (s *RPermitExpirableSemaphore) LeaseTime(ctx context.Context, permitID string) (time.Duration, error)

LeaseTime returns the remaining lease of a permit (-1 when unknown).

func (*RPermitExpirableSemaphore) Name added in v0.2.4

func (o *RPermitExpirableSemaphore) Name() string

Name returns the Redis key name of the object.

func (*RPermitExpirableSemaphore) Release added in v0.2.4

func (s *RPermitExpirableSemaphore) Release(ctx context.Context, permitID string) (bool, error)

Release returns a leased permit. Returns false for an unknown or expired permit id.

func (*RPermitExpirableSemaphore) ReleaseAll added in v0.2.13

func (s *RPermitExpirableSemaphore) ReleaseAll(ctx context.Context, permitIDs ...string) (int64, error)

ReleaseAll returns all known permit ids and reports how many were released.

func (*RPermitExpirableSemaphore) RemainTTL added in v0.2.4

func (o *RPermitExpirableSemaphore) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RPermitExpirableSemaphore) Rename added in v0.2.4

func (o *RPermitExpirableSemaphore) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RPermitExpirableSemaphore) SetPermits added in v0.2.13

func (s *RPermitExpirableSemaphore) SetPermits(ctx context.Context, permits int64) error

SetPermits changes the configured pool size while preserving acquisitions.

func (*RPermitExpirableSemaphore) Touch added in v0.2.4

func (o *RPermitExpirableSemaphore) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RPermitExpirableSemaphore) TryAcquire added in v0.2.4

func (s *RPermitExpirableSemaphore) TryAcquire(ctx context.Context, lease time.Duration) (string, error)

TryAcquire leases one permit for lease duration, returning its id ("" when none available).

func (*RPermitExpirableSemaphore) TryAcquireN added in v0.2.13

func (s *RPermitExpirableSemaphore) TryAcquireN(
	ctx context.Context,
	permits int,
	lease time.Duration,
) ([]string, error)

TryAcquireN atomically leases permits, returning an empty slice when the requested number isn't available.

func (*RPermitExpirableSemaphore) TryAcquireWait added in v0.2.13

func (s *RPermitExpirableSemaphore) TryAcquireWait(
	ctx context.Context,
	lease, wait time.Duration,
) (string, error)

TryAcquireWait waits up to wait for one permit, returning an empty id on timeout.

func (*RPermitExpirableSemaphore) TrySetPermits added in v0.2.4

func (s *RPermitExpirableSemaphore) TrySetPermits(ctx context.Context, permits int64) (bool, error)

TrySetPermits initializes the counter only when it does not exist.

func (o *RPermitExpirableSemaphore) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RPermitExpirableSemaphore) UpdateLeaseTime added in v0.2.4

func (s *RPermitExpirableSemaphore) UpdateLeaseTime(ctx context.Context, permitID string, lease time.Duration) (bool, error)

UpdateLeaseTime extends (or shortens) a permit's lease. Returns false for an unknown permit.

type RPriorityBlockingDeque added in v0.2.13

type RPriorityBlockingDeque struct {
	*RPriorityBlockingQueue
}

RPriorityBlockingDeque adds highest-score (tail) blocking pops via BZPOPMAX. Still ZSET+score semantics — not Java Comparator RPriorityBlockingDeque.

func (RPriorityBlockingDeque) ClearExpire added in v0.2.13

func (o RPriorityBlockingDeque) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RPriorityBlockingDeque) Delete added in v0.2.13

func (o RPriorityBlockingDeque) Delete(ctx context.Context) error

Delete removes the object's key.

func (RPriorityBlockingDeque) Exists added in v0.2.13

func (o RPriorityBlockingDeque) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RPriorityBlockingDeque) Expire added in v0.2.13

func (o RPriorityBlockingDeque) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RPriorityBlockingDeque) ExpireAt added in v0.2.13

func (o RPriorityBlockingDeque) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RPriorityBlockingDeque) Name added in v0.2.13

func (o RPriorityBlockingDeque) Name() string

Name returns the Redis key name of the object.

func (*RPriorityBlockingDeque) PollLastWithTimeout added in v0.2.13

func (q *RPriorityBlockingDeque) PollLastWithTimeout(ctx context.Context, timeout time.Duration) (any, error)

PollLastWithTimeout blocks up to timeout for the highest-score element.

func (RPriorityBlockingDeque) RemainTTL added in v0.2.13

func (o RPriorityBlockingDeque) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RPriorityBlockingDeque) Rename added in v0.2.13

func (o RPriorityBlockingDeque) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RPriorityBlockingDeque) TakeLast added in v0.2.13

func (q *RPriorityBlockingDeque) TakeLast(ctx context.Context) (any, error)

TakeLast blocks for the highest-score element (BZPOPMAX).

func (RPriorityBlockingDeque) Touch added in v0.2.13

func (o RPriorityBlockingDeque) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RPriorityBlockingDeque) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RPriorityBlockingQueue added in v0.2.13

type RPriorityBlockingQueue struct {
	*RPriorityQueue
}

RPriorityBlockingQueue is a blocking wrapper over RPriorityQueue (ZSET + BZPOPMIN). Same compatibility caveat as RPriorityQueue: NOT Java Comparator-based RPriorityBlockingQueue.

func (RPriorityBlockingQueue) ClearExpire added in v0.2.13

func (o RPriorityBlockingQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RPriorityBlockingQueue) Delete added in v0.2.13

func (o RPriorityBlockingQueue) Delete(ctx context.Context) error

Delete removes the object's key.

func (RPriorityBlockingQueue) Exists added in v0.2.13

func (o RPriorityBlockingQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RPriorityBlockingQueue) Expire added in v0.2.13

func (o RPriorityBlockingQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RPriorityBlockingQueue) ExpireAt added in v0.2.13

func (o RPriorityBlockingQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RPriorityBlockingQueue) Name added in v0.2.13

func (o RPriorityBlockingQueue) Name() string

Name returns the Redis key name of the object.

func (*RPriorityBlockingQueue) PollWithTimeout added in v0.2.13

func (q *RPriorityBlockingQueue) PollWithTimeout(ctx context.Context, timeout time.Duration) (any, error)

PollWithTimeout blocks up to timeout for the lowest-score element. Returns (nil, nil) on timeout.

func (RPriorityBlockingQueue) RemainTTL added in v0.2.13

func (o RPriorityBlockingQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RPriorityBlockingQueue) Rename added in v0.2.13

func (o RPriorityBlockingQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RPriorityBlockingQueue) Take added in v0.2.13

Take blocks until an element is available (BZPOPMIN timeout 0) or ctx ends.

func (RPriorityBlockingQueue) Touch added in v0.2.13

func (o RPriorityBlockingQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RPriorityBlockingQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RPriorityDeque added in v0.2.13

type RPriorityDeque struct {
	*RPriorityQueue
}

RPriorityDeque is a non-blocking double-ended view of the same ZSET priority queue (ZPOPMIN / ZPOPMAX). Not Java Comparator RPriorityDeque.

func (RPriorityDeque) ClearExpire added in v0.2.13

func (o RPriorityDeque) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RPriorityDeque) Delete added in v0.2.13

func (o RPriorityDeque) Delete(ctx context.Context) error

Delete removes the object's key.

func (RPriorityDeque) Exists added in v0.2.13

func (o RPriorityDeque) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RPriorityDeque) Expire added in v0.2.13

func (o RPriorityDeque) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RPriorityDeque) ExpireAt added in v0.2.13

func (o RPriorityDeque) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RPriorityDeque) Name added in v0.2.13

func (o RPriorityDeque) Name() string

Name returns the Redis key name of the object.

func (*RPriorityDeque) PeekFirst added in v0.2.13

func (q *RPriorityDeque) PeekFirst(ctx context.Context) (any, error)

PeekFirst returns the lowest-score element without removing it (alias of Peek).

func (*RPriorityDeque) PeekLast added in v0.2.13

func (q *RPriorityDeque) PeekLast(ctx context.Context) (any, error)

PeekLast returns the highest-score element without removing it.

func (*RPriorityDeque) PollFirst added in v0.2.13

func (q *RPriorityDeque) PollFirst(ctx context.Context) (any, error)

PollFirst removes and returns the lowest-score element (alias of Poll).

func (*RPriorityDeque) PollLast added in v0.2.13

func (q *RPriorityDeque) PollLast(ctx context.Context) (any, error)

PollLast removes and returns the highest-score element.

func (RPriorityDeque) RemainTTL added in v0.2.13

func (o RPriorityDeque) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RPriorityDeque) Rename added in v0.2.13

func (o RPriorityDeque) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RPriorityDeque) Touch added in v0.2.13

func (o RPriorityDeque) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RPriorityDeque) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RPriorityQueue added in v0.2.6

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

RPriorityQueue is a ZSET-backed priority queue: lower score is polled first. Members are codec-encoded.

Compatibility note: this is NOT Redisson's RPriorityQueue (LIST + Comparator). Java getPriorityQueue() will not interoperate with this structure. Use it as a Redis-native scored priority queue, or read the same ZSET via RScoredSortedSet / raw Redis.

func (*RPriorityQueue) Clear added in v0.2.6

func (q *RPriorityQueue) Clear(ctx context.Context) error

Clear removes the queue.

func (*RPriorityQueue) ClearExpire added in v0.2.6

func (o *RPriorityQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RPriorityQueue) Delete added in v0.2.6

func (o *RPriorityQueue) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RPriorityQueue) Exists added in v0.2.6

func (o *RPriorityQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RPriorityQueue) Expire added in v0.2.6

func (o *RPriorityQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RPriorityQueue) ExpireAt added in v0.2.6

func (o *RPriorityQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RPriorityQueue) Name added in v0.2.6

func (o *RPriorityQueue) Name() string

Name returns the Redis key name of the object.

func (*RPriorityQueue) Offer added in v0.2.6

func (q *RPriorityQueue) Offer(ctx context.Context, element any, score float64) error

Offer adds an element with the given priority score.

func (*RPriorityQueue) Peek added in v0.2.6

func (q *RPriorityQueue) Peek(ctx context.Context) (any, error)

Peek returns the highest-priority element without removing it.

func (*RPriorityQueue) PeekScore added in v0.2.6

func (q *RPriorityQueue) PeekScore(ctx context.Context, element any) (float64, bool, error)

PeekScore returns the priority of an element (ok=false when absent).

func (*RPriorityQueue) Poll added in v0.2.6

func (q *RPriorityQueue) Poll(ctx context.Context) (any, error)

Poll removes and returns the highest-priority element (lowest score). Returns (nil, nil) when empty.

func (*RPriorityQueue) RemainTTL added in v0.2.6

func (o *RPriorityQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RPriorityQueue) Remove added in v0.2.6

func (q *RPriorityQueue) Remove(ctx context.Context, element any) error

Remove deletes an element.

func (*RPriorityQueue) Rename added in v0.2.6

func (o *RPriorityQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RPriorityQueue) Size added in v0.2.6

func (q *RPriorityQueue) Size(ctx context.Context) (int64, error)

Size returns the number of queued elements.

func (*RPriorityQueue) Touch added in v0.2.6

func (o *RPriorityQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RPriorityQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RQueue

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

RQueue is a distributed FIFO queue backed by a Redis List. Offer appends to the tail (RPUSH) and Poll removes from the head (LPOP). Elements are codec (JSON) encoded, Redisson-compatible.

func (*RQueue) Clear

func (q *RQueue) Clear(ctx context.Context) error

Clear removes all elements.

func (*RQueue) ClearExpire

func (o *RQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RQueue) Delete

func (o *RQueue) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RQueue) Exists

func (o *RQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RQueue) Expire

func (o *RQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RQueue) ExpireAt

func (o *RQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RQueue) Name

func (o *RQueue) Name() string

Name returns the Redis key name of the object.

func (*RQueue) Offer

func (q *RQueue) Offer(ctx context.Context, values ...any) error

Offer adds values to the tail of the queue.

func (*RQueue) Peek

func (q *RQueue) Peek(ctx context.Context) (any, error)

Peek returns the head element without removing it. Returns (nil, nil) when the queue is empty.

func (*RQueue) PeekInto added in v0.2.13

func (q *RQueue) PeekInto(ctx context.Context, target any) (bool, error)

PeekInto decodes the head into target without removing it. Returns false when the queue is empty.

func (*RQueue) Poll

func (q *RQueue) Poll(ctx context.Context) (any, error)

Poll removes and returns the head element. Returns (nil, nil) when the queue is empty.

func (*RQueue) PollInto added in v0.2.13

func (q *RQueue) PollInto(ctx context.Context, target any) (bool, error)

PollInto removes the head and decodes it into target. Returns false when the queue is empty.

func (*RQueue) ReadAll added in v0.2.13

func (q *RQueue) ReadAll(ctx context.Context) ([]any, error)

ReadAll returns all elements without removing them (LRANGE 0 -1).

func (*RQueue) RemainTTL

func (o *RQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RQueue) Rename

func (o *RQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RQueue) Size

func (q *RQueue) Size(ctx context.Context) (int64, error)

Size returns the number of elements in the queue.

func (*RQueue) Take

func (q *RQueue) Take(ctx context.Context, timeout time.Duration) (any, error)

Take blocks until an element is available or ctx is cancelled, then removes and returns it. Sub-second timeouts are rounded up to 1s (BLPOP has second granularity).

func (*RQueue) Touch

func (o *RQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RRateLimiter

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

RRateLimiter is a distributed sliding-window rate limiter, wire-compatible with Redisson 4.6.x:

HASH   {name}             config: rate, interval (ms), keepAliveTime, type
STRING {name}:value       remaining permits in the window
ZSET   {name}:permits     claims: score = claim ts(ms),
                          member = 0x10 + 16B client UUID + LE uint32 permits

PER_CLIENT appends the client id to the value/permits keys.

Example
package main

import (
	"context"
	"fmt"
	"time"

	redi "github.com/linkerlin/redi.go"
)

func main() {
	client, err := redi.NewClient(redi.DefaultConfig())
	if err != nil {
		fmt.Println("skip:", err)
		return
	}
	defer client.Close() //nolint:errcheck // example
	ctx := context.Background()

	// Config is persisted in Redis: every process sharing the name
	// shares the same sliding window. (Self-cleanup INCLUDING the
	// companion keys keeps the example re-runnable.)
	_, _ = client.GetKeys().Delete(ctx, "demo:api", "{demo:api}:value", "{demo:api}:permits")
	rl := client.GetRateLimiter("demo:api")
	_, _ = rl.TrySetRate(ctx, redi.RateTypeOverall, 2, time.Minute)

	first, _ := rl.TryAcquire(ctx, 1)
	second, _ := rl.TryAcquire(ctx, 1)
	third, _ := rl.TryAcquire(ctx, 1)
	fmt.Println(first, second, third)
}
Output:
true true false

func (*RRateLimiter) Acquire

func (r *RRateLimiter) Acquire(ctx context.Context, permits int64) error

Acquire blocks until permits are granted or ctx is cancelled.

func (*RRateLimiter) AvailablePermits

func (r *RRateLimiter) AvailablePermits(ctx context.Context) (int64, error)

AvailablePermits returns the permits currently available in the window.

func (*RRateLimiter) ClearExpire

func (o *RRateLimiter) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RRateLimiter) Delete

func (r *RRateLimiter) Delete(ctx context.Context) error

Delete removes config, value and permits keys.

func (*RRateLimiter) Exists

func (o *RRateLimiter) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RRateLimiter) Expire

func (o *RRateLimiter) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RRateLimiter) ExpireAt

func (o *RRateLimiter) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RRateLimiter) GetConfig added in v0.2.13

func (r *RRateLimiter) GetConfig(ctx context.Context) (RateLimiterConfig, error)

GetConfig loads the persisted config from Redis (empty when unset).

func (*RRateLimiter) Name

func (o *RRateLimiter) Name() string

Name returns the Redis key name of the object.

func (*RRateLimiter) Release added in v0.2.13

func (r *RRateLimiter) Release(ctx context.Context, permits int64) error

Release returns permits to the pool immediately (capped at rate), without waiting for the sliding window to expire — Redisson release(permits).

func (*RRateLimiter) RemainTTL

func (o *RRateLimiter) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RRateLimiter) Rename

func (o *RRateLimiter) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RRateLimiter) SetRate

func (r *RRateLimiter) SetRate(ctx context.Context, rateType RateType, rate int64, interval time.Duration) error

SetRate (over)writes the persisted rate config.

func (*RRateLimiter) SetRateWithKeepAlive added in v0.2.13

func (r *RRateLimiter) SetRateWithKeepAlive(
	ctx context.Context, rateType RateType, rate int64, interval, keepAlive time.Duration,
) error

SetRateWithKeepAlive writes rate config and optional keepAlive TTL on the config HASH and active value/permits keys (Redisson keepAliveTime).

func (*RRateLimiter) Touch

func (o *RRateLimiter) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RRateLimiter) TryAcquire

func (r *RRateLimiter) TryAcquire(ctx context.Context, permits int64) (bool, error)

TryAcquire takes permits when the window allows it.

func (*RRateLimiter) TryAcquireWait added in v0.2.13

func (r *RRateLimiter) TryAcquireWait(
	ctx context.Context, permits int64, wait time.Duration,
) (bool, error)

TryAcquireWait waits up to wait for permits to become available.

func (*RRateLimiter) TrySetRate

func (r *RRateLimiter) TrySetRate(ctx context.Context, rateType RateType, rate int64, interval time.Duration) (bool, error)

TrySetRate sets the rate config only when not yet configured.

func (*RRateLimiter) TrySetRateWithKeepAlive added in v0.2.13

func (r *RRateLimiter) TrySetRateWithKeepAlive(
	ctx context.Context, rateType RateType, rate int64, interval, keepAlive time.Duration,
) (bool, error)

TrySetRateWithKeepAlive is TrySetRate plus config/companion TTL (Java keepAliveTime).

func (o *RRateLimiter) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RRateLimiter) UpdateRate added in v0.2.13

func (r *RRateLimiter) UpdateRate(
	ctx context.Context, rateType RateType, rate int64, interval time.Duration,
) (bool, error)

UpdateRate updates an initialized limiter and resets its active window. It returns false when the limiter doesn't exist.

func (*RRateLimiter) UpdateRateWithKeepAlive added in v0.2.13

func (r *RRateLimiter) UpdateRateWithKeepAlive(
	ctx context.Context, rateType RateType, rate int64, interval, keepAlive time.Duration,
) (bool, error)

UpdateRateWithKeepAlive is UpdateRate with an explicit keepAlive.

type RReadWriteLock

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

RReadWriteLock is a distributed read-write lock using a single Redis HASH (wire-compatible with Redisson's RedissonReadWriteLock layout):

HASH {name}
  mode                    = "read" | "write" | "read-write"
  {clientID}              = read-lock hold count
  {clientID}:write        = write-lock hold count

All acquire/release paths are atomic Lua. Channel redisson_rwlock:{name} wakes waiters on full release (message 0 after write release, 1 after read release, matching Redisson's LockPubSub messages).

Unlike RLock there is no watchdog: leases expire after the TTL (30s default).

func (*RReadWriteLock) ReadLock

func (l *RReadWriteLock) ReadLock() *RReadWriteSubLock

ReadLock returns the read (shared) lock view.

func (*RReadWriteLock) WriteLock

func (l *RReadWriteLock) WriteLock() *RReadWriteSubLock

WriteLock returns the write (exclusive) lock view.

type RReadWriteSubLock

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

RReadWriteSubLock is either the read or the write half of an RReadWriteLock.

func (*RReadWriteSubLock) ClearExpire

func (o *RReadWriteSubLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RReadWriteSubLock) Delete

func (o *RReadWriteSubLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RReadWriteSubLock) Exists

func (o *RReadWriteSubLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RReadWriteSubLock) Expire

func (o *RReadWriteSubLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RReadWriteSubLock) ExpireAt

func (o *RReadWriteSubLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RReadWriteSubLock) ForceUnlock

func (s *RReadWriteSubLock) ForceUnlock(ctx context.Context) (bool, error)

ForceUnlock deletes the lock key and wakes all waiters.

func (*RReadWriteSubLock) HoldCount added in v0.2.13

func (s *RReadWriteSubLock) HoldCount(ctx context.Context, clientID string) (int64, error)

HoldCount returns the re-entrancy count held by clientID.

func (*RReadWriteSubLock) IsHeldBy

func (s *RReadWriteSubLock) IsHeldBy(ctx context.Context, clientID string) (bool, error)

IsHeldBy reports whether clientID holds this half.

func (*RReadWriteSubLock) IsLocked

func (s *RReadWriteSubLock) IsLocked(ctx context.Context) (bool, error)

IsLocked reports whether this half is held (write half checks the mode).

func (*RReadWriteSubLock) Lock

func (s *RReadWriteSubLock) Lock(ctx context.Context, clientID string, ttl time.Duration) error

Lock blocks until acquired, waking on the rwlock channel.

func (*RReadWriteSubLock) Name

func (o *RReadWriteSubLock) Name() string

Name returns the Redis key name of the object.

func (*RReadWriteSubLock) RemainTTL

func (o *RReadWriteSubLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RReadWriteSubLock) RemainTimeToLive added in v0.2.13

func (s *RReadWriteSubLock) RemainTimeToLive(ctx context.Context) (time.Duration, error)

RemainTimeToLive returns the remaining lease for the shared lock key.

func (*RReadWriteSubLock) Rename

func (o *RReadWriteSubLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RReadWriteSubLock) Touch

func (o *RReadWriteSubLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RReadWriteSubLock) TryLock

func (s *RReadWriteSubLock) TryLock(ctx context.Context, clientID string, ttl time.Duration) (bool, error)

TryLock attempts one acquisition. With ttl <= 0 the watchdog renews the lease (see Lock).

func (*RReadWriteSubLock) TryLockWait added in v0.2.13

func (s *RReadWriteSubLock) TryLockWait(
	ctx context.Context, clientID string, wait, ttl time.Duration,
) (bool, error)

TryLockWait tries to acquire until wait elapses or ctx is cancelled.

func (o *RReadWriteSubLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RReadWriteSubLock) Unlock

func (s *RReadWriteSubLock) Unlock(ctx context.Context, clientID string) error

Unlock releases one hold. Returns ErrLockNotHeld when not the owner. The watchdog is stopped only after the ownership check succeeds and the hold count reaches zero.

type RRedLock added in v0.2.13

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

RRedLock implements RedissonRedLock's majority policy over independent RLock members. Members may belong to different Client instances.

func (*RRedLock) Lock added in v0.2.13

func (r *RRedLock) Lock(
	ctx context.Context, clientID string, ttl, wait time.Duration,
) error

Lock acquires a strict majority or returns ErrRedLockFailed when wait elapses. Context cancellation is returned unchanged.

func (*RRedLock) TryLock added in v0.2.13

func (r *RRedLock) TryLock(
	ctx context.Context, clientID string, ttl time.Duration,
) (bool, error)

TryLock attempts every member once and succeeds when a strict majority is acquired. A failed minority is tolerated; failure rolls back acquired locks.

func (*RRedLock) TryLockWait added in v0.2.13

func (r *RRedLock) TryLockWait(
	ctx context.Context, clientID string, wait, ttl time.Duration,
) (bool, error)

TryLockWait attempts to acquire a strict majority within wait. Like RedissonRedLock, each member receives at most remain/len(locks) wait time.

func (*RRedLock) Unlock added in v0.2.13

func (r *RRedLock) Unlock(ctx context.Context, clientID string) error

Unlock best-effort unlocks every member, matching RedissonRedLock. Members held by another owner are ignored.

type RRedisNodes added in v0.2.13

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

RRedisNodes is a thin topology probe analogous to Redisson getRedisNodes.

func (*RRedisNodes) Info added in v0.2.13

func (n *RRedisNodes) Info(ctx context.Context) (string, error)

Info returns INFO server section (best-effort; cluster returns one node).

func (*RRedisNodes) Mode added in v0.2.13

func (n *RRedisNodes) Mode() Mode

Mode returns the configured topology.

func (*RRedisNodes) Ping added in v0.2.13

func (n *RRedisNodes) Ping(ctx context.Context) error

Ping checks connectivity.

func (*RRedisNodes) String added in v0.2.13

func (n *RRedisNodes) String() string

String describes the mode and addresses.

type RReliableTopic added in v0.2.4

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

RReliableTopic is a reliable pub/sub topic backed by a Redis Stream, wire-compatible with Redisson's RedissonReliableTopic (source-verified):

STREAM {name}            messages: XADD field "m" = codec-encoded payload
GROUP  {subscriberId}    ONE CONSUMER GROUP PER SUBSCRIBER (Java
                        semantics: every group receives every message —
                        unlike one-group-many-consumers, which would
                        load-balance instead of broadcasting)
ZSET   {name}:timeout    subscriber liveness (watchdog deadline, score=ts)

Messages are acked only after the listener returns, so a crash mid-callback redelivers (reliable delivery).

func (*RReliableTopic) ClearExpire added in v0.2.4

func (o *RReliableTopic) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RReliableTopic) CountListeners added in v0.2.13

func (t *RReliableTopic) CountListeners() int

CountListeners returns the number of local reliable listeners.

func (*RReliableTopic) CountSubscribers added in v0.2.4

func (t *RReliableTopic) CountSubscribers(ctx context.Context) (int64, error)

CountSubscribers returns the number of active subscriber groups.

func (*RReliableTopic) Delete added in v0.2.4

func (t *RReliableTopic) Delete(ctx context.Context) error

Delete stops all listeners and removes the topic, its timeout zset and every subscriber group.

func (*RReliableTopic) Exists added in v0.2.4

func (o *RReliableTopic) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RReliableTopic) Expire added in v0.2.4

func (o *RReliableTopic) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RReliableTopic) ExpireAt added in v0.2.4

func (o *RReliableTopic) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RReliableTopic) Name added in v0.2.4

func (o *RReliableTopic) Name() string

Name returns the Redis key name of the object.

func (*RReliableTopic) Publish added in v0.2.4

func (t *RReliableTopic) Publish(ctx context.Context, message any) (int64, error)

Publish appends a message for every subscriber group (XADD field "m"). Returns the number of subscriber groups (Java semantics: XINFO GROUPS).

func (*RReliableTopic) RemainTTL added in v0.2.4

func (o *RReliableTopic) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RReliableTopic) RemoveAllListeners added in v0.2.13

func (t *RReliableTopic) RemoveAllListeners()

RemoveAllListeners unregisters every local listener and subscriber group.

func (*RReliableTopic) Rename added in v0.2.4

func (o *RReliableTopic) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RReliableTopic) Size added in v0.2.4

func (t *RReliableTopic) Size(ctx context.Context) (int64, error)

Size returns the number of messages in the stream.

func (*RReliableTopic) Subscribe added in v0.2.4

func (t *RReliableTopic) Subscribe(listener func(msg any)) (string, error)

Subscribe registers a listener that receives every message (its own consumer group, from the beginning of the stream like Java's StreamMessageId.ALL). Blocks until the group is created.

func (*RReliableTopic) Touch added in v0.2.4

func (o *RReliableTopic) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RReliableTopic) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RReliableTopic) Unsubscribe added in v0.2.4

func (t *RReliableTopic) Unsubscribe(id string)

Unsubscribe stops a listener and removes its group and liveness entry.

type RRingBuffer added in v0.2.12

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

RRingBuffer is a capacity-bounded FIFO that evicts the oldest element on overflow, wire-compatible with Redisson's RedissonRingBuffer:

LIST {name}                    elements (RPUSH tail, LPOP on overflow)
STRING redisson_rb:{name}      capacity (plain decimal, SETNX)

func (*RRingBuffer) Add added in v0.2.12

func (r *RRingBuffer) Add(ctx context.Context, value any) error

Add appends an element, evicting the oldest on overflow.

func (*RRingBuffer) AddAll added in v0.2.12

func (r *RRingBuffer) AddAll(ctx context.Context, values ...any) error

AddAll appends multiple elements, trimming to capacity in one pass.

func (*RRingBuffer) Capacity added in v0.2.12

func (r *RRingBuffer) Capacity(ctx context.Context) (int64, error)

Capacity returns the configured capacity (0 when undefined).

func (*RRingBuffer) Clear added in v0.2.13

func (r *RRingBuffer) Clear(ctx context.Context) error

Clear removes queued elements while preserving the configured capacity.

func (*RRingBuffer) ClearExpire added in v0.2.12

func (o *RRingBuffer) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RRingBuffer) Delete added in v0.2.12

func (r *RRingBuffer) Delete(ctx context.Context) error

Delete removes the buffer and its settings key.

func (*RRingBuffer) Exists added in v0.2.12

func (o *RRingBuffer) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RRingBuffer) Expire added in v0.2.12

func (o *RRingBuffer) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RRingBuffer) ExpireAt added in v0.2.12

func (o *RRingBuffer) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RRingBuffer) Name added in v0.2.12

func (o *RRingBuffer) Name() string

Name returns the Redis key name of the object.

func (*RRingBuffer) Offer added in v0.2.13

func (r *RRingBuffer) Offer(ctx context.Context, value any) error

Offer is the queue-style alias of Add.

func (*RRingBuffer) Peek added in v0.2.13

func (r *RRingBuffer) Peek(ctx context.Context) (any, error)

Peek returns the oldest element without removing it.

func (*RRingBuffer) Poll added in v0.2.13

func (r *RRingBuffer) Poll(ctx context.Context) (any, error)

Poll removes and returns the oldest element, or (nil, nil) when empty.

func (*RRingBuffer) ReadAll added in v0.2.13

func (r *RRingBuffer) ReadAll(ctx context.Context) ([]any, error)

ReadAll returns all elements from oldest to newest.

func (*RRingBuffer) ReadNewest added in v0.2.12

func (r *RRingBuffer) ReadNewest(ctx context.Context, count int64) ([]any, error)

ReadNewest returns up to count elements from the tail (newest last, same relative order as stored — matching Java's range(-count, -1)).

func (*RRingBuffer) ReadOldest added in v0.2.12

func (r *RRingBuffer) ReadOldest(ctx context.Context, count int64) ([]any, error)

ReadOldest returns up to count elements from the head (oldest first).

func (*RRingBuffer) RemainTTL added in v0.2.12

func (o *RRingBuffer) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RRingBuffer) RemainingCapacity added in v0.2.12

func (r *RRingBuffer) RemainingCapacity(ctx context.Context) (int64, error)

RemainingCapacity returns capacity minus current size (>= 0).

func (*RRingBuffer) Rename added in v0.2.12

func (o *RRingBuffer) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RRingBuffer) SetCapacity added in v0.2.12

func (r *RRingBuffer) SetCapacity(ctx context.Context, capacity int64) error

func (*RRingBuffer) Size added in v0.2.12

func (r *RRingBuffer) Size(ctx context.Context) (int64, error)

Size returns the current number of elements.

func (*RRingBuffer) Touch added in v0.2.12

func (o *RRingBuffer) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RRingBuffer) TrySetCapacity added in v0.2.12

func (r *RRingBuffer) TrySetCapacity(ctx context.Context, capacity int64) (bool, error)

TrySetCapacity initializes the capacity only when undefined.

func (o *RRingBuffer) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RScoredSortedSet

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

RScoredSortedSet is a distributed sorted set backed by a Redis ZSET. Members are codec (JSON) encoded; scores are float64.

func (*RScoredSortedSet) Add

func (s *RScoredSortedSet) Add(ctx context.Context, member any, score float64) (bool, error)

Add adds member with score. Returns true when newly added.

func (*RScoredSortedSet) AddAllIfAbsent added in v0.2.13

func (s *RScoredSortedSet) AddAllIfAbsent(
	ctx context.Context, entries map[any]float64,
) (int64, error)

AddAllIfAbsent adds only members that aren't already present.

func (*RScoredSortedSet) AddAndGetRank added in v0.2.13

func (s *RScoredSortedSet) AddAndGetRank(
	ctx context.Context, member any, score float64,
) (int64, error)

AddAndGetRank sets score and returns the member's ascending rank.

func (*RScoredSortedSet) AddIfAbsent added in v0.2.13

func (s *RScoredSortedSet) AddIfAbsent(ctx context.Context, member any, score float64) (bool, error)

AddIfAbsent adds member only when it isn't present.

func (*RScoredSortedSet) AddIfExists added in v0.2.13

func (s *RScoredSortedSet) AddIfExists(ctx context.Context, member any, score float64) (bool, error)

AddIfExists updates an existing member and reports whether its score changed.

func (*RScoredSortedSet) AddIfGreater added in v0.2.13

func (s *RScoredSortedSet) AddIfGreater(
	ctx context.Context, member any, score float64,
) (bool, error)

AddIfGreater adds a missing member or updates it only when score is greater.

func (*RScoredSortedSet) AddIfLess added in v0.2.13

func (s *RScoredSortedSet) AddIfLess(
	ctx context.Context, member any, score float64,
) (bool, error)

AddIfLess adds a missing member or updates it only when score is lower.

func (*RScoredSortedSet) AddScore

func (s *RScoredSortedSet) AddScore(ctx context.Context, member any, delta float64) (float64, error)

AddScore adds delta to member's score and returns the new score.

func (*RScoredSortedSet) AddScoreAndGetRank added in v0.2.13

func (s *RScoredSortedSet) AddScoreAndGetRank(
	ctx context.Context, member any, delta float64,
) (int64, error)

AddScoreAndGetRank increments score and returns the new ascending rank.

func (*RScoredSortedSet) Clear

func (s *RScoredSortedSet) Clear(ctx context.Context) error

Clear removes all members.

func (*RScoredSortedSet) ClearExpire

func (o *RScoredSortedSet) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RScoredSortedSet) Contains added in v0.2.13

func (s *RScoredSortedSet) Contains(ctx context.Context, member any) (bool, error)

Contains reports whether member is present.

func (*RScoredSortedSet) Count

func (s *RScoredSortedSet) Count(ctx context.Context, min, max float64) (int64, error)

Count returns the number of members with min <= score <= max.

func (*RScoredSortedSet) Delete

func (o *RScoredSortedSet) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RScoredSortedSet) Diff added in v0.2.13

func (s *RScoredSortedSet) Diff(ctx context.Context, otherNames ...string) ([]any, error)

Diff returns members present in this sorted set but absent from all named sorted sets.

func (*RScoredSortedSet) DiffStore added in v0.2.13

func (s *RScoredSortedSet) DiffStore(
	ctx context.Context, dest string, otherNames ...string,
) (int64, error)

DiffStore stores the difference in dest and returns its size.

func (*RScoredSortedSet) EntryRange added in v0.2.13

func (s *RScoredSortedSet) EntryRange(
	ctx context.Context, start, stop int64,
) ([]redis.Z, error)

EntryRange returns member/score pairs by ascending rank.

func (*RScoredSortedSet) Exists

func (o *RScoredSortedSet) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RScoredSortedSet) Expire

func (o *RScoredSortedSet) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RScoredSortedSet) ExpireAt

func (o *RScoredSortedSet) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RScoredSortedSet) First added in v0.2.13

func (s *RScoredSortedSet) First(ctx context.Context) (any, error)

First returns the lowest-score member without removing it.

func (*RScoredSortedSet) FirstEntry added in v0.2.13

func (s *RScoredSortedSet) FirstEntry(ctx context.Context) (*redis.Z, error)

FirstEntry returns the lowest-score member and score, or nil when empty.

func (*RScoredSortedSet) FirstScore added in v0.2.13

func (s *RScoredSortedSet) FirstScore(ctx context.Context) (float64, error)

FirstScore returns the lowest score, or 0 when empty.

func (*RScoredSortedSet) Intersection added in v0.2.13

func (s *RScoredSortedSet) Intersection(ctx context.Context, otherNames ...string) ([]any, error)

Intersection returns members present in this sorted set and every named sorted set. Redis sums scores when determining the result ordering.

func (*RScoredSortedSet) IntersectionStore added in v0.2.13

func (s *RScoredSortedSet) IntersectionStore(
	ctx context.Context, dest string, otherNames ...string,
) (int64, error)

IntersectionStore stores the intersection in dest and returns its size.

func (*RScoredSortedSet) Last added in v0.2.13

func (s *RScoredSortedSet) Last(ctx context.Context) (any, error)

Last returns the highest-score member without removing it.

func (*RScoredSortedSet) LastEntry added in v0.2.13

func (s *RScoredSortedSet) LastEntry(ctx context.Context) (*redis.Z, error)

LastEntry returns the highest-score member and score, or nil when empty.

func (*RScoredSortedSet) LastScore added in v0.2.13

func (s *RScoredSortedSet) LastScore(ctx context.Context) (float64, error)

LastScore returns the highest score, or 0 when empty.

func (*RScoredSortedSet) Name

func (o *RScoredSortedSet) Name() string

Name returns the Redis key name of the object.

func (*RScoredSortedSet) PollFirst added in v0.2.13

func (s *RScoredSortedSet) PollFirst(ctx context.Context) (any, error)

PollFirst removes and returns the lowest-score member.

func (*RScoredSortedSet) PollFirstEntries added in v0.2.13

func (s *RScoredSortedSet) PollFirstEntries(
	ctx context.Context, count int64,
) ([]redis.Z, error)

PollFirstEntries removes and returns up to count lowest-score entries.

func (*RScoredSortedSet) PollLast added in v0.2.13

func (s *RScoredSortedSet) PollLast(ctx context.Context) (any, error)

PollLast removes and returns the highest-score member.

func (*RScoredSortedSet) PollLastEntries added in v0.2.13

func (s *RScoredSortedSet) PollLastEntries(
	ctx context.Context, count int64,
) ([]redis.Z, error)

PollLastEntries removes and returns up to count highest-score entries in ascending score order, matching Redisson's zrange(-count, -1) result.

func (*RScoredSortedSet) Random added in v0.2.13

func (s *RScoredSortedSet) Random(ctx context.Context) (any, error)

Random returns one random member, or nil when empty.

func (*RScoredSortedSet) RandomN added in v0.2.13

func (s *RScoredSortedSet) RandomN(ctx context.Context, count int64) ([]any, error)

RandomN returns random members using Redis ZRANDMEMBER count semantics.

func (*RScoredSortedSet) Range

func (s *RScoredSortedSet) Range(ctx context.Context, start, stop int64) ([]any, error)

Range returns members in ascending rank order within [start, stop].

func (*RScoredSortedSet) RangeByScore

func (s *RScoredSortedSet) RangeByScore(ctx context.Context, min, max float64) ([]any, error)

RangeByScore returns members with min <= score <= max, ascending.

func (*RScoredSortedSet) RangeReversed added in v0.2.13

func (s *RScoredSortedSet) RangeReversed(ctx context.Context, start, stop int64) ([]any, error)

RangeReversed returns members in descending rank order within [start, stop].

func (*RScoredSortedSet) RangeWithScores

func (s *RScoredSortedSet) RangeWithScores(ctx context.Context, start, stop int64) ([]redis.Z, error)

RangeWithScores returns member/score pairs within [start, stop].

func (*RScoredSortedSet) Rank

func (s *RScoredSortedSet) Rank(ctx context.Context, member any) (int64, error)

Rank returns the 0-based ascending rank. Returns (-1, nil) when absent.

func (*RScoredSortedSet) RemainTTL

func (o *RScoredSortedSet) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RScoredSortedSet) Remove

func (s *RScoredSortedSet) Remove(ctx context.Context, members ...any) error

Remove removes members.

func (*RScoredSortedSet) RemoveRangeByRank added in v0.2.13

func (s *RScoredSortedSet) RemoveRangeByRank(ctx context.Context, start, stop int64) (int64, error)

RemoveRangeByRank removes members with ranks in [start, stop].

func (*RScoredSortedSet) RemoveRangeByScore added in v0.2.13

func (s *RScoredSortedSet) RemoveRangeByScore(ctx context.Context, min, max float64) (int64, error)

RemoveRangeByScore removes members with min <= score <= max.

func (*RScoredSortedSet) Rename

func (o *RScoredSortedSet) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RScoredSortedSet) RevRank added in v0.2.13

func (s *RScoredSortedSet) RevRank(ctx context.Context, member any) (int64, error)

RevRank returns the 0-based descending rank. Returns (-1, nil) when absent.

func (*RScoredSortedSet) Score

func (s *RScoredSortedSet) Score(ctx context.Context, member any) (float64, error)

Score returns member's score. Returns (0, nil) when member is absent.

func (*RScoredSortedSet) Size

func (s *RScoredSortedSet) Size(ctx context.Context) (int64, error)

Size returns the number of members.

func (*RScoredSortedSet) Touch

func (o *RScoredSortedSet) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RScoredSortedSet) TryAdd added in v0.2.13

func (s *RScoredSortedSet) TryAdd(ctx context.Context, member any, score float64) (bool, error)

TryAdd is the Redisson-style alias of AddIfAbsent.

func (*RScoredSortedSet) Union added in v0.2.13

func (s *RScoredSortedSet) Union(ctx context.Context, otherNames ...string) ([]any, error)

Union returns members present in this sorted set or any named sorted set. Redis sums scores for members present in multiple sets.

func (*RScoredSortedSet) UnionStore added in v0.2.13

func (s *RScoredSortedSet) UnionStore(
	ctx context.Context, dest string, otherNames ...string,
) (int64, error)

UnionStore stores the union in dest and returns its size.

func (o *RScoredSortedSet) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RScript

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

RScript evaluates Lua scripts with cached digests (EVAL/EVALSHA), mirroring Redisson's RScript.

func (*RScript) Eval

func (s *RScript) Eval(ctx context.Context, script string, rt ScriptReturnType, keys []string, values ...any) (any, error)

Eval runs a script with keys and argument values, casting the reply per rt. A Lua nil reply decodes to (nil, nil).

func (*RScript) EvalSha

func (s *RScript) EvalSha(ctx context.Context, sha string, rt ScriptReturnType, keys []string, values ...any) (any, error)

EvalSha runs a script by SHA digest (the script must already be loaded).

func (*RScript) ScriptExists

func (s *RScript) ScriptExists(ctx context.Context, shas ...string) ([]bool, error)

ScriptExists reports which digests are cached on the server.

func (*RScript) ScriptLoad

func (s *RScript) ScriptLoad(ctx context.Context, script string) (string, error)

ScriptLoad loads a script and returns its SHA digest.

type RSearch added in v0.2.13

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

RSearch is a RediSearch facade (create / search / drop subset).

func (*RSearch) CreateIndex added in v0.2.13

func (s *RSearch) CreateIndex(ctx context.Context, name string, opts IndexOptions, fields ...IndexField) error

CreateIndex creates an index.

func (*RSearch) DropIndex added in v0.2.13

func (s *RSearch) DropIndex(ctx context.Context, name string, deleteDocuments bool) error

DropIndex drops an index; deleteDocuments maps to DD.

func (*RSearch) Search added in v0.2.13

func (s *RSearch) Search(ctx context.Context, name, query string, opts SearchOptions) (SearchResult, error)

Search runs FT.SEARCH.

type RSemaphore

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

RSemaphore is a distributed counting semaphore backed by a Redis String (permit counter), Redisson wire-compatible: channel redisson_sc:{name} wakes blocked acquirers on release.

func (*RSemaphore) Acquire

func (s *RSemaphore) Acquire(ctx context.Context, permits int64) error

Acquire blocks until permits are available or ctx is cancelled. Wakes on release via the redisson_sc channel, with a 1s fallback poll.

func (*RSemaphore) AddPermits

func (s *RSemaphore) AddPermits(ctx context.Context, permits int64) error

AddPermits increases (or, when negative, decreases) the permit counter.

func (*RSemaphore) AvailablePermits

func (s *RSemaphore) AvailablePermits(ctx context.Context) (int64, error)

AvailablePermits returns the current permit count (0 when uninitialized).

func (*RSemaphore) ClearExpire

func (o *RSemaphore) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RSemaphore) Delete

func (o *RSemaphore) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RSemaphore) DrainPermits

func (s *RSemaphore) DrainPermits(ctx context.Context) (int64, error)

DrainPermits takes all available permits and returns how many were taken.

func (*RSemaphore) Exists

func (o *RSemaphore) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RSemaphore) Expire

func (o *RSemaphore) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RSemaphore) ExpireAt

func (o *RSemaphore) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RSemaphore) Name

func (o *RSemaphore) Name() string

Name returns the Redis key name of the object.

func (*RSemaphore) Release

func (s *RSemaphore) Release(ctx context.Context, permits int64) error

Release returns permits and wakes blocked acquirers.

func (*RSemaphore) ReleaseIfExists added in v0.2.13

func (s *RSemaphore) ReleaseIfExists(
	ctx context.Context, permits int64,
) (bool, error)

ReleaseIfExists returns permits only when the semaphore is initialized.

func (*RSemaphore) RemainTTL

func (o *RSemaphore) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RSemaphore) Rename

func (o *RSemaphore) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RSemaphore) Touch

func (o *RSemaphore) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RSemaphore) TryAcquire

func (s *RSemaphore) TryAcquire(ctx context.Context, permits int64) (bool, error)

TryAcquire takes permits when available, returning false otherwise.

func (*RSemaphore) TryAcquireWait added in v0.2.13

func (s *RSemaphore) TryAcquireWait(ctx context.Context, permits int64, wait time.Duration) (bool, error)

TryAcquireWait tries to acquire until wait elapses or ctx is cancelled. Wakes on release via the redisson_sc channel, with a 1s fallback poll.

func (*RSemaphore) TrySetPermits

func (s *RSemaphore) TrySetPermits(ctx context.Context, permits int64) (bool, error)

TrySetPermits initializes the semaphore only when it does not exist.

func (o *RSemaphore) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RSet

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

RSet is a distributed set backed by a Redis Set. Members are codec (JSON) encoded, Redisson-compatible.

func (*RSet) Add

func (s *RSet) Add(ctx context.Context, members ...any) error

Add adds members to the set.

func (*RSet) AddCounted added in v0.2.13

func (s *RSet) AddCounted(ctx context.Context, members ...any) (int64, error)

AddCounted adds members and returns how many were newly inserted (Redisson addAllCounted / SADD).

func (*RSet) Clear

func (s *RSet) Clear(ctx context.Context) error

Clear removes all members.

func (*RSet) ClearExpire

func (o *RSet) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RSet) Contains

func (s *RSet) Contains(ctx context.Context, member any) (bool, error)

Contains reports whether member is in the set.

func (*RSet) CountIntersection added in v0.2.13

func (s *RSet) CountIntersection(
	ctx context.Context, otherNames ...string,
) (int64, error)

CountIntersection returns the intersection cardinality without materializing the members.

func (*RSet) Delete

func (o *RSet) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RSet) Diff added in v0.2.13

func (s *RSet) Diff(ctx context.Context, otherNames ...string) ([]any, error)

Diff returns members present in this set but absent from all named sets.

func (*RSet) DiffStore added in v0.2.13

func (s *RSet) DiffStore(ctx context.Context, dest string, otherNames ...string) (int64, error)

DiffStore stores the difference in dest and returns its cardinality.

func (*RSet) Exists

func (o *RSet) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RSet) Expire

func (o *RSet) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RSet) ExpireAt

func (o *RSet) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RSet) GetCountDownLatch added in v0.2.13

func (s *RSet) GetCountDownLatch(value any) *RCountDownLatch

GetCountDownLatch returns the Redisson latch associated with a set value.

func (*RSet) GetFairLock added in v0.2.13

func (s *RSet) GetFairLock(value any) *RFairLock

GetFairLock returns the Redisson fair lock associated with a set value.

func (*RSet) GetLock added in v0.2.13

func (s *RSet) GetLock(value any) *RLock

GetLock returns the Redisson lock associated with a set value.

func (*RSet) GetPermitExpirableSemaphore added in v0.2.13

func (s *RSet) GetPermitExpirableSemaphore(value any) *RPermitExpirableSemaphore

GetPermitExpirableSemaphore returns the Redisson expirable semaphore for a set value.

func (*RSet) GetReadWriteLock added in v0.2.13

func (s *RSet) GetReadWriteLock(value any) *RReadWriteLock

GetReadWriteLock returns the Redisson read-write lock for a set value.

func (*RSet) GetSemaphore added in v0.2.13

func (s *RSet) GetSemaphore(value any) *RSemaphore

GetSemaphore returns the Redisson semaphore associated with a set value.

func (*RSet) Intersection added in v0.2.13

func (s *RSet) Intersection(ctx context.Context, otherNames ...string) ([]any, error)

Intersection returns members present in this set and every named set.

func (*RSet) IntersectionStore added in v0.2.13

func (s *RSet) IntersectionStore(ctx context.Context, dest string, otherNames ...string) (int64, error)

IntersectionStore stores the intersection in dest and returns its cardinality.

func (*RSet) Members

func (s *RSet) Members(ctx context.Context) ([]any, error)

Members returns all members in the set (decoded).

func (*RSet) Move added in v0.2.13

func (s *RSet) Move(ctx context.Context, destination string, member any) (bool, error)

Move moves member from this set to destination (another RSet name). Returns true when the member was moved.

func (*RSet) Name

func (o *RSet) Name() string

Name returns the Redis key name of the object.

func (*RSet) Random added in v0.2.13

func (s *RSet) Random(ctx context.Context) (any, error)

Random returns one random member, or (nil, nil) when the set is empty.

func (*RSet) RandomN added in v0.2.13

func (s *RSet) RandomN(ctx context.Context, n int64) ([]any, error)

RandomN returns up to n random members (may contain duplicates when n exceeds cardinality — Redis SRANDMEMBER semantics).

func (*RSet) ReadAll added in v0.2.13

func (s *RSet) ReadAll(ctx context.Context) ([]any, error)

ReadAll is the Redisson-style alias of Members.

func (*RSet) RemainTTL

func (o *RSet) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RSet) Remove

func (s *RSet) Remove(ctx context.Context, members ...any) error

Remove removes members from the set.

func (*RSet) RemoveCounted added in v0.2.13

func (s *RSet) RemoveCounted(ctx context.Context, members ...any) (int64, error)

RemoveCounted removes members and returns how many were actually removed (Redisson removeAllCounted / SREM).

func (*RSet) RemoveRandom added in v0.2.13

func (s *RSet) RemoveRandom(ctx context.Context) (any, error)

RemoveRandom pops and returns one random member, or (nil, nil) when empty.

func (*RSet) RemoveRandomN added in v0.2.13

func (s *RSet) RemoveRandomN(ctx context.Context, n int64) ([]any, error)

RemoveRandomN pops up to n random members.

func (*RSet) Rename

func (o *RSet) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RSet) Size

func (s *RSet) Size(ctx context.Context) (int64, error)

Size returns the cardinality of the set.

func (*RSet) Touch

func (o *RSet) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RSet) TryAdd added in v0.2.13

func (s *RSet) TryAdd(ctx context.Context, members ...any) (bool, error)

TryAdd atomically adds all members only when none is already present.

func (*RSet) Union added in v0.2.13

func (s *RSet) Union(ctx context.Context, otherNames ...string) ([]any, error)

Union returns members present in this set or any named set.

func (*RSet) UnionStore added in v0.2.13

func (s *RSet) UnionStore(ctx context.Context, dest string, otherNames ...string) (int64, error)

UnionStore stores the union in dest and returns its cardinality.

func (o *RSet) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RSetCache

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

RSetCache is an RSet with per-element TTL and maxIdle, wire-compatible with Redisson's RedissonSetCache:

ZSET {name}                        member = codec value,
                                   score = absolute expiry epoch ms
                                   (math.MaxInt64 for no TTL)
ZSET redisson__idle__set:{name}    idle *duration* per member;
                                   contains() refreshes the deadline.

func (*RSetCache) Add

func (s *RSetCache) Add(ctx context.Context, element any, ttl, maxIdle time.Duration) (bool, error)

Add adds element with optional ttl and maxIdle (0 = disabled). Returns true when the element was not present before.

func (*RSetCache) AddIfAbsent added in v0.2.13

func (s *RSetCache) AddIfAbsent(ctx context.Context, element any, ttl time.Duration) (bool, error)

AddIfAbsent adds element only when it has no live TTL deadline.

func (*RSetCache) AddIfExists added in v0.2.13

func (s *RSetCache) AddIfExists(ctx context.Context, element any, ttl time.Duration) (bool, error)

AddIfExists updates the TTL only when element is live.

func (*RSetCache) AddIfGreater added in v0.2.13

func (s *RSetCache) AddIfGreater(ctx context.Context, element any, ttl time.Duration) (bool, error)

AddIfGreater extends the TTL deadline of a live element.

func (*RSetCache) AddIfLess added in v0.2.13

func (s *RSetCache) AddIfLess(ctx context.Context, element any, ttl time.Duration) (bool, error)

AddIfLess shortens the TTL deadline of a live element.

func (*RSetCache) Clear

func (s *RSetCache) Clear(ctx context.Context) error

Clear removes the cache and its idle set.

func (*RSetCache) ClearExpire

func (o *RSetCache) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RSetCache) Contains

func (s *RSetCache) Contains(ctx context.Context, element any) (bool, error)

Contains reports membership; a hit refreshes the maxIdle deadline.

func (*RSetCache) ContainsAll added in v0.2.13

func (s *RSetCache) ContainsAll(ctx context.Context, elements ...any) (bool, error)

ContainsAll reports whether every element is live in the cache.

func (*RSetCache) Delete

func (o *RSetCache) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RSetCache) Exists

func (o *RSetCache) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RSetCache) Expire

func (o *RSetCache) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RSetCache) ExpireAt

func (o *RSetCache) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RSetCache) Members

func (s *RSetCache) Members(ctx context.Context) ([]any, error)

Members returns all live elements (decoded).

func (*RSetCache) Name

func (o *RSetCache) Name() string

Name returns the Redis key name of the object.

func (*RSetCache) Random added in v0.2.13

func (s *RSetCache) Random(ctx context.Context) (any, error)

Random returns one random live element, or (nil, nil) when empty.

func (*RSetCache) RandomN added in v0.2.13

func (s *RSetCache) RandomN(ctx context.Context, n int64) ([]any, error)

RandomN returns up to n distinct random live elements.

func (*RSetCache) ReadAll added in v0.2.13

func (s *RSetCache) ReadAll(ctx context.Context) ([]any, error)

ReadAll is the Redisson-style alias of Members.

func (*RSetCache) RemainTTL

func (o *RSetCache) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RSetCache) Remove

func (s *RSetCache) Remove(ctx context.Context, element any) (bool, error)

Remove drops element (and its idle entry).

func (*RSetCache) RemoveAll added in v0.2.13

func (s *RSetCache) RemoveAll(ctx context.Context, elements ...any) (bool, error)

RemoveAll removes the supplied elements and reports whether the cache changed.

func (*RSetCache) RemoveRandom added in v0.2.13

func (s *RSetCache) RemoveRandom(ctx context.Context) (any, error)

RemoveRandom removes and returns one random live element.

func (*RSetCache) RemoveRandomN added in v0.2.13

func (s *RSetCache) RemoveRandomN(ctx context.Context, n int64) ([]any, error)

RemoveRandomN removes and returns up to n distinct random live elements.

func (*RSetCache) Rename

func (o *RSetCache) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RSetCache) RetainAll added in v0.2.13

func (s *RSetCache) RetainAll(ctx context.Context, elements ...any) (bool, error)

RetainAll keeps only the supplied live elements and reports whether changed.

func (*RSetCache) Size

func (s *RSetCache) Size(ctx context.Context) (int64, error)

Size returns the live element count (after eviction).

func (*RSetCache) Touch

func (o *RSetCache) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RSetCache) TryAdd added in v0.2.13

func (s *RSetCache) TryAdd(ctx context.Context, element any, ttl time.Duration) (bool, error)

TryAdd is the Redisson-style alias of AddIfAbsent.

func (o *RSetCache) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RSetMultimap

type RSetMultimap struct{ RMultimap }

RSetMultimap stores an unordered value set per key.

func (*RSetMultimap) ClearExpire

func (o *RSetMultimap) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RSetMultimap) Delete

func (o *RSetMultimap) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RSetMultimap) Exists

func (o *RSetMultimap) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RSetMultimap) Expire

func (o *RSetMultimap) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RSetMultimap) ExpireAt

func (o *RSetMultimap) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RSetMultimap) Name

func (o *RSetMultimap) Name() string

Name returns the Redis key name of the object.

func (*RSetMultimap) RemainTTL

func (o *RSetMultimap) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RSetMultimap) Rename

func (o *RSetMultimap) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RSetMultimap) Touch

func (o *RSetMultimap) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RSetMultimap) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RSetMultimapCache added in v0.2.13

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

RSetMultimapCache stores an unordered value set per key with Redisson's per-key expiration metadata.

func (RSetMultimapCache) Clear added in v0.2.13

func (m RSetMultimapCache) Clear(ctx context.Context) error

Clear removes the index, timeout metadata and every per-key collection.

func (RSetMultimapCache) ContainsEntry added in v0.2.13

func (m RSetMultimapCache) ContainsEntry(
	ctx context.Context, key, value any,
) (bool, error)

ContainsEntry reports whether the current key contains value.

func (RSetMultimapCache) ContainsKey added in v0.2.13

func (m RSetMultimapCache) ContainsKey(ctx context.Context, key any) (bool, error)

ContainsKey reports whether key currently has values.

func (RSetMultimapCache) ContainsValue added in v0.2.13

func (m RSetMultimapCache) ContainsValue(ctx context.Context, value any) (bool, error)

ContainsValue reports whether any live key is associated with value.

func (RSetMultimapCache) Delete added in v0.2.13

func (m RSetMultimapCache) Delete(ctx context.Context) error

Delete removes the whole multimap cache.

func (RSetMultimapCache) Entries added in v0.2.13

func (m RSetMultimapCache) Entries(ctx context.Context) ([]MultimapEntry, error)

Entries returns every live key/value association.

func (RSetMultimapCache) Expire added in v0.2.13

func (m RSetMultimapCache) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire applies ttl to the index, timeout metadata and every per-key collection, matching RedissonMultimapCache's whole-object expiration.

func (RSetMultimapCache) ExpireKey added in v0.2.13

func (m RSetMultimapCache) ExpireKey(
	ctx context.Context, key any, ttl time.Duration,
) (bool, error)

ExpireKey sets the lifetime of every value associated with key.

func (RSetMultimapCache) Get added in v0.2.13

func (m RSetMultimapCache) Get(ctx context.Context, key any) ([]any, error)

Get returns the current values. Expired keys are hidden and lazily removed from the HASH, timeout ZSET and per-key collection.

func (RSetMultimapCache) GetFairLock added in v0.2.13

func (m RSetMultimapCache) GetFairLock(key any) *RFairLock

GetFairLock returns the Redisson fair lock for a multimap-cache key.

func (RSetMultimapCache) GetLock added in v0.2.13

func (m RSetMultimapCache) GetLock(key any) *RLock

GetLock returns the Redisson lock associated with a multimap-cache key.

func (RSetMultimapCache) GetReadWriteLock added in v0.2.13

func (m RSetMultimapCache) GetReadWriteLock(key any) *RReadWriteLock

GetReadWriteLock returns the Redisson read-write lock for a cache key.

func (RSetMultimapCache) GetSemaphore added in v0.2.13

func (m RSetMultimapCache) GetSemaphore(key any) *RSemaphore

GetSemaphore returns the Redisson semaphore for a multimap-cache key.

func (RSetMultimapCache) IsEmpty added in v0.2.13

func (m RSetMultimapCache) IsEmpty(ctx context.Context) (bool, error)

IsEmpty reports whether the cache has no live associations.

func (RSetMultimapCache) KeySet added in v0.2.13

func (m RSetMultimapCache) KeySet(ctx context.Context) ([]any, error)

KeySet returns every live key.

func (RSetMultimapCache) KeySize added in v0.2.13

func (m RSetMultimapCache) KeySize(ctx context.Context) (int64, error)

KeySize returns the number of live keys.

func (RSetMultimapCache) Put added in v0.2.13

func (m RSetMultimapCache) Put(
	ctx context.Context, key, value any,
) (bool, error)

Put associates value with key. For an expired key it first removes the old collection, so a new association starts a fresh non-expiring key.

func (RSetMultimapCache) PutAll added in v0.2.13

func (m RSetMultimapCache) PutAll(
	ctx context.Context, key any, values ...any,
) (bool, error)

PutAll associates all values with key.

func (RSetMultimapCache) ReadAllKeySet added in v0.2.13

func (m RSetMultimapCache) ReadAllKeySet(ctx context.Context) ([]any, error)

ReadAllKeySet is the eager Redisson-style alias of KeySet.

func (RSetMultimapCache) RemoveAll added in v0.2.13

func (m RSetMultimapCache) RemoveAll(ctx context.Context, key any) (bool, error)

RemoveAll removes key, its values and expiration metadata.

func (RSetMultimapCache) ReplaceValues added in v0.2.13

func (m RSetMultimapCache) ReplaceValues(
	ctx context.Context, key any, values ...any,
) ([]any, error)

ReplaceValues replaces all live values associated with key and returns the previous values. The key keeps its existing per-key expiration.

func (RSetMultimapCache) Size added in v0.2.13

func (m RSetMultimapCache) Size(ctx context.Context) (int64, error)

Size returns the number of live key/value associations.

func (RSetMultimapCache) StartAutoEviction added in v0.2.13

func (m RSetMultimapCache) StartAutoEviction(interval time.Duration)

StartAutoEviction periodically runs lazy expiry cleanup until the client closes (optional; default access paths already clean lazily).

func (RSetMultimapCache) Values added in v0.2.13

func (m RSetMultimapCache) Values(ctx context.Context) ([]any, error)

Values returns values across all live keys.

type RSetMultimapCacheNative added in v0.2.13

type RSetMultimapCacheNative struct{ *RSetMultimap }

RSetMultimapCacheNative / RListMultimapCacheNative add per-key TTL via Redis HPEXPIRE on the index HASH field plus PEXPIRE on the values collection (RedissonMultimapCacheNative 4.6.1). Requires Redis ≥ 7.4.

func (RSetMultimapCacheNative) ClearExpire added in v0.2.13

func (o RSetMultimapCacheNative) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RSetMultimapCacheNative) Delete added in v0.2.13

func (o RSetMultimapCacheNative) Delete(ctx context.Context) error

Delete removes the object's key.

func (RSetMultimapCacheNative) Exists added in v0.2.13

func (o RSetMultimapCacheNative) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RSetMultimapCacheNative) Expire added in v0.2.13

func (o RSetMultimapCacheNative) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RSetMultimapCacheNative) ExpireAt added in v0.2.13

func (o RSetMultimapCacheNative) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RSetMultimapCacheNative) ExpireKey added in v0.2.13

func (m *RSetMultimapCacheNative) ExpireKey(ctx context.Context, key any, ttl time.Duration) (bool, error)

func (RSetMultimapCacheNative) Name added in v0.2.13

func (o RSetMultimapCacheNative) Name() string

Name returns the Redis key name of the object.

func (RSetMultimapCacheNative) RemainTTL added in v0.2.13

func (o RSetMultimapCacheNative) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RSetMultimapCacheNative) Rename added in v0.2.13

func (o RSetMultimapCacheNative) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RSetMultimapCacheNative) Touch added in v0.2.13

func (o RSetMultimapCacheNative) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o RSetMultimapCacheNative) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RShardedTopic added in v0.2.12

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

RShardedTopic is a cluster-friendly topic using Redis 7+ sharded pub/sub (SSUBSCRIBE / SSPUBLISH): messages stay on the slot's shard instead of broadcasting cluster-wide, so heavy topics do not saturate the bus. Messages are codec-encoded like RTopic; cross-language interop is automatic (Redis-native protocol).

func (*RShardedTopic) ClearExpire added in v0.2.12

func (o *RShardedTopic) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RShardedTopic) CountSubscribers added in v0.2.12

func (t *RShardedTopic) CountSubscribers(ctx context.Context) (int64, error)

CountSubscribers returns the sharded subscriber count (PUBSUB SHARDNUMSUB).

func (*RShardedTopic) Delete added in v0.2.12

func (o *RShardedTopic) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RShardedTopic) Exists added in v0.2.12

func (o *RShardedTopic) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RShardedTopic) Expire added in v0.2.12

func (o *RShardedTopic) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RShardedTopic) ExpireAt added in v0.2.12

func (o *RShardedTopic) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RShardedTopic) Name added in v0.2.12

func (o *RShardedTopic) Name() string

Name returns the Redis key name of the object.

func (*RShardedTopic) Publish added in v0.2.12

func (t *RShardedTopic) Publish(ctx context.Context, message any) (int64, error)

Publish broadcasts via SSPUBLISH. Returns receivers count.

func (*RShardedTopic) RemainTTL added in v0.2.12

func (o *RShardedTopic) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RShardedTopic) Rename added in v0.2.12

func (o *RShardedTopic) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RShardedTopic) Subscribe added in v0.2.12

func (t *RShardedTopic) Subscribe(listener func(msg any)) (int, error)

Subscribe registers a listener and (lazily) starts the SSUBSCRIBE goroutine; blocks until the subscription is live.

func (*RShardedTopic) Touch added in v0.2.12

func (o *RShardedTopic) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RShardedTopic) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RShardedTopic) Unsubscribe added in v0.2.12

func (t *RShardedTopic) Unsubscribe(id int) bool

Unsubscribe removes a listener, stopping the goroutine when empty.

type RSpinLock added in v0.2.13

type RSpinLock struct {
	*RLock
}

RSpinLock is a re-entrant lock that busy-waits with short sleeps instead of pub/sub wakeups (Redisson SpinLock). Wire layout matches RLock (HASH + redisson_lock__channel:{name} unused for acquire).

func (RSpinLock) ClearExpire added in v0.2.13

func (o RSpinLock) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RSpinLock) Delete added in v0.2.13

func (o RSpinLock) Delete(ctx context.Context) error

Delete removes the object's key.

func (RSpinLock) Exists added in v0.2.13

func (o RSpinLock) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RSpinLock) Expire added in v0.2.13

func (o RSpinLock) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RSpinLock) ExpireAt added in v0.2.13

func (o RSpinLock) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RSpinLock) Lock added in v0.2.13

func (l *RSpinLock) Lock(ctx context.Context, clientID string, ttl time.Duration) error

Lock spins until acquired or ctx cancelled. ttl semantics match RLock.

func (RSpinLock) Name added in v0.2.13

func (o RSpinLock) Name() string

Name returns the Redis key name of the object.

func (RSpinLock) RemainTTL added in v0.2.13

func (o RSpinLock) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RSpinLock) Rename added in v0.2.13

func (o RSpinLock) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RSpinLock) Touch added in v0.2.13

func (o RSpinLock) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RSpinLock) TryLockWait added in v0.2.13

func (l *RSpinLock) TryLockWait(ctx context.Context, clientID string, wait, ttl time.Duration) (bool, error)

TryLockWait spins until wait elapses (no pub/sub).

func (o RSpinLock) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RStream added in v0.2.3

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

RStream is a distributed log backed by a Redis Stream. Field names and values are codec-encoded (matching Redisson's RStream with JsonJacksonCodec — verified via redi.py's bidirectional tests); consumer groups are Redis-native so cross-language interop is automatic.

func (*RStream) Ack added in v0.2.3

func (s *RStream) Ack(ctx context.Context, group string, ids ...string) (int64, error)

Ack acknowledges entries previously delivered to the group.

func (*RStream) Add added in v0.2.3

func (s *RStream) Add(ctx context.Context, fields map[string]any) (string, error)

Add appends an entry, returning its stream id ("*" auto id).

func (*RStream) AddWithID added in v0.2.13

func (s *RStream) AddWithID(ctx context.Context, id string, fields map[string]any) (string, error)

AddWithID appends an entry with an explicit stream id.

func (*RStream) AddWithMaxLen added in v0.2.3

func (s *RStream) AddWithMaxLen(ctx context.Context, fields map[string]any, maxLen int64, approximate bool) (string, error)

AddWithMaxLen appends with optional trimming (maxLen > 0).

func (*RStream) AutoClaim added in v0.2.3

func (s *RStream) AutoClaim(ctx context.Context, group, consumer string, minIdle time.Duration, start string, count int64) ([]StreamEntry, string, error)

AutoClaim claims up to count entries idle for at least minIdle, starting the scan at start ("0-0"). Returns the entries and the next cursor.

func (*RStream) Claim added in v0.2.3

func (s *RStream) Claim(ctx context.Context, group, consumer string, minIdle time.Duration, ids ...string) ([]StreamEntry, error)

Claim atomically transfers ownership of ids to consumer (minIdle filters).

func (*RStream) ClearExpire added in v0.2.3

func (o *RStream) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RStream) CreateConsumer added in v0.2.3

func (s *RStream) CreateConsumer(ctx context.Context, group, consumer string) (bool, error)

CreateConsumer registers a consumer in a group.

func (*RStream) CreateGroup added in v0.2.3

func (s *RStream) CreateGroup(ctx context.Context, group, id string) (bool, error)

CreateGroup creates a consumer group starting at id ("$" = only new entries, "0" = whole history). Returns false when the group exists.

func (*RStream) Delete added in v0.2.3

func (o *RStream) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RStream) DeleteGroup added in v0.2.3

func (s *RStream) DeleteGroup(ctx context.Context, group string) (bool, error)

DeleteGroup removes a consumer group.

func (*RStream) Exists added in v0.2.3

func (o *RStream) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RStream) Expire added in v0.2.3

func (o *RStream) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RStream) ExpireAt added in v0.2.3

func (o *RStream) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RStream) FastAutoClaim added in v0.2.13

func (s *RStream) FastAutoClaim(
	ctx context.Context,
	group, consumer string,
	minIdle time.Duration,
	start string,
	count int64,
) ([]string, string, error)

FastAutoClaim claims entries like AutoClaim and returns only message ids.

func (*RStream) FastClaim added in v0.2.13

func (s *RStream) FastClaim(
	ctx context.Context, group, consumer string, minIdle time.Duration, ids ...string,
) ([]string, error)

FastClaim transfers ownership like Claim and returns only message ids.

func (*RStream) GetInfo added in v0.2.13

func (s *RStream) GetInfo(ctx context.Context) (*redis.XInfoStream, error)

GetInfo returns stream metadata from XINFO STREAM.

func (*RStream) Len added in v0.2.3

func (s *RStream) Len(ctx context.Context) (int64, error)

Len returns the number of entries (XLEN).

func (*RStream) ListConsumers added in v0.2.13

func (s *RStream) ListConsumers(ctx context.Context, group string) ([]redis.XInfoConsumer, error)

ListConsumers returns consumer metadata for a group.

func (*RStream) ListGroups added in v0.2.13

func (s *RStream) ListGroups(ctx context.Context) ([]redis.XInfoGroup, error)

ListGroups returns the stream's consumer-group metadata.

func (*RStream) Nack added in v0.2.13

func (s *RStream) Nack(
	ctx context.Context, group string, mode StreamNackMode, ids ...string,
) (int64, error)

Nack negatively acknowledges pending entries using Redis 8.2 XNACK.

func (*RStream) Name added in v0.2.3

func (o *RStream) Name() string

Name returns the Redis key name of the object.

func (*RStream) PendingInfo added in v0.2.13

func (s *RStream) PendingInfo(ctx context.Context, group string) (*redis.XPending, error)

PendingInfo returns the pending-entry summary for a group.

func (*RStream) PendingRange added in v0.2.3

func (s *RStream) PendingRange(ctx context.Context, group, consumer string, count int64) ([]PendingEntry, error)

PendingRange lists unacknowledged entries (optionally for one consumer).

func (*RStream) Read added in v0.2.13

func (s *RStream) Read(ctx context.Context, id string, count int64, block time.Duration) ([]StreamEntry, error)

Read returns entries newer than id using XREAD. block > 0 waits up to that duration; block <= 0 returns immediately.

func (*RStream) ReadGroup added in v0.2.3

func (s *RStream) ReadGroup(ctx context.Context, group, consumer string, count int64, block time.Duration) ([]StreamEntry, error)

ReadGroup delivers undelivered (">") entries to a group consumer. block > 0 waits up to that duration; block <= 0 returns immediately (go-redis emits BLOCK for any Block >= 0, and "block 0" means block forever — hence the -1 sentinels).

func (*RStream) ReadRange added in v0.2.3

func (s *RStream) ReadRange(ctx context.Context, start, end string, count int64) ([]StreamEntry, error)

ReadRange returns entries with id in [start, end] ("-" .. "+"), ascending, up to count (0 = unlimited).

func (*RStream) ReadReverse added in v0.2.3

func (s *RStream) ReadReverse(ctx context.Context, end, start string, count int64) ([]StreamEntry, error)

ReadReverse returns entries in descending id order.

func (*RStream) RemainTTL added in v0.2.3

func (o *RStream) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RStream) Remove added in v0.2.3

func (s *RStream) Remove(ctx context.Context, ids ...string) (int64, error)

Remove deletes specific entries by id.

func (*RStream) RemoveConsumer added in v0.2.3

func (s *RStream) RemoveConsumer(ctx context.Context, group, consumer string) (int64, error)

RemoveConsumer removes a consumer and its pending entries.

func (*RStream) Rename added in v0.2.3

func (o *RStream) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RStream) Touch added in v0.2.3

func (o *RStream) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RStream) Trim added in v0.2.3

func (s *RStream) Trim(ctx context.Context, maxLen int64, approximate bool) (int64, error)

Trim removes old entries keeping at most maxLen (XTRIM MAXLEN).

func (*RStream) TrimMinID added in v0.2.3

func (s *RStream) TrimMinID(ctx context.Context, minID string, approximate bool) (int64, error)

TrimMinID removes entries with ids older than minID (XTRIM MINID).

func (o *RStream) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RStream) UpdateGroupMessageID added in v0.2.13

func (s *RStream) UpdateGroupMessageID(
	ctx context.Context, group, id string,
) error

UpdateGroupMessageID changes a group's last-delivered id (XGROUP SETID).

type RTDigest added in v0.2.13

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

RTDigest wraps Redis TDIGEST.* commands (numeric sketches; no codec wrap).

func (*RTDigest) Add added in v0.2.13

func (t *RTDigest) Add(ctx context.Context, values ...float64) error

Add observes values.

func (*RTDigest) CDF added in v0.2.13

func (t *RTDigest) CDF(ctx context.Context, values ...float64) ([]float64, error)

CDF estimates cumulative distribution at the given values.

func (*RTDigest) ClearExpire added in v0.2.13

func (o *RTDigest) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RTDigest) Delete added in v0.2.13

func (o *RTDigest) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RTDigest) Exists added in v0.2.13

func (o *RTDigest) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RTDigest) Expire added in v0.2.13

func (o *RTDigest) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RTDigest) ExpireAt added in v0.2.13

func (o *RTDigest) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RTDigest) Max added in v0.2.13

func (t *RTDigest) Max(ctx context.Context) (float64, error)

func (*RTDigest) Min added in v0.2.13

func (t *RTDigest) Min(ctx context.Context) (float64, error)

Min / Max / Rank helpers.

func (*RTDigest) Name added in v0.2.13

func (o *RTDigest) Name() string

Name returns the Redis key name of the object.

func (*RTDigest) Quantile added in v0.2.13

func (t *RTDigest) Quantile(ctx context.Context, quantiles ...float64) ([]float64, error)

Quantile estimates values at the given quantiles (0..1).

func (*RTDigest) RemainTTL added in v0.2.13

func (o *RTDigest) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RTDigest) Rename added in v0.2.13

func (o *RTDigest) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RTDigest) Touch added in v0.2.13

func (o *RTDigest) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RTDigest) TryCreate added in v0.2.13

func (t *RTDigest) TryCreate(ctx context.Context) (bool, error)

TryCreate initializes the sketch (TDIGEST.CREATE).

func (*RTDigest) TryCreateWithCompression added in v0.2.13

func (t *RTDigest) TryCreateWithCompression(ctx context.Context, compression int64) (bool, error)

TryCreateWithCompression initializes with compression.

func (o *RTDigest) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RTimeSeries added in v0.2.11

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

RTimeSeries is a time-series store, wire-compatible with Redisson's RedissonTimeSeries (source-verified):

ZSET {name}                        entries: score = timestamp ms,
                                   member = struct.pack('BBc0Lc0Lc0',
                                     4, idLen, id, valLen, encoded,
                                     lblLen, label)
ZSET redisson__ts_ttl:{name}       expiry deadlines (score = epoch ms)
STRING redisson__ts_seq:{name}     entry-id counter (zero-padded to
                                   20 digits, compared as strings)

The label blob = byte(n) + label where n=2 means "no label" and n=3 means "with label" (Java's convention).

func (*RTimeSeries) Add added in v0.2.11

func (s *RTimeSeries) Add(ctx context.Context, timestampMs int64, value any, label string, ttl time.Duration) error

Add stores value at timestamp (ms). ttl <= 0 means the Java default (effectively 100 years). label == "" stores an unlabeled entry.

func (*RTimeSeries) AddAll added in v0.2.13

func (s *RTimeSeries) AddAll(
	ctx context.Context, entries ...TimeSeriesEntry,
) error

AddAll stores entries in one atomic script using the default Redisson TTL.

func (*RTimeSeries) ClearExpire added in v0.2.11

func (o *RTimeSeries) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RTimeSeries) Delete added in v0.2.11

func (s *RTimeSeries) Delete(ctx context.Context) error

Delete removes the series and its companion keys.

func (*RTimeSeries) Exists added in v0.2.11

func (o *RTimeSeries) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RTimeSeries) Expire added in v0.2.11

func (o *RTimeSeries) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RTimeSeries) ExpireAt added in v0.2.11

func (o *RTimeSeries) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RTimeSeries) FirstEntries added in v0.2.13

func (s *RTimeSeries) FirstEntries(ctx context.Context, count int) ([]TimeSeriesEntry, error)

FirstEntries returns up to count earliest unexpired entries in ascending order.

func (*RTimeSeries) FirstEntry added in v0.2.13

func (s *RTimeSeries) FirstEntry(ctx context.Context) (*TimeSeriesEntry, error)

FirstEntry returns the earliest unexpired entry, or nil when empty.

func (*RTimeSeries) FirstTimestamp added in v0.2.13

func (s *RTimeSeries) FirstTimestamp(ctx context.Context) (int64, error)

FirstTimestamp returns the earliest unexpired timestamp, or zero when empty.

func (*RTimeSeries) Get added in v0.2.11

func (s *RTimeSeries) Get(ctx context.Context, timestampMs int64) (*TimeSeriesEntry, error)

Get returns the (unexpired) entry stored at exactly timestampMs (nil when absent).

func (*RTimeSeries) GetAndRemove added in v0.2.13

func (s *RTimeSeries) GetAndRemove(
	ctx context.Context, timestampMs int64,
) (any, error)

GetAndRemove removes and returns the first live value at timestampMs.

func (*RTimeSeries) GetAndRemoveEntry added in v0.2.13

func (s *RTimeSeries) GetAndRemoveEntry(
	ctx context.Context, timestampMs int64,
) (*TimeSeriesEntry, error)

GetAndRemoveEntry removes and returns the first live entry at timestampMs.

func (*RTimeSeries) LastEntries added in v0.2.13

func (s *RTimeSeries) LastEntries(ctx context.Context, count int) ([]TimeSeriesEntry, error)

LastEntries returns up to count latest unexpired entries in ascending order.

func (*RTimeSeries) LastEntry added in v0.2.13

func (s *RTimeSeries) LastEntry(ctx context.Context) (*TimeSeriesEntry, error)

LastEntry returns the latest unexpired entry, or nil when empty.

func (*RTimeSeries) LastTimestamp added in v0.2.13

func (s *RTimeSeries) LastTimestamp(ctx context.Context) (int64, error)

LastTimestamp returns the latest unexpired timestamp, or zero when empty.

func (*RTimeSeries) Name added in v0.2.11

func (o *RTimeSeries) Name() string

Name returns the Redis key name of the object.

func (*RTimeSeries) PollFirstEntries added in v0.2.13

func (s *RTimeSeries) PollFirstEntries(ctx context.Context, count int) ([]TimeSeriesEntry, error)

PollFirstEntries removes and returns up to count earliest unexpired entries.

func (*RTimeSeries) PollLastEntries added in v0.2.13

func (s *RTimeSeries) PollLastEntries(ctx context.Context, count int) ([]TimeSeriesEntry, error)

PollLastEntries removes and returns up to count latest unexpired entries in ascending order.

func (*RTimeSeries) Range added in v0.2.11

func (s *RTimeSeries) Range(ctx context.Context, fromMs, toMs int64, limit int64) ([]TimeSeriesEntry, error)

Range returns unexpired entries in [fromMs, toMs] ascending (limit <= 0 means unlimited).

func (*RTimeSeries) RangeReversed added in v0.2.13

func (s *RTimeSeries) RangeReversed(
	ctx context.Context,
	fromMs, toMs int64,
	limit int64,
) ([]TimeSeriesEntry, error)

RangeReversed returns unexpired entries in [fromMs, toMs] descending. limit <= 0 means unlimited.

func (*RTimeSeries) RemainTTL added in v0.2.11

func (o *RTimeSeries) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RTimeSeries) Remove added in v0.2.11

func (s *RTimeSeries) Remove(ctx context.Context, timestampMs int64) (int64, error)

Remove deletes the entries stored at exactly timestampMs.

func (*RTimeSeries) RemoveRange added in v0.2.13

func (s *RTimeSeries) RemoveRange(
	ctx context.Context, fromMs, toMs int64,
) (int64, error)

RemoveRange removes live entries with timestamps in the inclusive range.

func (*RTimeSeries) Rename added in v0.2.11

func (o *RTimeSeries) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RTimeSeries) Size added in v0.2.11

func (s *RTimeSeries) Size(ctx context.Context) (int64, error)

Size returns the number of unexpired entries (Java's lazy semantics: ZCARD minus expired, without deleting them).

func (*RTimeSeries) Touch added in v0.2.11

func (o *RTimeSeries) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RTimeSeries) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RTopK added in v0.2.13

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

RTopK wraps Redis TOPK.* commands.

func (*RTopK) Add added in v0.2.13

func (t *RTopK) Add(ctx context.Context, elements ...any) ([]string, error)

Add increments items; returns items dropped from the top-k (possibly empty strings).

func (*RTopK) ClearExpire added in v0.2.13

func (o *RTopK) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RTopK) Delete added in v0.2.13

func (o *RTopK) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RTopK) Exists added in v0.2.13

func (o *RTopK) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RTopK) Expire added in v0.2.13

func (o *RTopK) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RTopK) ExpireAt added in v0.2.13

func (o *RTopK) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RTopK) List added in v0.2.13

func (t *RTopK) List(ctx context.Context) ([]string, error)

List returns the current top-k items (encoded strings).

func (*RTopK) ListWithCount added in v0.2.13

func (t *RTopK) ListWithCount(ctx context.Context) (map[string]int64, error)

ListWithCount returns item -> count.

func (*RTopK) Name added in v0.2.13

func (o *RTopK) Name() string

Name returns the Redis key name of the object.

func (*RTopK) Query added in v0.2.13

func (t *RTopK) Query(ctx context.Context, elements ...any) ([]bool, error)

Query reports whether each element is currently in the top-k.

func (*RTopK) RemainTTL added in v0.2.13

func (o *RTopK) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RTopK) Rename added in v0.2.13

func (o *RTopK) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RTopK) Touch added in v0.2.13

func (o *RTopK) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RTopK) TryInit added in v0.2.13

func (t *RTopK) TryInit(ctx context.Context, k int64) (bool, error)

TryInit reserves a top-k sketch of size k.

func (o *RTopK) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RTopic

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

RTopic is a pub/sub topic whose messages are codec (JSON) encoded, interoperable with Redisson's RTopic. Listeners run on a dedicated subscription goroutine; Publish never fans out locally (exactly-once delivery per listener).

func (*RTopic) ChannelNames added in v0.2.13

func (t *RTopic) ChannelNames() []string

ChannelNames returns the Redis channels used by this topic.

func (*RTopic) ClearExpire

func (o *RTopic) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RTopic) CountListeners added in v0.2.13

func (t *RTopic) CountListeners() int

CountListeners returns the number of local listeners.

func (*RTopic) CountSubscribers

func (t *RTopic) CountSubscribers(ctx context.Context) (int64, error)

CountSubscribers returns the number of remote subscribers (PUBSUB NUMSUB).

func (*RTopic) Delete

func (o *RTopic) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RTopic) Exists

func (o *RTopic) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RTopic) Expire

func (o *RTopic) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RTopic) ExpireAt

func (o *RTopic) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RTopic) GetChannelNames added in v0.2.13

func (t *RTopic) GetChannelNames() []string

GetChannelNames is the Redisson-style alias of ChannelNames.

func (*RTopic) Name

func (o *RTopic) Name() string

Name returns the Redis key name of the object.

func (*RTopic) Publish

func (t *RTopic) Publish(ctx context.Context, message any) (int64, error)

Publish broadcasts message to all subscribers (local and remote). Returns the number of clients that received it.

func (*RTopic) RemainTTL

func (o *RTopic) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RTopic) RemoveAllListeners added in v0.2.13

func (t *RTopic) RemoveAllListeners()

RemoveAllListeners unregisters every local listener.

func (*RTopic) Rename

func (o *RTopic) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RTopic) Subscribe

func (t *RTopic) Subscribe(listener func(msg any)) (int, error)

Subscribe registers a listener and (lazily) starts the subscription goroutine. It blocks until the subscription is confirmed by Redis.

func (*RTopic) Touch

func (o *RTopic) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RTopic) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

func (*RTopic) Unsubscribe

func (t *RTopic) Unsubscribe(id int) bool

Unsubscribe removes a listener, stopping the subscription goroutine when the last one goes away.

type RTransferQueue

type RTransferQueue struct {
	*RQueue
}

RTransferQueue atomically moves elements from its head to the tail of a destination queue (single Lua round-trip, no TOCTOU window).

Compatibility note: this is NOT Redisson's RTransferQueue (which is built on RRemoteService handoff). It is a local Redis queue-to-queue migrate helper. Do not expect Java getTransferQueue() to share protocol with it.

func (RTransferQueue) ClearExpire

func (o RTransferQueue) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (RTransferQueue) Delete

func (o RTransferQueue) Delete(ctx context.Context) error

Delete removes the object's key.

func (RTransferQueue) Exists

func (o RTransferQueue) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (RTransferQueue) Expire

func (o RTransferQueue) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (RTransferQueue) ExpireAt

func (o RTransferQueue) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (RTransferQueue) Name

func (o RTransferQueue) Name() string

Name returns the Redis key name of the object.

func (RTransferQueue) RemainTTL

func (o RTransferQueue) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (RTransferQueue) Rename

func (o RTransferQueue) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (RTransferQueue) Touch

func (o RTransferQueue) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (*RTransferQueue) Transfer

func (q *RTransferQueue) Transfer(ctx context.Context, destination string) (any, error)

Transfer pops the head of this queue and pushes it onto the destination queue's tail, returning the transferred value (nil when this queue is empty).

func (*RTransferQueue) TryTransfer

func (q *RTransferQueue) TryTransfer(ctx context.Context, destination string, timeout time.Duration) (any, error)

TryTransfer transfers with a blocking wait for up to timeout, polling every 50ms. Returns the transferred value (nil on timeout).

func (o RTransferQueue) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RVectorSet added in v0.2.13

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

RVectorSet wraps Redis 8+ Vector Set commands (VADD/VSIM/…).

func (*RVectorSet) Add added in v0.2.13

func (v *RVectorSet) Add(ctx context.Context, element string, vector []float64) (bool, error)

Add inserts or updates element with vector coordinates.

func (*RVectorSet) ClearExpire added in v0.2.13

func (o *RVectorSet) ClearExpire(ctx context.Context) (bool, error)

ClearExpire removes the TTL (key becomes persistent).

func (*RVectorSet) Contains added in v0.2.13

func (v *RVectorSet) Contains(ctx context.Context, element string) (bool, error)

Contains reports membership.

func (*RVectorSet) Delete added in v0.2.13

func (o *RVectorSet) Delete(ctx context.Context) error

Delete removes the object's key.

func (*RVectorSet) Dimensions added in v0.2.13

func (v *RVectorSet) Dimensions(ctx context.Context) (int64, error)

Dimensions returns VDIM.

func (*RVectorSet) Exists added in v0.2.13

func (o *RVectorSet) Exists(ctx context.Context) (bool, error)

Exists reports whether the key exists.

func (*RVectorSet) Expire added in v0.2.13

func (o *RVectorSet) Expire(ctx context.Context, ttl time.Duration) (bool, error)

Expire sets a TTL on the key.

func (*RVectorSet) ExpireAt added in v0.2.13

func (o *RVectorSet) ExpireAt(ctx context.Context, ts time.Time) (bool, error)

ExpireAt sets an absolute expiry time.

func (*RVectorSet) GetVector added in v0.2.13

func (v *RVectorSet) GetVector(ctx context.Context, element string) ([]float64, error)

GetVector returns approximate coordinates for element.

func (*RVectorSet) Name added in v0.2.13

func (o *RVectorSet) Name() string

Name returns the Redis key name of the object.

func (*RVectorSet) RemainTTL added in v0.2.13

func (o *RVectorSet) RemainTTL(ctx context.Context) (time.Duration, error)

RemainTTL returns the remaining time-to-live (-1 no expiry, -2 missing).

func (*RVectorSet) Remove added in v0.2.13

func (v *RVectorSet) Remove(ctx context.Context, element string) (bool, error)

Remove deletes element.

func (*RVectorSet) Rename added in v0.2.13

func (o *RVectorSet) Rename(ctx context.Context, newName string) error

Rename renames the object's key. Note: for structures with companion keys (locks, delayed queues, map caches) the companion keys are not moved.

func (*RVectorSet) SimilarByElement added in v0.2.13

func (v *RVectorSet) SimilarByElement(ctx context.Context, element string, count int) ([]string, error)

SimilarByElement returns nearest neighbour names for element.

func (*RVectorSet) SimilarByVector added in v0.2.13

func (v *RVectorSet) SimilarByVector(ctx context.Context, vector []float64, count int) ([]string, error)

SimilarByVector returns nearest neighbours for a query vector.

func (*RVectorSet) Size added in v0.2.13

func (v *RVectorSet) Size(ctx context.Context) (int64, error)

Size returns VCARD.

func (*RVectorSet) Touch added in v0.2.13

func (o *RVectorSet) Touch(ctx context.Context) (bool, error)

Touch updates the last-access time of the key.

func (o *RVectorSet) Unlink(ctx context.Context) error

Unlink removes the key asynchronously (non-blocking Redis UNLINK).

type RateLimiterConfig added in v0.2.13

type RateLimiterConfig struct {
	RateType  RateType
	Rate      int64
	Interval  time.Duration
	KeepAlive time.Duration
}

RateLimiterConfig is the persisted limiter configuration (Redisson RateLimiterConfig).

type RateType

type RateType int

RateType mirrors Redisson's RateType enum ordinals (wire format).

const (
	RateTypeOverall   RateType = 0
	RateTypePerClient RateType = 1
)

type ScriptReturnType

type ScriptReturnType int

ScriptReturnType selects the cast applied to a Lua script reply, mirroring Redisson's RScript.ReturnType.

const (
	ScriptReturnValue ScriptReturnType = iota
	ScriptReturnBoolean
	ScriptReturnInteger
	ScriptReturnStatus
)

type SearchDocument added in v0.2.13

type SearchDocument struct {
	ID     string
	Score  float64
	Fields map[string]string
}

SearchDocument is one hit.

type SearchOptions added in v0.2.13

type SearchOptions struct {
	LimitOffset int
	LimitCount  int
	Return      []string
	WithScores  bool
	NoContent   bool
}

SearchOptions configures FT.SEARCH.

type SearchResult added in v0.2.13

type SearchResult struct {
	Total     int64
	Documents []SearchDocument
}

SearchResult is FT.SEARCH output.

type StreamEntry added in v0.2.3

type StreamEntry struct {
	ID     string
	Fields map[string]any
}

StreamEntry is one stream record with codec-decoded fields.

type StreamNackMode added in v0.2.13

type StreamNackMode string

StreamNackMode controls how Redis XNACK marks delivery attempts.

const (
	StreamNackSilent StreamNackMode = "SILENT"
	StreamNackFail   StreamNackMode = "FAIL"
	StreamNackFatal  StreamNackMode = "FATAL"
)

type TimeSeriesEntry added in v0.2.11

type TimeSeriesEntry struct {
	Timestamp int64
	Value     any
	Label     string
	Id        int64
}

TimeSeriesEntry is one stored point (Id is the sequence number Java assigns per entry; zero when not read back).

Directories

Path Synopsis
Package dashboard provides a TUI monitoring dashboard for redi.go clients.
Package dashboard provides a TUI monitoring dashboard for redi.go clients.

Jump to

Keyboard shortcuts

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