Documentation
¶
Overview ¶
Package rueidistpl 在 Rueidis、gocache 和 rueidislock 之上提供面向业务的轻量封装。
包内统一处理 Redis 连接配置、key 前缀、JSON 编解码和常用数据结构,包括 Bitmap、Geo、 HyperLogLog、Redis 8 的 JSON/TimeSeries/Vector Set/概率结构,以及 Redis 8.8+ 原生稀疏 Array,同时保留 Redis.Client 原生出口。连接管理、客户端缓存和分布式锁续期仍由成熟的 上游库负责,本包不重复实现 Redis 协议、连接池或锁算法。
Index ¶
- Constants
- Variables
- func IsNotFound(err error) bool
- type Array
- func (array *Array[T]) Clear(ctx context.Context) error
- func (array *Array[T]) Count(ctx context.Context) (int64, error)
- func (array *Array[T]) Delete(ctx context.Context, indices ...int64) (int64, error)
- func (array *Array[T]) DeleteRanges(ctx context.Context, ranges ...ArrayRange) (int64, error)
- func (array *Array[T]) Get(ctx context.Context, index int64) (T, error)
- func (array *Array[T]) GetMany(ctx context.Context, indices ...int64) ([]ArrayItem[T], error)
- func (array *Array[T]) Insert(ctx context.Context, values ...T) (int64, error)
- func (array *Array[T]) Key() string
- func (array *Array[T]) LastItems(ctx context.Context, count int64, reverse bool) ([]T, error)
- func (array *Array[T]) Len(ctx context.Context) (int64, error)
- func (array *Array[T]) Next(ctx context.Context) (int64, error)
- func (array *Array[T]) Range(ctx context.Context, start, end int64) ([]ArrayItem[T], error)
- func (array *Array[T]) Ring(ctx context.Context, size int64, values ...T) (int64, error)
- func (array *Array[T]) Scan(ctx context.Context, start, end, limit int64) ([]ArrayItem[T], error)
- func (array *Array[T]) Seek(ctx context.Context, index int64) (bool, error)
- func (array *Array[T]) Set(ctx context.Context, start int64, values ...T) (int64, error)
- func (array *Array[T]) SetMany(ctx context.Context, values map[int64]T) (int64, error)
- type ArrayItem
- type ArrayRange
- type AutoClaimResult
- type Bitmap
- func (bitmap *Bitmap) BitFieldGet(ctx context.Context, encoding string, offset int64) (int64, error)
- func (bitmap *Bitmap) Clear(ctx context.Context) error
- func (bitmap *Bitmap) Combine(ctx context.Context, operation BitmapOperation, destination string, ...) (int64, error)
- func (bitmap *Bitmap) Count(ctx context.Context) (int64, error)
- func (bitmap *Bitmap) CountBits(ctx context.Context, start, end int64) (int64, error)
- func (bitmap *Bitmap) Get(ctx context.Context, offset int64) (bool, error)
- func (bitmap *Bitmap) Key() string
- func (bitmap *Bitmap) Position(ctx context.Context, value bool) (int64, error)
- func (bitmap *Bitmap) PositionBits(ctx context.Context, value bool, start, end int64) (int64, error)
- func (bitmap *Bitmap) Set(ctx context.Context, offset int64, value bool) (bool, error)
- type BitmapOperation
- type BloomFilter
- func (filter *BloomFilter) Add(ctx context.Context, item string) (bool, error)
- func (filter *BloomFilter) AddMany(ctx context.Context, items ...string) ([]bool, error)
- func (filter *BloomFilter) Card(ctx context.Context) (int64, error)
- func (filter *BloomFilter) Clear(ctx context.Context) error
- func (filter *BloomFilter) Exists(ctx context.Context, item string) (bool, error)
- func (filter *BloomFilter) ExistsMany(ctx context.Context, items ...string) ([]bool, error)
- func (filter *BloomFilter) Key() string
- func (filter *BloomFilter) Reserve(ctx context.Context, errorRate float64, capacity int64) error
- type Cache
- func (cache *Cache[T]) Delete(ctx context.Context, key string) error
- func (cache *Cache[T]) Get(ctx context.Context, key string) (T, error)
- func (cache *Cache[T]) GetWithTTL(ctx context.Context, key string) (T, time.Duration, error)
- func (cache *Cache[T]) Prefix() string
- func (cache *Cache[T]) Set(ctx context.Context, key string, value T, ttl ...time.Duration) error
- type ClaimedDelayed
- type Config
- type CountMinIncrement
- type CountMinSketch
- func (sketch *CountMinSketch) Clear(ctx context.Context) error
- func (sketch *CountMinSketch) Increment(ctx context.Context, increments ...CountMinIncrement) ([]int64, error)
- func (sketch *CountMinSketch) InitByDimensions(ctx context.Context, width, depth int64) error
- func (sketch *CountMinSketch) InitByProbability(ctx context.Context, errorRate, probability float64) error
- func (sketch *CountMinSketch) Key() string
- func (sketch *CountMinSketch) Query(ctx context.Context, items ...string) ([]int64, error)
- type Counter
- func (counter *Counter) Add(ctx context.Context, delta int64) (int64, error)
- func (counter *Counter) Delete(ctx context.Context) error
- func (counter *Counter) Get(ctx context.Context) (int64, error)
- func (counter *Counter) Increment(ctx context.Context) (int64, error)
- func (counter *Counter) Key() string
- func (counter *Counter) Set(ctx context.Context, value int64) error
- type CuckooFilter
- func (filter *CuckooFilter) Add(ctx context.Context, item string) (bool, error)
- func (filter *CuckooFilter) AddNX(ctx context.Context, item string) (bool, error)
- func (filter *CuckooFilter) Clear(ctx context.Context) error
- func (filter *CuckooFilter) Count(ctx context.Context, item string) (int64, error)
- func (filter *CuckooFilter) Delete(ctx context.Context, item string) (bool, error)
- func (filter *CuckooFilter) Exists(ctx context.Context, item string) (bool, error)
- func (filter *CuckooFilter) ExistsMany(ctx context.Context, items ...string) ([]bool, error)
- func (filter *CuckooFilter) Key() string
- func (filter *CuckooFilter) Reserve(ctx context.Context, capacity int64) error
- type DelayQueue
- func (queue *DelayQueue[T]) Ack(ctx context.Context, id, token string) (bool, error)
- func (queue *DelayQueue[T]) Claim(ctx context.Context, visibilityTimeout time.Duration, limit int64) ([]ClaimedDelayed[T], error)
- func (queue *DelayQueue[T]) Clear(ctx context.Context) error
- func (queue *DelayQueue[T]) Extend(ctx context.Context, id, token string, visibilityTimeout time.Duration) (bool, error)
- func (queue *DelayQueue[T]) InFlight(ctx context.Context) (int64, error)
- func (queue *DelayQueue[T]) Keys() (valuesKey, scoresKey string)
- func (queue *DelayQueue[T]) Len(ctx context.Context) (int64, error)
- func (queue *DelayQueue[T]) Nack(ctx context.Context, id, token string, dueAt time.Time) (bool, error)
- func (queue *DelayQueue[T]) Poll(ctx context.Context, now time.Time, limit int64) ([]Delayed[T], error)
- func (queue *DelayQueue[T]) ReliableKeys() (processingKey, claimsKey string)
- func (queue *DelayQueue[T]) Remove(ctx context.Context, id string) (bool, error)
- func (queue *DelayQueue[T]) Schedule(ctx context.Context, id string, dueAt time.Time, value T) error
- type Delayed
- type DeleteBatchResult
- type DeleteKeyResult
- type ExistsBatchResult
- type ExistsKeyResult
- type ExpirationInfo
- type Geo
- func (geo *Geo) Add(ctx context.Context, points ...GeoPoint) (int64, error)
- func (geo *Geo) Clear(ctx context.Context) error
- func (geo *Geo) Distance(ctx context.Context, member1, member2 string, unit GeoUnit) (float64, error)
- func (geo *Geo) Key() string
- func (geo *Geo) Len(ctx context.Context) (int64, error)
- func (geo *Geo) Position(ctx context.Context, member string) (GeoPosition, error)
- func (geo *Geo) Positions(ctx context.Context, members ...string) ([]GeoPosition, error)
- func (geo *Geo) Remove(ctx context.Context, members ...string) (int64, error)
- func (geo *Geo) SearchRadius(ctx context.Context, longitude, latitude, radius float64, unit GeoUnit, ...) ([]GeoSearchResult, error)
- func (geo *Geo) SearchRadiusByMember(ctx context.Context, member string, radius float64, unit GeoUnit, ...) ([]GeoSearchResult, error)
- type GeoPoint
- type GeoPosition
- type GeoSearchOptions
- type GeoSearchResult
- type GeoUnit
- type Hash
- func (hash *Hash[T]) All(ctx context.Context) (map[string]T, error)
- func (hash *Hash[T]) Clear(ctx context.Context) error
- func (hash *Hash[T]) Delete(ctx context.Context, fields ...string) (int64, error)
- func (hash *Hash[T]) Exists(ctx context.Context, field string) (bool, error)
- func (hash *Hash[T]) ExpirationField(ctx context.Context, field string) (ExpirationInfo, error)
- func (hash *Hash[T]) ExpireField(ctx context.Context, field string, ttl time.Duration) (bool, error)
- func (hash *Hash[T]) Get(ctx context.Context, field string) (T, error)
- func (hash *Hash[T]) GetMany(ctx context.Context, fields ...string) (map[string]T, error)
- func (hash *Hash[T]) IncrementFloat(ctx context.Context, field string, delta float64) (float64, error)
- func (hash *Hash[T]) IncrementInt(ctx context.Context, field string, delta int64) (int64, error)
- func (hash *Hash[T]) Key() string
- func (hash *Hash[T]) Keys(ctx context.Context) ([]string, error)
- func (hash *Hash[T]) Len(ctx context.Context) (int64, error)
- func (hash *Hash[T]) PersistField(ctx context.Context, field string) (bool, error)
- func (hash *Hash[T]) Scan(ctx context.Context, cursor uint64, pattern string, count int64) (HashScan[T], error)
- func (hash *Hash[T]) Set(ctx context.Context, field string, value T) error
- func (hash *Hash[T]) SetMany(ctx context.Context, values map[string]T) error
- func (hash *Hash[T]) SetNX(ctx context.Context, field string, value T) (bool, error)
- func (hash *Hash[T]) TTLField(ctx context.Context, field string) (time.Duration, error)
- func (hash *Hash[T]) Values(ctx context.Context) ([]T, error)
- type HashScan
- type HyperLogLog
- func (hyperLogLog *HyperLogLog) Add(ctx context.Context, elements ...string) (bool, error)
- func (hyperLogLog *HyperLogLog) Clear(ctx context.Context) error
- func (hyperLogLog *HyperLogLog) Count(ctx context.Context) (int64, error)
- func (hyperLogLog *HyperLogLog) CountWith(ctx context.Context, others ...string) (int64, error)
- func (hyperLogLog *HyperLogLog) Key() string
- func (hyperLogLog *HyperLogLog) MergeFrom(ctx context.Context, sources ...string) error
- type Idempotency
- func (idempotency *Idempotency) Exists(ctx context.Context, id string) (bool, error)
- func (idempotency *Idempotency) Forget(ctx context.Context, id string) error
- func (idempotency *Idempotency) Run(ctx context.Context, id string, ttl time.Duration, ...) (bool, error)
- func (idempotency *Idempotency) Try(ctx context.Context, id string, ttl time.Duration) (bool, error)
- type JSONDocument
- func (document *JSONDocument[T]) Clear(ctx context.Context) error
- func (document *JSONDocument[T]) DeletePath(ctx context.Context, path string) (int64, error)
- func (document *JSONDocument[T]) Exists(ctx context.Context) (bool, error)
- func (document *JSONDocument[T]) Get(ctx context.Context) (T, error)
- func (document *JSONDocument[T]) GetPath(ctx context.Context, path string) (json.RawMessage, error)
- func (document *JSONDocument[T]) Key() string
- func (document *JSONDocument[T]) MergePath(ctx context.Context, path string, value any) error
- func (document *JSONDocument[T]) Set(ctx context.Context, value T) error
- func (document *JSONDocument[T]) SetNX(ctx context.Context, value T) (bool, error)
- func (document *JSONDocument[T]) SetPath(ctx context.Context, path string, value any) error
- func (document *JSONDocument[T]) SetXX(ctx context.Context, value T) (bool, error)
- type List
- func (list *List[T]) Clear(ctx context.Context) error
- func (list *List[T]) Index(ctx context.Context, index int64) (T, error)
- func (list *List[T]) Key() string
- func (list *List[T]) Len(ctx context.Context) (int64, error)
- func (list *List[T]) PopLeft(ctx context.Context) (T, error)
- func (list *List[T]) PopRight(ctx context.Context) (T, error)
- func (list *List[T]) PushLeft(ctx context.Context, values ...T) (int64, error)
- func (list *List[T]) PushRight(ctx context.Context, values ...T) (int64, error)
- func (list *List[T]) Range(ctx context.Context, start, stop int64) ([]T, error)
- func (list *List[T]) Remove(ctx context.Context, count int64, value T) (int64, error)
- func (list *List[T]) Set(ctx context.Context, index int64, value T) error
- func (list *List[T]) Trim(ctx context.Context, start, stop int64) error
- type PendingEntry
- type PubSub
- func (pubsub *PubSub[T]) Prefix() string
- func (pubsub *PubSub[T]) Publish(ctx context.Context, channel string, value T) (int64, error)
- func (pubsub *PubSub[T]) PublishShard(ctx context.Context, channel string, value T) (int64, error)
- func (pubsub *PubSub[T]) Subscribe(ctx context.Context, handler func(PubSubMessage[T]) error, channels ...string) error
- func (pubsub *PubSub[T]) SubscribePattern(ctx context.Context, handler func(PubSubMessage[T]) error, patterns ...string) error
- func (pubsub *PubSub[T]) SubscribeShard(ctx context.Context, handler func(PubSubMessage[T]) error, channels ...string) error
- type PubSubMessage
- type Ranked
- type Ranking
- func (ranking *Ranking[T]) Clear(ctx context.Context) error
- func (ranking *Ranking[T]) Get(ctx context.Context, id string) (Ranked[T], error)
- func (ranking *Ranking[T]) Keys() (valuesKey, scoresKey string)
- func (ranking *Ranking[T]) Len(ctx context.Context) (int64, error)
- func (ranking *Ranking[T]) Page(ctx context.Context, offset, limit int64) ([]Ranked[T], error)
- func (ranking *Ranking[T]) Range(ctx context.Context, start, stop int64) ([]Ranked[T], error)
- func (ranking *Ranking[T]) Remove(ctx context.Context, id string) (bool, error)
- func (ranking *Ranking[T]) Top(ctx context.Context, limit int64) ([]Ranked[T], error)
- func (ranking *Ranking[T]) Upsert(ctx context.Context, id string, score float64, value T) error
- type Redis
- func (redis *Redis) Bitmap(key string) *Bitmap
- func (redis *Redis) BloomFilter(key string) *BloomFilter
- func (redis *Redis) Client() rueidis.Client
- func (redis *Redis) Close()
- func (redis *Redis) CountMinSketch(key string) *CountMinSketch
- func (redis *Redis) Counter(key string) *Counter
- func (redis *Redis) CuckooFilter(key string) *CuckooFilter
- func (redis *Redis) Delete(ctx context.Context, keys ...string) (int64, error)
- func (redis *Redis) DeleteEach(ctx context.Context, keys ...string) DeleteBatchResult
- func (redis *Redis) Exists(ctx context.Context, keys ...string) (int64, error)
- func (redis *Redis) ExistsEach(ctx context.Context, keys ...string) ExistsBatchResult
- func (redis *Redis) Expiration(ctx context.Context, key string) (ExpirationInfo, error)
- func (redis *Redis) FencingKey(name string) string
- func (redis *Redis) Geo(key string) *Geo
- func (redis *Redis) GetString(ctx context.Context, key string) (string, error)
- func (redis *Redis) Has(ctx context.Context, key string) (bool, error)
- func (redis *Redis) HyperLogLog(key string) *HyperLogLog
- func (redis *Redis) Idempotency(namespace string) *Idempotency
- func (redis *Redis) Key(key string) string
- func (redis *Redis) List(key string) *StringList
- func (redis *Redis) Lock(ctx context.Context, name string) (context.Context, context.CancelFunc, error)
- func (redis *Redis) LockFenced(ctx context.Context, name string) (context.Context, int64, context.CancelFunc, error)
- func (redis *Redis) Ping(ctx context.Context) error
- func (redis *Redis) SetString(ctx context.Context, key, value string, ttl ...time.Duration) error
- func (redis *Redis) SortedSet(key string) *SortedSet
- func (redis *Redis) StringList(key string) *StringList
- func (redis *Redis) StringSet(key string) *StringSet
- func (redis *Redis) TDigest(key string) *TDigest
- func (redis *Redis) TimeSeries(key string) *TimeSeries
- func (redis *Redis) TopK(key string) *TopK
- func (redis *Redis) TryLock(ctx context.Context, name string) (context.Context, context.CancelFunc, error)
- func (redis *Redis) TryLockFenced(ctx context.Context, name string) (context.Context, int64, context.CancelFunc, error)
- func (redis *Redis) VectorSet(key string) *VectorSet
- func (redis *Redis) WithFencedLock(ctx context.Context, name string, fn func(context.Context, int64) error) error
- func (redis *Redis) WithLock(ctx context.Context, name string, fn func(context.Context) error) error
- type ScoredMember
- type Set
- func (set *Set[T]) Add(ctx context.Context, values ...T) (int64, error)
- func (set *Set[T]) Clear(ctx context.Context) error
- func (set *Set[T]) Contains(ctx context.Context, value T) (bool, error)
- func (set *Set[T]) Key() string
- func (set *Set[T]) Len(ctx context.Context) (int64, error)
- func (set *Set[T]) Members(ctx context.Context) ([]T, error)
- func (set *Set[T]) Remove(ctx context.Context, values ...T) (int64, error)
- func (set *Set[T]) Scan(ctx context.Context, cursor uint64, pattern string, count int64) (SetScan[T], error)
- type SetScan
- type SortedSet
- func (set *SortedSet) Add(ctx context.Context, member string, score float64) error
- func (set *SortedSet) AddMany(ctx context.Context, members ...ScoredMember) error
- func (set *SortedSet) Clear(ctx context.Context) error
- func (set *SortedSet) Increment(ctx context.Context, member string, delta float64) (float64, error)
- func (set *SortedSet) Key() string
- func (set *SortedSet) Len(ctx context.Context) (int64, error)
- func (set *SortedSet) PopMax(ctx context.Context, count int64) ([]ScoredMember, error)
- func (set *SortedSet) PopMin(ctx context.Context, count int64) ([]ScoredMember, error)
- func (set *SortedSet) Range(ctx context.Context, start, stop int64) ([]ScoredMember, error)
- func (set *SortedSet) RangeByScore(ctx context.Context, min, max float64, offset, count int64) ([]ScoredMember, error)
- func (set *SortedSet) Rank(ctx context.Context, member string) (int64, error)
- func (set *SortedSet) Remove(ctx context.Context, members ...string) (int64, error)
- func (set *SortedSet) RemoveByScore(ctx context.Context, min, max float64) (int64, error)
- func (set *SortedSet) ReverseRange(ctx context.Context, start, stop int64) ([]ScoredMember, error)
- func (set *SortedSet) ReverseRank(ctx context.Context, member string) (int64, error)
- func (set *SortedSet) Score(ctx context.Context, member string) (float64, error)
- type Stream
- func (stream *Stream[T]) Ack(ctx context.Context, group string, ids ...string) (int64, error)
- func (stream *Stream[T]) Add(ctx context.Context, value T) (string, error)
- func (stream *Stream[T]) AddMaxLen(ctx context.Context, value T, maxLen int64) (string, error)
- func (stream *Stream[T]) AddWithID(ctx context.Context, id string, value T) (string, error)
- func (stream *Stream[T]) AddWithIDMaxLen(ctx context.Context, id string, value T, maxLen int64) (string, error)
- func (stream *Stream[T]) AutoClaim(ctx context.Context, group, consumer string, minIdle time.Duration, ...) (AutoClaimResult[T], error)
- func (stream *Stream[T]) Claim(ctx context.Context, group, consumer string, minIdle time.Duration, ...) ([]StreamEntry[T], error)
- func (stream *Stream[T]) Clear(ctx context.Context) error
- func (stream *Stream[T]) Consumers(ctx context.Context, group string) ([]StreamConsumerInfo, error)
- func (stream *Stream[T]) CreateGroup(ctx context.Context, group, startID string) error
- func (stream *Stream[T]) Delete(ctx context.Context, ids ...string) (int64, error)
- func (stream *Stream[T]) DeleteConsumer(ctx context.Context, group, consumer string) (int64, error)
- func (stream *Stream[T]) DeleteGroup(ctx context.Context, group string) (bool, error)
- func (stream *Stream[T]) Groups(ctx context.Context) ([]StreamGroupInfo, error)
- func (stream *Stream[T]) Key() string
- func (stream *Stream[T]) Len(ctx context.Context) (int64, error)
- func (stream *Stream[T]) Pending(ctx context.Context, group string, count int64) ([]PendingEntry, error)
- func (stream *Stream[T]) Range(ctx context.Context, start, end string, count int64) ([]StreamEntry[T], error)
- func (stream *Stream[T]) Read(ctx context.Context, afterID string, count int64) ([]StreamEntry[T], error)
- func (stream *Stream[T]) ReadBlock(ctx context.Context, afterID string, count int64, block time.Duration) ([]StreamEntry[T], error)
- func (stream *Stream[T]) ReadGroup(ctx context.Context, group, consumer string, count int64) ([]StreamEntry[T], error)
- func (stream *Stream[T]) ReadGroupFrom(ctx context.Context, group, consumer, startID string, count int64, ...) ([]StreamEntry[T], error)
- func (stream *Stream[T]) SetGroupID(ctx context.Context, group, id string) error
- func (stream *Stream[T]) TrimMaxLen(ctx context.Context, maxLen int64) (int64, error)
- type StreamConsumerInfo
- type StreamEntry
- type StreamGroupInfo
- type StringList
- func (list *StringList) Clear(ctx context.Context) error
- func (list *StringList) Key() string
- func (list *StringList) Len(ctx context.Context) (int64, error)
- func (list *StringList) PopLeft(ctx context.Context) (string, error)
- func (list *StringList) PopRight(ctx context.Context) (string, error)
- func (list *StringList) PushLeft(ctx context.Context, values ...string) (int64, error)
- func (list *StringList) PushRight(ctx context.Context, values ...string) (int64, error)
- func (list *StringList) Range(ctx context.Context, start, stop int64) ([]string, error)
- func (list *StringList) Trim(ctx context.Context, start, stop int64) error
- type StringSet
- func (set *StringSet) Add(ctx context.Context, members ...string) (int64, error)
- func (set *StringSet) Clear(ctx context.Context) error
- func (set *StringSet) Contains(ctx context.Context, member string) (bool, error)
- func (set *StringSet) Key() string
- func (set *StringSet) Len(ctx context.Context) (int64, error)
- func (set *StringSet) Members(ctx context.Context) ([]string, error)
- func (set *StringSet) Remove(ctx context.Context, members ...string) (int64, error)
- func (set *StringSet) Scan(ctx context.Context, cursor uint64, pattern string, count int64) (StringSetScan, error)
- type StringSetScan
- type TDigest
- func (digest *TDigest) Add(ctx context.Context, values ...float64) error
- func (digest *TDigest) CDF(ctx context.Context, values ...float64) ([]float64, error)
- func (digest *TDigest) Clear(ctx context.Context) error
- func (digest *TDigest) Create(ctx context.Context, compression int64) error
- func (digest *TDigest) Key() string
- func (digest *TDigest) Max(ctx context.Context) (float64, error)
- func (digest *TDigest) Min(ctx context.Context) (float64, error)
- func (digest *TDigest) Quantiles(ctx context.Context, quantiles ...float64) ([]float64, error)
- func (digest *TDigest) Rank(ctx context.Context, values ...float64) ([]int64, error)
- func (digest *TDigest) Reset(ctx context.Context) error
- func (digest *TDigest) ReverseRank(ctx context.Context, values ...float64) ([]int64, error)
- func (digest *TDigest) TrimmedMean(ctx context.Context, lowerQuantile, upperQuantile float64) (float64, error)
- type TimeSeries
- func (series *TimeSeries) Add(ctx context.Context, timestamp int64, value float64) (int64, error)
- func (series *TimeSeries) AddNow(ctx context.Context, value float64) (int64, error)
- func (series *TimeSeries) Clear(ctx context.Context) error
- func (series *TimeSeries) Create(ctx context.Context, options TimeSeriesOptions) error
- func (series *TimeSeries) Decrement(ctx context.Context, delta float64) (int64, error)
- func (series *TimeSeries) DeleteRange(ctx context.Context, start, end int64) (int64, error)
- func (series *TimeSeries) Get(ctx context.Context) (TimeSeriesSample, error)
- func (series *TimeSeries) Increment(ctx context.Context, delta float64) (int64, error)
- func (series *TimeSeries) Key() string
- func (series *TimeSeries) Range(ctx context.Context, start, end int64, count int64) ([]TimeSeriesSample, error)
- func (series *TimeSeries) RangeAll(ctx context.Context, count int64) ([]TimeSeriesSample, error)
- func (series *TimeSeries) ReverseRange(ctx context.Context, start, end int64, count int64) ([]TimeSeriesSample, error)
- type TimeSeriesOptions
- type TimeSeriesSample
- type TopK
- func (top *TopK) Add(ctx context.Context, items ...string) ([]TopKAddResult, error)
- func (top *TopK) Clear(ctx context.Context) error
- func (top *TopK) Count(ctx context.Context, items ...string) ([]int64, error)
- func (top *TopK) Key() string
- func (top *TopK) List(ctx context.Context) ([]TopKItem, error)
- func (top *TopK) Query(ctx context.Context, items ...string) ([]bool, error)
- func (top *TopK) Reserve(ctx context.Context, size int64) error
- func (top *TopK) ReserveWithOptions(ctx context.Context, size int64, options TopKOptions) error
- type TopKAddResult
- type TopKItem
- type TopKOptions
- type Value
- func (value *Value[T]) Delete(ctx context.Context) (bool, error)
- func (value *Value[T]) Exists(ctx context.Context) (bool, error)
- func (value *Value[T]) Expiration(ctx context.Context) (ExpirationInfo, error)
- func (value *Value[T]) Expire(ctx context.Context, ttl time.Duration) (bool, error)
- func (value *Value[T]) Get(ctx context.Context) (T, error)
- func (value *Value[T]) GetDelete(ctx context.Context) (T, error)
- func (value *Value[T]) Key() string
- func (value *Value[T]) Set(ctx context.Context, data T, ttl ...time.Duration) error
- func (value *Value[T]) SetNX(ctx context.Context, data T, ttl time.Duration) (bool, error)
- func (value *Value[T]) TTL(ctx context.Context) (time.Duration, error)
- type VectorMatch
- type VectorSearchOptions
- type VectorSet
- func (set *VectorSet) Add(ctx context.Context, member string, vector []float64) (bool, error)
- func (set *VectorSet) AttributesRaw(ctx context.Context, member string) (json.RawMessage, error)
- func (set *VectorSet) Card(ctx context.Context) (int64, error)
- func (set *VectorSet) Clear(ctx context.Context) error
- func (set *VectorSet) ClearAttributes(ctx context.Context, member string) (bool, error)
- func (set *VectorSet) Contains(ctx context.Context, member string) (bool, error)
- func (set *VectorSet) Dimension(ctx context.Context) (int64, error)
- func (set *VectorSet) Key() string
- func (set *VectorSet) Remove(ctx context.Context, member string) (bool, error)
- func (set *VectorSet) Search(ctx context.Context, vector []float64, options VectorSearchOptions) ([]VectorMatch, error)
- func (set *VectorSet) SearchByMember(ctx context.Context, member string, options VectorSearchOptions) ([]VectorMatch, error)
- func (set *VectorSet) SetAttributes(ctx context.Context, member string, attributes any) (bool, error)
- func (set *VectorSet) Vector(ctx context.Context, member string) ([]float64, error)
Constants ¶
const MaxDelayQueuePollBatch int64 = 1000
MaxDelayQueuePollBatch 是 Poll 和 Claim 允许的最大单次任务数。 该上限同时约束 Lua unpack 参数量、Redis 执行时间和网络响应大小。
const MaxRankingPageSize int64 = 1000
MaxRankingPageSize 限制 Page 单次读取的条目数,避免一次 Lua 处理过大的排行榜。
Variables ¶
var ( // ErrArrayValuesRequired 表示 ARINSERT/ARRING 缺少 Redis 要求的至少一个 value。 ErrArrayValuesRequired = errors.New("rueidistpl: array requires at least one value") // ErrInvalidArrayRingSize 表示 ARRING 的窗口大小不是正数。 ErrInvalidArrayRingSize = errors.New("rueidistpl: array ring size must be positive") )
var ( // ErrInvalidBitOffset 表示位偏移为负数。 ErrInvalidBitOffset = errors.New("rueidistpl: bit offset must not be negative") // ErrInvalidBitmapOperation 表示 BITOP 操作不是 AND、OR、XOR 或 NOT。 ErrInvalidBitmapOperation = errors.New("rueidistpl: invalid bitmap operation") )
var ( // ErrInvalidBloomErrorRate 表示 Bloom Filter 误判率不在 (0,1) 范围内。 ErrInvalidBloomErrorRate = errors.New("rueidistpl: bloom filter error rate must be between 0 and 1") // ErrInvalidBloomCapacity 表示 Bloom Filter 预计容量不是正数。 ErrInvalidBloomCapacity = errors.New("rueidistpl: bloom filter capacity must be positive") )
var ( // ErrClosed 表示 Redis 门面已经关闭,不能再创建或获取锁客户端。 ErrClosed = errors.New("rueidistpl: redis client is closed") // ErrInvalidLockerConfig 表示锁续期间隔不足以在租约过期前安全续期。 ErrInvalidLockerConfig = errors.New("rueidistpl: invalid locker configuration") // ErrLockLost 表示业务执行期间已失去分布式锁租约。 ErrLockLost = errors.New("rueidistpl: distributed lock lease lost") // ErrNilLockHandler 表示 WithLock 或 WithFencedLock 没有收到业务函数。 ErrNilLockHandler = errors.New("rueidistpl: lock handler must not be nil") )
var ( // ErrInvalidCountMinDimensions 表示宽度或深度不是正数。 ErrInvalidCountMinDimensions = errors.New("rueidistpl: count-min sketch width and depth must be positive") // ErrInvalidCountMinProbability 表示误差率或失败概率不在 (0,1) 范围内。 ErrInvalidCountMinProbability = errors.New("rueidistpl: count-min sketch error rate and probability must be between 0 and 1") // ErrInvalidCountMinIncrement 表示增量不是正数。 ErrInvalidCountMinIncrement = errors.New("rueidistpl: count-min sketch increment must be positive") )
var ( // ErrInvalidGeoCoordinate 表示经纬度超出 Redis GEO 接受范围。 ErrInvalidGeoCoordinate = errors.New("rueidistpl: invalid geo coordinate") // ErrInvalidGeoUnit 表示距离单位不是 m、km、ft 或 mi。 ErrInvalidGeoUnit = errors.New("rueidistpl: invalid geo unit") // ErrInvalidGeoRadius 表示搜索半径不是正数。 ErrInvalidGeoRadius = errors.New("rueidistpl: geo radius must be positive") )
var ( // ErrInvalidTDigestCompression 表示压缩参数不是正数。 ErrInvalidTDigestCompression = errors.New("rueidistpl: t-digest compression must be positive") // ErrInvalidTDigestValue 表示输入样本或查询值不是有限数。 ErrInvalidTDigestValue = errors.New("rueidistpl: t-digest value must be finite") // ErrInvalidTDigestQuantile 表示分位点不在 [0,1] 范围内。 ErrInvalidTDigestQuantile = errors.New("rueidistpl: t-digest quantile must be between 0 and 1") )
var ( // ErrInvalidTimeSeriesRetention 表示保留时间不能为负数。 ErrInvalidTimeSeriesRetention = errors.New("rueidistpl: time series retention must not be negative") // ErrInvalidTimeSeriesValue 表示样本值是 NaN 或无穷大。 ErrInvalidTimeSeriesValue = errors.New("rueidistpl: time series value must be finite") )
var ( // ErrInvalidTopK 表示跟踪的 Top-K 数量不是正数。 ErrInvalidTopK = errors.New("rueidistpl: top-k size must be positive") // ErrInvalidTopKOptions 表示 width、depth 或 decay 配置无效。 ErrInvalidTopKOptions = errors.New("rueidistpl: invalid top-k options") )
var ( // ErrVectorRequired 表示向量至少需要一个维度。 ErrVectorRequired = errors.New("rueidistpl: vector must not be empty") // ErrInvalidVectorValue 表示向量包含 NaN 或无穷大。 ErrInvalidVectorValue = errors.New("rueidistpl: vector values must be finite") )
var ErrDelayQueuePollLimit = errors.New("rueidistpl: delay queue poll limit exceeds maximum batch size")
ErrDelayQueuePollLimit 表示 Poll 或 Claim 的 limit 超过了安全批次上限。
var ErrEmptyChannels = errors.New("rueidistpl: at least one channel is required")
ErrEmptyChannels 表示订阅时没有提供任何 channel 或 pattern。
var ErrHyperLogLogSourcesRequired = errors.New("rueidistpl: hyperloglog merge requires at least one source")
ErrHyperLogLogSourcesRequired 表示 PFMERGE 没有提供任何来源 key。
var ErrIdempotencyLeaseLost = errors.New("rueidistpl: idempotency lease lost")
ErrIdempotencyLeaseLost 表示 Run 执行期间幂等标记已过期、被替换或无法续租。 收到该错误时不能假设业务未执行,调用方应依靠下游唯一约束或业务状态进行核对。
var ErrInvalidBatchResponse = errors.New("rueidistpl: invalid batch response")
ErrInvalidBatchResponse 表示 Rueidis 返回的批量结果数量或单 key 状态值不符合命令约定。
var ErrInvalidCuckooCapacity = errors.New("rueidistpl: cuckoo filter capacity must be positive")
ErrInvalidCuckooCapacity 表示 Cuckoo Filter 预计容量不是正数。
var ErrInvalidExpiration = errors.New("rueidistpl: expiration must be greater than zero")
ErrInvalidExpiration 表示要求过期的操作收到零值或负数 TTL。
var ErrInvalidExpirationResponse = errors.New("rueidistpl: invalid expiration response")
ErrInvalidExpirationResponse 表示 Redis 返回了 PTTL/HPTTL 约定之外的负数状态码。
var ErrInvalidMinIdle = errors.New("rueidistpl: stream minimum idle time must not be negative")
ErrInvalidMinIdle 表示 XCLAIM 收到了负数最小空闲时间。
var ErrInvalidRankingPage = errors.New("rueidistpl: invalid ranking page")
ErrInvalidRankingPage 表示分页偏移为负数、页大小不在 [1, MaxRankingPageSize] 内或下标溢出。
var ErrInvalidScore = errors.New("rueidistpl: sorted set score must not be NaN")
ErrInvalidScore 表示 ZSet 操作收到了 Redis 不接受的 NaN 分数。 正负无穷是 Redis 支持的合法边界,因此不会触发该错误。
var ErrInvalidStreamMaxLen = errors.New("rueidistpl: stream maximum length must be positive")
ErrInvalidStreamMaxLen 表示 Stream 最大长度不是正数。
var ErrRankingScoreMissing = errors.New("rueidistpl: ranking object has no score")
ErrRankingScoreMissing 表示 Hash 中存在排行榜对象,但对应 ZSet 分数已经缺失。
var ErrRankingValueMissing = errors.New("rueidistpl: ranking member has no object value")
ErrRankingValueMissing 表示 ZSet 中存在排行榜 ID,但对应 Hash 对象已经缺失。
var ErrStreamDataMissing = errors.New("rueidistpl: stream entry has no data field")
ErrStreamDataMissing 表示消息不是由本封装写入,缺少约定的 data 字段。
Functions ¶
func IsNotFound ¶
IsNotFound 统一判断 gocache 缓存未命中和 Rueidis Redis Nil。 因此可用于 Cache、Value、Hash、List、Ranking 等单值读取 API。
Types ¶
type Array ¶
type Array[T any] struct { // contains filtered or unexported fields }
Array 使用 Redis 8.8+ 原生 Array 保存 JSON 对象。 Array 可以高效表示稀疏下标;连接 Redis 8.6 及以下版本时,调用这些方法会收到未知命令错误。
func (*Array[T]) DeleteRanges ¶
DeleteRanges 删除一个或多个下标闭区间并返回实际删除数;空输入返回 0。
func (*Array[T]) Insert ¶
Insert 从内部插入游标开始连续追加对象,并返回最后写入的下标。 可用 Next 查看游标、Seek 调整游标;空输入返回 ErrArrayValuesRequired。
func (*Array[T]) LastItems ¶
LastItems 返回最近插入的最多 count 个对象。 reverse=false 按从旧到新的插入顺序返回,reverse=true 按从新到旧返回;count 非正时返回空切片。 count 限制 Redis 检查的槽位数,空槽会被跳过,因此实际返回的对象数可能更少。 需要保留空槽状态时使用 Range 或 GetMany。
func (*Array[T]) Range ¶
Range 返回 start 到 end 的闭区间;start>end 时按下标倒序返回。 Redis 的空槽不会被丢弃,而是表示为 Exists=false 的 ArrayItem。
func (*Array[T]) Ring ¶
Ring 按固定窗口大小循环写入对象,并返回最后写入的下标。 size 必须为正数,values 不能为空;缩小 size 时 Redis 会截断超出窗口的槽位。
func (*Array[T]) Scan ¶
Scan 只返回 start 到 end 闭区间内的非空槽位,start>end 时按下标倒序扫描。 limit 大于 0 时限制最多返回的槽位数,非正值表示不添加 LIMIT。
type ArrayRange ¶
ArrayRange 表示 ARDELRANGE 使用的下标闭区间。
type AutoClaimResult ¶
type AutoClaimResult[T any] struct { // NextStart 是下一次扫描时应传入的起始 ID;返回 0-0 表示本轮扫描结束。 NextStart string // Entries 是本次转移到新消费者名下的消息。 Entries []StreamEntry[T] // DeletedIDs 是在 Pending 列表中但已从 Stream 删除的 ID;Redis 7.0 起才会返回。 DeletedIDs []string }
AutoClaimResult 是 XAUTOCLAIM 的强类型返回值。
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
Bitmap 使用 Redis String 的位操作保存布尔状态集合。
func (*Bitmap) BitFieldGet ¶
func (bitmap *Bitmap) BitFieldGet(ctx context.Context, encoding string, offset int64) (int64, error)
BitFieldGet 将 String 中的一段位按 Redis BITFIELD 编码读取为整数。 encoding 使用 Redis 原生格式,例如 i8、u16;复杂的批量和溢出策略应直接使用 Rueidis Builder。
func (*Bitmap) Combine ¶
func (bitmap *Bitmap) Combine(ctx context.Context, operation BitmapOperation, destination string, additionalSources ...string) (int64, error)
Combine 将当前位图和 additionalSources 做位运算,结果写入逻辑 destination key,并返回结果字节数。 operation 支持 AND、OR、XOR 和 NOT;NOT 只能使用当前位图,不能提供 additionalSources。 Redis Cluster 要求 destination、当前 key 和所有 source 位于同一 slot。
type BitmapOperation ¶
type BitmapOperation string
BitmapOperation 表示 BITOP 支持的经典位运算。
const ( BitmapAnd BitmapOperation = "AND" BitmapOr BitmapOperation = "OR" BitmapXor BitmapOperation = "XOR" BitmapNot BitmapOperation = "NOT" )
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
BloomFilter 封装 RedisBloom 的 Bloom Filter 常用操作。 它适合空间敏感且允许少量假阳性的存在性判断。
func (*BloomFilter) Card ¶
func (filter *BloomFilter) Card(ctx context.Context) (int64, error)
Card 返回成功加入过滤器的近似唯一元素数。
func (*BloomFilter) Clear ¶
func (filter *BloomFilter) Clear(ctx context.Context) error
Clear 删除整个过滤器。
func (*BloomFilter) ExistsMany ¶
ExistsMany 批量判断并保持输入顺序;空输入不发送命令。
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache 是基于 gocache Rueidis Store 的 JSON 对象缓存。
func (*Cache[T]) GetWithTTL ¶
GetWithTTL 原子读取对象及 Redis key 的剩余 TTL,精度为毫秒,不使用客户端缓存。 -1ms 表示对象不过期;未命中可用 IsNotFound 判断;发生错误时对象和 TTL 都返回零值。
type ClaimedDelayed ¶ added in v0.2.0
ClaimedDelayed 是通过 Claim 取得、等待 ACK 或 NACK 的任务。 Token 是本次领取的所有权凭证;旧 worker 的 token 不能确认后来重新投递的同一任务。
type Config ¶
type Config struct {
// ClientOption 是 Rueidis 原生连接配置,例如地址、认证、集群和连接池参数。
ClientOption rueidis.ClientOption
// KeyPrefix 会自动添加到本包管理的全部业务 key 前面。
KeyPrefix string
// CacheTTL 是 NewCache[T] 的默认过期时间,非正值使用 10 分钟。
CacheTTL time.Duration
// ClientSideCacheTTL 控制 gocache Rueidis Store 的客户端缓存时间。
ClientSideCacheTTL time.Duration
// LockerOption 配置 rueidislock;其中 ClientOption 会统一使用上面的连接配置。
LockerOption rueidislock.LockerOption
}
Config 复用 Rueidis 与 rueidislock 的原生配置,只补充模板需要的缓存默认值。
type CountMinIncrement ¶
CountMinIncrement 是一个元素及其正整数增量。
type CountMinSketch ¶
type CountMinSketch struct {
// contains filtered or unexported fields
}
CountMinSketch 封装 RedisBloom 的 Count-Min Sketch 高频计数操作。
func (*CountMinSketch) Clear ¶
func (sketch *CountMinSketch) Clear(ctx context.Context) error
Clear 删除整个草图。
func (*CountMinSketch) Increment ¶
func (sketch *CountMinSketch) Increment(ctx context.Context, increments ...CountMinIncrement) ([]int64, error)
Increment 批量增加元素计数,并返回与输入顺序对应的新估算值;空输入不发送命令。
func (*CountMinSketch) InitByDimensions ¶
func (sketch *CountMinSketch) InitByDimensions(ctx context.Context, width, depth int64) error
InitByDimensions 按宽度和深度显式初始化草图。
func (*CountMinSketch) InitByProbability ¶
func (sketch *CountMinSketch) InitByProbability(ctx context.Context, errorRate, probability float64) error
InitByProbability 按误差率和失败概率显式初始化草图。
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter 是使用 Redis String 实现的 int64 原子计数器。
type CuckooFilter ¶
type CuckooFilter struct {
// contains filtered or unexported fields
}
CuckooFilter 封装 RedisBloom 的 Cuckoo Filter 常用操作。 相比 Bloom Filter,它支持删除元素和统计同一元素的插入次数。
func (*CuckooFilter) Clear ¶
func (filter *CuckooFilter) Clear(ctx context.Context) error
Clear 删除整个过滤器。
func (*CuckooFilter) ExistsMany ¶
ExistsMany 批量判断并保持输入顺序;空输入不发送命令。
type DelayQueue ¶
type DelayQueue[T any] struct { // contains filtered or unexported fields }
DelayQueue 是基于 Hash + ZSet 的延迟队列。 Claim 提供可见性超时与 ACK/NACK;兼容入口 Poll 仍是取出即删除的至多一次语义。
func NewDelayQueue ¶
func NewDelayQueue[T any](redis *Redis, namespace string) *DelayQueue[T]
NewDelayQueue 创建延迟队列;内部 key 自动使用相同的 Redis Cluster hash tag。
func (*DelayQueue[T]) Claim ¶ added in v0.2.0
func (queue *DelayQueue[T]) Claim(ctx context.Context, visibilityTimeout time.Duration, limit int64) ([]ClaimedDelayed[T], error)
Claim 使用 Redis 服务端时间领取到期任务,并设置 visibilityTimeout。 worker 崩溃后,租约到期的任务会在后续 Claim 中自动重新投递;成功必须调用 Ack,失败可调用 Nack。 网络错误意味着领取结果不确定,调用方应等待租约到期,不能立即无条件重试同一批业务副作用。
func (*DelayQueue[T]) Clear ¶
func (queue *DelayQueue[T]) Clear(ctx context.Context) error
Clear 删除队列的载荷、调度、处理中任务和所有权记录。
func (*DelayQueue[T]) Extend ¶ added in v0.2.0
func (queue *DelayQueue[T]) Extend(ctx context.Context, id, token string, visibilityTimeout time.Duration) (bool, error)
Extend 按所有权 token 延长尚未到期的处理租约;租约已失效时返回 false。
func (*DelayQueue[T]) InFlight ¶ added in v0.2.0
func (queue *DelayQueue[T]) InFlight(ctx context.Context) (int64, error)
InFlight 返回正在处理、尚未 ACK/NACK 的任务数量。
func (*DelayQueue[T]) Keys ¶
func (queue *DelayQueue[T]) Keys() (valuesKey, scoresKey string)
Keys 返回内部载荷 Hash 和调度 ZSet 的真实 key,主要用于监控和清理。
func (*DelayQueue[T]) Len ¶
func (queue *DelayQueue[T]) Len(ctx context.Context) (int64, error)
Len 返回当前等待调度的任务数量。
func (*DelayQueue[T]) Nack ¶ added in v0.2.0
func (queue *DelayQueue[T]) Nack(ctx context.Context, id, token string, dueAt time.Time) (bool, error)
Nack 按所有权 token 将任务重新调度到 dueAt;token 已失效时返回 false。
func (*DelayQueue[T]) Poll ¶
func (queue *DelayQueue[T]) Poll(ctx context.Context, now time.Time, limit int64) ([]Delayed[T], error)
Poll 原子取出并删除不晚于 now 的任务。 limit 不得超过 MaxDelayQueuePollBatch;由于是至多一次语义,被取出后即使 JSON 解码失败,任务也已从 Redis 删除。
func (*DelayQueue[T]) ReliableKeys ¶ added in v0.2.0
func (queue *DelayQueue[T]) ReliableKeys() (processingKey, claimsKey string)
ReliableKeys 返回可靠消费额外使用的处理中 ZSet 和所有权 Hash。
type Delayed ¶
type Delayed[T any] struct { // ID 是调度时指定的稳定任务标识;重复调度相同 ID 会覆盖原任务。 ID string // DueAt 是任务原定执行时间,精度为毫秒。 DueAt time.Time // Value 是反序列化后的任务载荷。 Value T }
Delayed 表示从延迟队列取出的到期任务。
type DeleteBatchResult ¶
type DeleteBatchResult struct {
Results []DeleteKeyResult
Deleted int64
Err error
}
DeleteBatchResult 同时保留逐 key 状态、成功删除总数和聚合错误。 即使 Err 非空,Results 中其他成功项和 Deleted 仍然有效。
type DeleteKeyResult ¶
DeleteKeyResult 记录 DeleteEach 中一个逻辑 key 的执行结果。
type ExistsBatchResult ¶
type ExistsBatchResult struct {
Results []ExistsKeyResult
Existing int64
Err error
}
ExistsBatchResult 同时保留逐 key 状态、实际存在总数和聚合错误。 即使 Err 非空,Results 中其他成功项和 Existing 仍然有效。
type ExistsKeyResult ¶
ExistsKeyResult 记录 ExistsEach 中一个逻辑 key 的存在状态。
type ExpirationInfo ¶
ExpirationInfo 是已经解释过 Redis 特殊 TTL 状态的结构化结果。
Exists=false 表示 key 或 field 不存在;Persistent=true 表示对象存在但没有过期时间; 只有 Exists=true 且 Persistent=false 时,TTL 才表示剩余有效期。
type Geo ¶
type Geo struct {
// contains filtered or unexported fields
}
Geo 是 Redis Geospatial 索引的便利封装。
func (*Geo) Distance ¶
func (geo *Geo) Distance(ctx context.Context, member1, member2 string, unit GeoUnit) (float64, error)
Distance 返回两个成员之间按 unit 表示的距离;成员不存在时返回 Rueidis Nil。
func (*Geo) SearchRadius ¶
func (geo *Geo) SearchRadius(ctx context.Context, longitude, latitude, radius float64, unit GeoUnit, options GeoSearchOptions) ([]GeoSearchResult, error)
SearchRadius 以经纬度为圆心搜索,并始终返回成员、距离和坐标。
func (*Geo) SearchRadiusByMember ¶
func (geo *Geo) SearchRadiusByMember(ctx context.Context, member string, radius float64, unit GeoUnit, options GeoSearchOptions) ([]GeoSearchResult, error)
SearchRadiusByMember 以已有 member 为圆心搜索,并始终返回成员、距离和坐标。
type GeoPosition ¶
GeoPosition 是一个成员的位置;Exists=false 表示成员不存在。
type GeoSearchOptions ¶
type GeoSearchOptions struct {
// Count 大于 0 时限制结果数。
Count int64
// Any 允许 Redis 在找到足够结果后提前停止;只有 Count>0 时有效。
Any bool
// Desc 为 true 时按距离从远到近返回,默认从近到远。
Desc bool
}
GeoSearchOptions 控制半径搜索的数量和顺序。
type GeoSearchResult ¶
GeoSearchResult 是带距离和坐标的 GEOSEARCH 结果。
type Hash ¶
type Hash[T any] struct { // contains filtered or unexported fields }
Hash 使用 Redis Hash 保存 JSON 对象,field 通常使用稳定业务 ID。
func (*Hash[T]) ExpirationField ¶
ExpirationField 返回结构化 field 过期状态,避免调用方自行解释 HPTTL 的 -1ms/-2ms。
func (*Hash[T]) ExpireField ¶
func (hash *Hash[T]) ExpireField(ctx context.Context, field string, ttl time.Duration) (bool, error)
ExpireField 设置单个 Hash field 的 TTL,需要 Redis 7.4+。
func (*Hash[T]) IncrementFloat ¶
func (hash *Hash[T]) IncrementFloat(ctx context.Context, field string, delta float64) (float64, error)
IncrementFloat 原子增加浮点 field,并返回增加后的值。
func (*Hash[T]) IncrementInt ¶
IncrementInt 和 IncrementFloat 适用于保存数字字符串的独立 Hash field。
func (*Hash[T]) PersistField ¶
PersistField 移除单个 field 的过期时间,需要 Redis 7.4+。
func (*Hash[T]) Scan ¶
func (hash *Hash[T]) Scan(ctx context.Context, cursor uint64, pattern string, count int64) (HashScan[T], error)
Scan 分批扫描 Hash。pattern 为空表示不过滤,count 非正时默认使用 100。 count 是 Redis 的数量提示,不保证每批严格返回该数量。
type HashScan ¶
type HashScan[T any] struct { // Cursor 为下一次扫描使用的游标;返回 0 表示扫描完成。 Cursor uint64 // Values 是本批次 field 到对象的映射。 Values map[string]T }
HashScan 表示一次 HSCAN 的游标和本批对象。
type HyperLogLog ¶
type HyperLogLog struct {
// contains filtered or unexported fields
}
HyperLogLog 是 Redis 近似去重计数结构。
func (*HyperLogLog) Clear ¶
func (hyperLogLog *HyperLogLog) Clear(ctx context.Context) error
Clear 删除整个 HyperLogLog key。
func (*HyperLogLog) Count ¶
func (hyperLogLog *HyperLogLog) Count(ctx context.Context) (int64, error)
Count 返回当前 HyperLogLog 的近似基数。
type Idempotency ¶
type Idempotency struct {
// contains filtered or unexported fields
}
Idempotency 使用 SET NX PX 记录已接收的业务 ID。
func (*Idempotency) Forget ¶
func (idempotency *Idempotency) Forget(ctx context.Context, id string) error
Forget 主动删除幂等标记,使相同 ID 可以再次执行。
func (*Idempotency) Run ¶
func (idempotency *Idempotency) Run(ctx context.Context, id string, ttl time.Duration, fn func(context.Context) error) (bool, error)
Run 仅为首次出现的 ID 执行 fn,并在执行期间按 ttl/3 自动续租。 fn 必须使用收到的 context;续租失败时该 context 会以 ErrIdempotencyLeaseLost 为 cause 取消。 fn 成功后会把标记有效期重新设置为完整 ttl;fn 失败时只删除本次持有的标记以允许重试。 Redis 幂等标记不能替代数据库唯一约束,也不提供跨 Redis 与外部系统的恰好一次事务。
type JSONDocument ¶
type JSONDocument[T any] struct { // contains filtered or unexported fields }
JSONDocument 使用 RedisJSON 保存一个可按 JSONPath 局部读写的强类型文档。 Redis 8 已内置 RedisJSON;旧版 Redis 需要单独安装 RedisJSON 模块。
func NewJSONDocument ¶
func NewJSONDocument[T any](redis *Redis, key string) *JSONDocument[T]
NewJSONDocument 创建强类型 JSON 文档并自动应用全局 key 前缀。
func (*JSONDocument[T]) Clear ¶
func (document *JSONDocument[T]) Clear(ctx context.Context) error
Clear 删除整个 JSON 文档。
func (*JSONDocument[T]) DeletePath ¶
DeletePath 删除路径匹配的值,并返回实际删除数量。
func (*JSONDocument[T]) Exists ¶
func (document *JSONDocument[T]) Exists(ctx context.Context) (bool, error)
Exists 判断整个 JSON 文档是否存在。
func (*JSONDocument[T]) Get ¶
func (document *JSONDocument[T]) Get(ctx context.Context) (T, error)
Get 读取并反序列化根文档;文档不存在时返回 T 的零值和 Redis Nil。
func (*JSONDocument[T]) GetPath ¶
func (document *JSONDocument[T]) GetPath(ctx context.Context, path string) (json.RawMessage, error)
GetPath 返回指定 JSONPath 的原始 JSON。 使用以 $ 开头的 JSONPath 时,RedisJSON 会返回匹配结果数组,调用方可按需要再解码。
func (*JSONDocument[T]) Key ¶
func (document *JSONDocument[T]) Key() string
Key 返回应用全局前缀后的真实 Redis key。
func (*JSONDocument[T]) Set ¶
func (document *JSONDocument[T]) Set(ctx context.Context, value T) error
Set 新增或覆盖根文档。
func (*JSONDocument[T]) SetNX ¶
func (document *JSONDocument[T]) SetNX(ctx context.Context, value T) (bool, error)
SetNX 仅在文档不存在时写入根文档,写入成功返回 true。
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List 使用 Redis List 保存 JSON 对象。
type PendingEntry ¶
type PendingEntry struct {
// ID 是 Redis Stream 消息 ID。
ID string
// Consumer 是当前持有该 Pending 消息的消费者。
Consumer string
// Idle 是距离上次投递经过的时间。
Idle time.Duration
// Deliveries 是累计投递次数。
Deliveries int64
}
PendingEntry 描述消费组中一条尚未 ACK 的消息。
type PubSub ¶
type PubSub[T any] struct { // contains filtered or unexported fields }
PubSub 为消息提供 JSON 编解码和统一 channel 前缀。
func (*PubSub[T]) PublishShard ¶
PublishShard 发布 Redis Cluster Sharded Pub/Sub 消息。
func (*PubSub[T]) Subscribe ¶
func (pubsub *PubSub[T]) Subscribe(ctx context.Context, handler func(PubSubMessage[T]) error, channels ...string) error
Subscribe 阻塞直到 ctx 取消、连接失败或 handler 返回错误。
func (*PubSub[T]) SubscribePattern ¶
func (pubsub *PubSub[T]) SubscribePattern(ctx context.Context, handler func(PubSubMessage[T]) error, patterns ...string) error
SubscribePattern 按模式订阅,例如传入 "order:*"。
func (*PubSub[T]) SubscribeShard ¶
func (pubsub *PubSub[T]) SubscribeShard(ctx context.Context, handler func(PubSubMessage[T]) error, channels ...string) error
SubscribeShard 使用 Redis Cluster Sharded Pub/Sub。
type PubSubMessage ¶
type PubSubMessage[T any] struct { // Channel 是去掉命名空间前缀后的逻辑 channel。 Channel string // Pattern 是模式订阅命中的逻辑 pattern;普通订阅时为空。 Pattern string // Value 是消息体反序列化后的业务对象。 Value T }
PubSubMessage 是已经完成 JSON 解码和逻辑 channel 去前缀的消息。
type Ranked ¶
type Ranked[T any] struct { // ID 是稳定业务标识,同时作为 ZSet member 和 Hash field。 ID string // Score 是用于倒序排名的分数。 Score float64 // Value 是与 ID 对应的业务对象。 Value T }
Ranked 是包含业务 ID、分数和对象内容的排行榜条目。
type Ranking ¶
type Ranking[T any] struct { // contains filtered or unexported fields }
Ranking 使用 Hash 保存对象、ZSet 保存稳定 ID 与分数。 两个键使用同一 Redis Cluster hash tag,Upsert 和 Remove 由 Lua 原子执行。
func NewRanking ¶
NewRanking 创建对象排行榜。内部两个 key 自动使用相同的 Cluster hash tag。
func (*Ranking[T]) Page ¶ added in v0.2.0
Page 从零基 offset 开始按分数降序读取 limit 项;每页最多 MaxRankingPageSize 项。 每页内部是同一时刻的快照;并发更新时不同页之间可能出现重复或遗漏。
func (*Ranking[T]) Range ¶
Range 按分数降序返回零基排名闭区间内的对象,支持 Redis 的负下标。 该兼容接口不限制返回条目数;大排行榜应使用 Page 控制单次 Lua 的工作量。
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis 统一管理业务客户端、JSON 缓存和按需创建的分布式锁客户端。
func (*Redis) BloomFilter ¶
func (redis *Redis) BloomFilter(key string) *BloomFilter
BloomFilter 创建过滤器并自动应用全局 key 前缀。
func (*Redis) CountMinSketch ¶
func (redis *Redis) CountMinSketch(key string) *CountMinSketch
CountMinSketch 创建草图并自动应用全局 key 前缀。
func (*Redis) CuckooFilter ¶
func (redis *Redis) CuckooFilter(key string) *CuckooFilter
CuckooFilter 创建过滤器并自动应用全局 key 前缀。
func (*Redis) Delete ¶
Delete 删除一个或多个逻辑 key,并返回实际删除的 key 数量。 多个 key 分别发送 DEL,因此在 Redis Cluster 中不要求这些 key 位于同一 slot。 部分失败时返回已确认的删除数量和聚合错误;需要逐 key 明细时使用 DeleteEach。
func (*Redis) DeleteEach ¶
func (redis *Redis) DeleteEach(ctx context.Context, keys ...string) DeleteBatchResult
DeleteEach 逐 key 执行 DEL,返回与输入顺序一致的明细。 每个 key 使用独立命令,因此可以安全处理 Redis Cluster 中跨 Slot 的输入。 大批次会分块执行;某个 key 失败不会阻止后续 key,ctx 取消后不再发送后续分块。
func (*Redis) Exists ¶
Exists 返回实际存在的逻辑 key 数量;多个 key 会分别查询以兼容 Redis Cluster。 部分失败时返回已确认的存在数量和聚合错误;需要逐 key 明细时使用 ExistsEach。
func (*Redis) ExistsEach ¶
func (redis *Redis) ExistsEach(ctx context.Context, keys ...string) ExistsBatchResult
ExistsEach 逐 key 执行 EXISTS,返回与输入顺序一致的明细。 每个 key 使用独立命令,因此可以安全处理 Redis Cluster 中跨 Slot 的输入。 大批次会分块执行;某个 key 失败不会阻止后续 key,ctx 取消后不再发送后续分块。
func (*Redis) Expiration ¶
Expiration 返回逻辑 key 的结构化过期状态,调用方无需再解释 PTTL 的 -1ms/-2ms。
func (*Redis) FencingKey ¶ added in v0.2.0
FencingKey 返回某个锁名对应的 fencing 计数器 key。 该 key 不应删除或设置过期时间,否则 token 可能倒退。
func (*Redis) HyperLogLog ¶
func (redis *Redis) HyperLogLog(key string) *HyperLogLog
HyperLogLog 创建近似去重计数器并自动应用全局 key 前缀。
func (*Redis) Idempotency ¶
func (redis *Redis) Idempotency(namespace string) *Idempotency
Idempotency 创建带独立 key 命名空间的幂等控制器。
func (*Redis) Lock ¶
func (redis *Redis) Lock(ctx context.Context, name string) (context.Context, context.CancelFunc, error)
Lock 等待获得自动续期的分布式锁。
func (*Redis) LockFenced ¶ added in v0.2.0
func (redis *Redis) LockFenced(ctx context.Context, name string) (context.Context, int64, context.CancelFunc, error)
LockFenced 等待获得锁,并生成一个单调递增的 fencing token。 下游资源必须持久化并拒绝小于等于已见最大值的 token,才能阻止失去租约的旧持有者继续写入。
func (*Redis) StringList ¶
func (redis *Redis) StringList(key string) *StringList
StringList 返回保存原始字符串的 List;对象列表使用 NewList[T]。
func (*Redis) TimeSeries ¶
func (redis *Redis) TimeSeries(key string) *TimeSeries
TimeSeries 创建时间序列并自动应用全局 key 前缀。
func (*Redis) TryLock ¶
func (redis *Redis) TryLock(ctx context.Context, name string) (context.Context, context.CancelFunc, error)
TryLock 只尝试一次;锁已被占用时返回 rueidislock.ErrNotLocked。
func (*Redis) TryLockFenced ¶ added in v0.2.0
func (redis *Redis) TryLockFenced(ctx context.Context, name string) (context.Context, int64, context.CancelFunc, error)
TryLockFenced 只尝试一次获取锁,并在成功后生成 fencing token。
type ScoredMember ¶
type ScoredMember struct {
// Member 是稳定的字符串成员。
Member string
// Score 用于排序,Redis 按 float64 保存。
Score float64
}
ScoredMember 表示 ZSet 的字符串成员及其分数。
type Set ¶
type Set[T any] struct { // contains filtered or unexported fields }
Set 使用 Redis Set 保存 JSON 对象,适合去重、成员判断和无序集合。 Redis 以 JSON 字节串判断成员是否相同;自定义 MarshalJSON 时应保证同一业务值的输出稳定。
type SetScan ¶
type SetScan[T any] struct { // Cursor 是下一次扫描使用的游标;返回 0 表示扫描完成。 Cursor uint64 // Values 是本批已完成 JSON 解码的成员,Redis Set 不保证顺序。 Values []T }
SetScan 表示一次泛型 Set 游标扫描结果。
type SortedSet ¶
type SortedSet struct {
// contains filtered or unexported fields
}
SortedSet 是 member 为字符串的通用 Redis ZSet。
func (*SortedSet) AddMany ¶
func (set *SortedSet) AddMany(ctx context.Context, members ...ScoredMember) error
AddMany 使用一次 ZADD 批量新增或更新成员。
func (*SortedSet) RangeByScore ¶
func (set *SortedSet) RangeByScore(ctx context.Context, min, max float64, offset, count int64) ([]ScoredMember, error)
RangeByScore 按分数升序查询,min/max 为闭区间;可使用 math.Inf 表示无穷。
func (*SortedSet) RemoveByScore ¶
RemoveByScore 删除闭区间分数内的成员,可使用 math.Inf 表示无穷。
func (*SortedSet) ReverseRange ¶
ReverseRange 按分数降序返回排名闭区间内的成员及分数。
func (*SortedSet) ReverseRank ¶
ReverseRank 返回成员按分数降序排列的零基排名。
type Stream ¶
type Stream[T any] struct { // contains filtered or unexported fields }
Stream 使用单个 data field 保存 JSON 对象。
func (*Stream[T]) AddMaxLen ¶
AddMaxLen 使用 Redis 自动生成的 ID 添加消息,并以 MAXLEN ~ 近似裁剪 Stream。 近似裁剪通常比精确裁剪更高效,但长度可能暂时略大于 maxLen。
func (*Stream[T]) AddWithIDMaxLen ¶
func (stream *Stream[T]) AddWithIDMaxLen(ctx context.Context, id string, value T, maxLen int64) (string, error)
AddWithIDMaxLen 使用指定 ID 添加消息,并以 MAXLEN ~ 近似裁剪 Stream。
func (*Stream[T]) AutoClaim ¶
func (stream *Stream[T]) AutoClaim(ctx context.Context, group, consumer string, minIdle time.Duration, start string, count int64) (AutoClaimResult[T], error)
AutoClaim 扫描 Pending 列表,将空闲时间不少于 minIdle 的消息自动转移给 consumer。 start 为空时从 0-0 开始;count 非正时默认每次处理 100 条。该命令需要 Redis 6.2+。
func (*Stream[T]) Claim ¶
func (stream *Stream[T]) Claim(ctx context.Context, group, consumer string, minIdle time.Duration, ids ...string) ([]StreamEntry[T], error)
Claim 将空闲时间不少于 minIdle 的 Pending 消息转移给 consumer。 minIdle 不能为负;小于 1ms 的正值提升为 1ms,零值表示立即允许转移。
func (*Stream[T]) CreateGroup ¶
CreateGroup 创建消费组;组已存在时也返回 nil。
func (*Stream[T]) DeleteConsumer ¶
DeleteConsumer 从消费组中删除消费者,返回被一并丢弃的 Pending 消息数。 调用前应先确认或转移该消费者的 Pending 消息,避免消息失去归属。
func (*Stream[T]) DeleteGroup ¶
DeleteGroup 删除消费组及其 Pending 状态,返回该消费组是否存在并被删除。
func (*Stream[T]) Groups ¶
func (stream *Stream[T]) Groups(ctx context.Context) ([]StreamGroupInfo, error)
Groups 返回 Stream 的全部消费组状态,包含 Pending 数和可用时的 lag。
func (*Stream[T]) Pending ¶
func (stream *Stream[T]) Pending(ctx context.Context, group string, count int64) ([]PendingEntry, error)
Pending 返回消费组中最多 count 条待确认消息及其消费者、空闲时间和投递次数。
func (*Stream[T]) Range ¶
func (stream *Stream[T]) Range(ctx context.Context, start, end string, count int64) ([]StreamEntry[T], error)
Range 按 ID 闭区间读取消息;count 非正表示不添加 COUNT 限制。
func (*Stream[T]) Read ¶
func (stream *Stream[T]) Read(ctx context.Context, afterID string, count int64) ([]StreamEntry[T], error)
Read 从 afterID 之后非阻塞读取消息;count 非正时默认读取 100 条。
func (*Stream[T]) ReadBlock ¶
func (stream *Stream[T]) ReadBlock(ctx context.Context, afterID string, count int64, block time.Duration) ([]StreamEntry[T], error)
ReadBlock 最多阻塞 block 等待消息;block 非正时退化为非阻塞 Read,小于 1ms 的正值提升为 1ms。
func (*Stream[T]) ReadGroup ¶
func (stream *Stream[T]) ReadGroup(ctx context.Context, group, consumer string, count int64) ([]StreamEntry[T], error)
ReadGroup 读取尚未投递给其他消费者的新消息。
func (*Stream[T]) ReadGroupFrom ¶
func (stream *Stream[T]) ReadGroupFrom(ctx context.Context, group, consumer, startID string, count int64, block time.Duration) ([]StreamEntry[T], error)
ReadGroupFrom 可读取新消息(startID 为 ">")或当前消费者的 Pending 消息。 block 小于 1ms 的正值提升为 1ms,避免 Redis 将 BLOCK 0 解释为无限等待。
func (*Stream[T]) SetGroupID ¶
SetGroupID 修改消费组的最后投递 ID,可用于重放或跳过历史消息。 该操作不会清理已有 Pending 消息,调用前应确认业务重放语义。
type StreamConsumerInfo ¶
type StreamConsumerInfo struct {
// Name 是消费者名称。
Name string
// Pending 是归属该消费者且尚未 ACK 的消息数。
Pending int64
// Idle 是距离该消费者最后一次交互的时间。
Idle time.Duration
// Inactive 是距离该消费者最后一次成功投递的时间,Redis 7.2+ 提供。
Inactive time.Duration
// InactiveKnown 表示当前 Redis 响应是否包含 Inactive。
InactiveKnown bool
}
StreamConsumerInfo 描述 XINFO CONSUMERS 返回的单个消费者状态。
type StreamEntry ¶
type StreamEntry[T any] struct { // ID 是 Redis Stream 消息 ID。 ID string // Value 是 data 字段中的业务对象。 Value T }
StreamEntry 表示一条已经完成 JSON 解码的 Stream 消息。
type StreamGroupInfo ¶
type StreamGroupInfo struct {
// Name 是消费组名称。
Name string
// Consumers 是该组已知消费者数。
Consumers int64
// Pending 是已投递但尚未 ACK 的消息数。
Pending int64
// LastDeliveredID 是最后一条已投递消息的 ID。
LastDeliveredID string
// EntriesRead 是 Redis 估算的已读取消息数。
EntriesRead int64
// EntriesReadKnown 表示 Redis 是否能给出 EntriesRead。
EntriesReadKnown bool
// Lag 是尚未投递给该组的消息数。
Lag int64
// LagKnown 表示 Redis 是否能给出 Lag。
LagKnown bool
}
StreamGroupInfo 描述 XINFO GROUPS 返回的消费组运行状态。
type StringList ¶
type StringList struct {
// contains filtered or unexported fields
}
StringList 是直接保存字符串的 Redis List。
func (*StringList) Clear ¶
func (list *StringList) Clear(ctx context.Context) error
Clear 删除整个列表 key。
func (*StringList) Len ¶
func (list *StringList) Len(ctx context.Context) (int64, error)
Len 返回列表长度。
func (*StringList) PopLeft ¶
func (list *StringList) PopLeft(ctx context.Context) (string, error)
PopLeft 从左侧弹出一个字符串;空列表返回 Redis Nil 错误。
func (*StringList) PopRight ¶
func (list *StringList) PopRight(ctx context.Context) (string, error)
PopRight 从右侧弹出一个字符串;空列表返回 Redis Nil 错误。
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
StringSet 是 member 为字符串的 Redis Set。
type StringSetScan ¶
type StringSetScan struct {
// Cursor 是下一次扫描使用的游标;返回 0 表示扫描完成。
Cursor uint64
// Members 是本批字符串成员。
Members []string
}
StringSetScan 表示一次字符串 Set 游标扫描结果。
type TDigest ¶
type TDigest struct {
// contains filtered or unexported fields
}
TDigest 封装 RedisBloom 的 t-digest 分布统计操作。
func (*TDigest) ReverseRank ¶
ReverseRank 返回大于各值的估算样本数量。
type TimeSeries ¶
type TimeSeries struct {
// contains filtered or unexported fields
}
TimeSeries 封装 RedisTimeSeries 的常用单序列操作。 Redis 8 已内置 RedisTimeSeries;旧版 Redis 需要单独安装模块。
func (*TimeSeries) Clear ¶
func (series *TimeSeries) Clear(ctx context.Context) error
Clear 删除整个时间序列。
func (*TimeSeries) Create ¶
func (series *TimeSeries) Create(ctx context.Context, options TimeSeriesOptions) error
Create 显式创建时间序列。直接调用 Add 时 Redis 也可以按默认配置自动创建。
func (*TimeSeries) DeleteRange ¶
DeleteRange 删除毫秒时间戳闭区间内的样本,并返回删除数量。
func (*TimeSeries) Get ¶
func (series *TimeSeries) Get(ctx context.Context) (TimeSeriesSample, error)
Get 返回时间戳最大的最新样本;序列不存在或没有样本时返回 Redis Nil。
func (*TimeSeries) Range ¶
func (series *TimeSeries) Range(ctx context.Context, start, end int64, count int64) ([]TimeSeriesSample, error)
Range 返回毫秒时间戳闭区间内按时间升序排列的样本;count 非正时不限制数量。
func (*TimeSeries) RangeAll ¶
func (series *TimeSeries) RangeAll(ctx context.Context, count int64) ([]TimeSeriesSample, error)
RangeAll 返回整个时间序列;count 非正时不限制数量。
func (*TimeSeries) ReverseRange ¶
func (series *TimeSeries) ReverseRange(ctx context.Context, start, end int64, count int64) ([]TimeSeriesSample, error)
ReverseRange 返回毫秒时间戳闭区间内按时间降序排列的样本;count 非正时不限制数量。
type TimeSeriesOptions ¶
type TimeSeriesOptions struct {
// Retention 为零表示永久保留;负数无效。
Retention time.Duration
// Labels 用于查询和聚合;写入命令会按名称排序以保证稳定。
Labels map[string]string
}
TimeSeriesOptions 配置时间序列的保留时间和标签。
type TimeSeriesSample ¶
TimeSeriesSample 是一个毫秒时间戳及其浮点样本值。
type TopK ¶
type TopK struct {
// contains filtered or unexported fields
}
TopK 封装 RedisBloom 的 Top-K 高频元素追踪操作。
func (*TopK) ReserveWithOptions ¶
ReserveWithOptions 使用完整精度参数初始化 Top-K 草图。
type TopKAddResult ¶
TopKAddResult 表示一次添加及可能被 Top-K 列表挤出的元素。
type TopKOptions ¶
TopKOptions 配置 Top-K 草图的精度和衰减。
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
Value 使用单个 Redis String 保存 JSON 对象,不经过 gocache。
func (*Value[T]) Expiration ¶
func (value *Value[T]) Expiration(ctx context.Context) (ExpirationInfo, error)
Expiration 返回结构化过期状态,避免调用方自行解释 TTL 的 -1ms/-2ms。
func (*Value[T]) GetDelete ¶
GetDelete 原子读取并删除对象;key 不存在时返回 Redis Nil 错误。 该命令需要 Redis 6.2+;发生任何错误时返回 T 的零值。
type VectorMatch ¶
VectorMatch 是一个相似元素及其余弦相似度分数。
type VectorSearchOptions ¶
type VectorSearchOptions struct {
// Count 是最多返回数量,非正时默认返回 10 个。
Count int64
// Filter 是针对元素属性的 Redis Vector Set 过滤表达式;为空表示不过滤。
Filter string
}
VectorSearchOptions 配置向量相似度搜索。
type VectorSet ¶
type VectorSet struct {
// contains filtered or unexported fields
}
VectorSet 封装 Redis 8.0+ 原生 Vector Set 的常用操作。
func (*VectorSet) AttributesRaw ¶
AttributesRaw 返回元素属性的原始 JSON;元素不存在时返回 Redis Nil。
func (*VectorSet) ClearAttributes ¶
ClearAttributes 清空元素属性;元素存在时返回 true。
func (*VectorSet) Search ¶
func (set *VectorSet) Search(ctx context.Context, vector []float64, options VectorSearchOptions) ([]VectorMatch, error)
Search 按给定向量返回相似元素,结果按相似度从高到低排列。
func (*VectorSet) SearchByMember ¶
func (set *VectorSet) SearchByMember(ctx context.Context, member string, options VectorSearchOptions) ([]VectorMatch, error)
SearchByMember 使用已有元素的向量搜索相似元素。
Source Files
¶
- array.go
- batch.go
- bitmap.go
- bloom_filter.go
- cache.go
- client.go
- count_min_sketch.go
- cuckoo_filter.go
- delay_queue.go
- doc.go
- expiration.go
- geo.go
- hash.go
- hyperloglog.go
- idempotency.go
- json.go
- json_document.go
- list.go
- ownership.go
- pubsub.go
- ranking.go
- set.go
- sorted_set.go
- stream.go
- structures.go
- t_digest.go
- time_series.go
- top_k.go
- value.go
- vector_set.go