forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/redis/go-redis/v9/stream_commands.go

764 lines
13 KiB
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
package redis
import (
"context"
"time"
)
type StreamCmdable interface {
XAdd(ctx context.Context, a *XAddArgs) *StringCmd
2024-02-18 10:42:21 +00:00
XDel(ctx context.Context, stream string, ids ...string) *IntCmd
2024-02-18 10:42:21 +00:00
XLen(ctx context.Context, stream string) *IntCmd
2024-02-18 10:42:21 +00:00
XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
2024-02-18 10:42:21 +00:00
XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
2024-02-18 10:42:21 +00:00
XRevRange(ctx context.Context, stream string, start, stop string) *XMessageSliceCmd
2024-02-18 10:42:21 +00:00
XRevRangeN(ctx context.Context, stream string, start, stop string, count int64) *XMessageSliceCmd
2024-02-18 10:42:21 +00:00
XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd
2024-02-18 10:42:21 +00:00
XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd
2024-02-18 10:42:21 +00:00
XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd
2024-02-18 10:42:21 +00:00
XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd
2024-02-18 10:42:21 +00:00
XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd
2024-02-18 10:42:21 +00:00
XGroupDestroy(ctx context.Context, stream, group string) *IntCmd
2024-02-18 10:42:21 +00:00
XGroupCreateConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
2024-02-18 10:42:21 +00:00
XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
2024-02-18 10:42:21 +00:00
XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd
2024-02-18 10:42:21 +00:00
XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd
2024-02-18 10:42:21 +00:00
XPending(ctx context.Context, stream, group string) *XPendingCmd
2024-02-18 10:42:21 +00:00
XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd
2024-02-18 10:42:21 +00:00
XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd
2024-02-18 10:42:21 +00:00
XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd
2024-02-18 10:42:21 +00:00
XAutoClaim(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimCmd
2024-02-18 10:42:21 +00:00
XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimJustIDCmd
2024-02-18 10:42:21 +00:00
XTrimMaxLen(ctx context.Context, key string, maxLen int64) *IntCmd
2024-02-18 10:42:21 +00:00
XTrimMaxLenApprox(ctx context.Context, key string, maxLen, limit int64) *IntCmd
2024-02-18 10:42:21 +00:00
XTrimMinID(ctx context.Context, key string, minID string) *IntCmd
2024-02-18 10:42:21 +00:00
XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd
2024-02-18 10:42:21 +00:00
XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
2024-02-18 10:42:21 +00:00
XInfoStream(ctx context.Context, key string) *XInfoStreamCmd
2024-02-18 10:42:21 +00:00
XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd
2024-02-18 10:42:21 +00:00
XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd
}
// XAddArgs accepts values in the following formats:
2024-02-18 10:42:21 +00:00
// - XAddArgs.Values = []interface{}{"key1", "value1", "key2", "value2"}
2024-02-18 10:42:21 +00:00
// - XAddArgs.Values = []string("key1", "value1", "key2", "value2")
2024-02-18 10:42:21 +00:00
// - XAddArgs.Values = map[string]interface{}{"key1": "value1", "key2": "value2"}
2024-02-18 10:42:21 +00:00
//
2024-02-18 10:42:21 +00:00
// Note that map will not preserve the order of key-value pairs.
2024-02-18 10:42:21 +00:00
// MaxLen/MaxLenApprox and MinID are in conflict, only one of them can be used.
2024-02-18 10:42:21 +00:00
type XAddArgs struct {
Stream string
2024-02-18 10:42:21 +00:00
NoMkStream bool
MaxLen int64 // MAXLEN N
MinID string
2024-02-18 10:42:21 +00:00
// Approx causes MaxLen and MinID to use "~" matcher (instead of "=").
2024-02-18 10:42:21 +00:00
Approx bool
Limit int64
ID string
2024-02-18 10:42:21 +00:00
Values interface{}
}
func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 11)
2024-02-18 10:42:21 +00:00
args = append(args, "xadd", a.Stream)
2024-02-18 10:42:21 +00:00
if a.NoMkStream {
2024-02-18 10:42:21 +00:00
args = append(args, "nomkstream")
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
switch {
2024-02-18 10:42:21 +00:00
case a.MaxLen > 0:
2024-02-18 10:42:21 +00:00
if a.Approx {
2024-02-18 10:42:21 +00:00
args = append(args, "maxlen", "~", a.MaxLen)
2024-02-18 10:42:21 +00:00
} else {
2024-02-18 10:42:21 +00:00
args = append(args, "maxlen", a.MaxLen)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
case a.MinID != "":
2024-02-18 10:42:21 +00:00
if a.Approx {
2024-02-18 10:42:21 +00:00
args = append(args, "minid", "~", a.MinID)
2024-02-18 10:42:21 +00:00
} else {
2024-02-18 10:42:21 +00:00
args = append(args, "minid", a.MinID)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if a.Limit > 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "limit", a.Limit)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if a.ID != "" {
2024-02-18 10:42:21 +00:00
args = append(args, a.ID)
2024-02-18 10:42:21 +00:00
} else {
2024-02-18 10:42:21 +00:00
args = append(args, "*")
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
args = appendArg(args, a.Values)
cmd := NewStringCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XDel(ctx context.Context, stream string, ids ...string) *IntCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"xdel", stream}
2024-02-18 10:42:21 +00:00
for _, id := range ids {
2024-02-18 10:42:21 +00:00
args = append(args, id)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XLen(ctx context.Context, stream string) *IntCmd {
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, "xlen", stream)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXMessageSliceCmd(ctx, "xrange", stream, start, stop)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXMessageSliceCmd(ctx, "xrange", stream, start, stop, "count", count)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXMessageSliceCmd(ctx, "xrevrange", stream, start, stop)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXMessageSliceCmd(ctx, "xrevrange", stream, start, stop, "count", count)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
type XReadArgs struct {
Streams []string // list of streams and ids, e.g. stream1 stream2 id1 id2
Count int64
Block time.Duration
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 6+len(a.Streams))
2024-02-18 10:42:21 +00:00
args = append(args, "xread")
keyPos := int8(1)
2024-02-18 10:42:21 +00:00
if a.Count > 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "count")
2024-02-18 10:42:21 +00:00
args = append(args, a.Count)
2024-02-18 10:42:21 +00:00
keyPos += 2
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if a.Block >= 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "block")
2024-02-18 10:42:21 +00:00
args = append(args, int64(a.Block/time.Millisecond))
2024-02-18 10:42:21 +00:00
keyPos += 2
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
args = append(args, "streams")
2024-02-18 10:42:21 +00:00
keyPos++
2024-02-18 10:42:21 +00:00
for _, s := range a.Streams {
2024-02-18 10:42:21 +00:00
args = append(args, s)
2024-02-18 10:42:21 +00:00
}
cmd := NewXStreamSliceCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
if a.Block >= 0 {
2024-02-18 10:42:21 +00:00
cmd.setReadTimeout(a.Block)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd.SetFirstKeyPos(keyPos)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd {
2024-02-18 10:42:21 +00:00
return c.XRead(ctx, &XReadArgs{
2024-02-18 10:42:21 +00:00
Streams: streams,
Block: -1,
2024-02-18 10:42:21 +00:00
})
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd {
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd(ctx, "xgroup", "create", stream, group, start)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd {
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd(ctx, "xgroup", "create", stream, group, start, "mkstream")
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd {
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd(ctx, "xgroup", "setid", stream, group, start)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd {
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, "xgroup", "destroy", stream, group)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XGroupCreateConsumer(ctx context.Context, stream, group, consumer string) *IntCmd {
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, "xgroup", "createconsumer", stream, group, consumer)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd {
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, "xgroup", "delconsumer", stream, group, consumer)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
type XReadGroupArgs struct {
Group string
2024-02-18 10:42:21 +00:00
Consumer string
Streams []string // list of streams and ids, e.g. stream1 stream2 id1 id2
Count int64
Block time.Duration
NoAck bool
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 10+len(a.Streams))
2024-02-18 10:42:21 +00:00
args = append(args, "xreadgroup", "group", a.Group, a.Consumer)
keyPos := int8(4)
2024-02-18 10:42:21 +00:00
if a.Count > 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "count", a.Count)
2024-02-18 10:42:21 +00:00
keyPos += 2
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if a.Block >= 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "block", int64(a.Block/time.Millisecond))
2024-02-18 10:42:21 +00:00
keyPos += 2
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if a.NoAck {
2024-02-18 10:42:21 +00:00
args = append(args, "noack")
2024-02-18 10:42:21 +00:00
keyPos++
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
args = append(args, "streams")
2024-02-18 10:42:21 +00:00
keyPos++
2024-02-18 10:42:21 +00:00
for _, s := range a.Streams {
2024-02-18 10:42:21 +00:00
args = append(args, s)
2024-02-18 10:42:21 +00:00
}
cmd := NewXStreamSliceCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
if a.Block >= 0 {
2024-02-18 10:42:21 +00:00
cmd.setReadTimeout(a.Block)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd.SetFirstKeyPos(keyPos)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"xack", stream, group}
2024-02-18 10:42:21 +00:00
for _, id := range ids {
2024-02-18 10:42:21 +00:00
args = append(args, id)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XPending(ctx context.Context, stream, group string) *XPendingCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXPendingCmd(ctx, "xpending", stream, group)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
type XPendingExtArgs struct {
Stream string
Group string
Idle time.Duration
Start string
End string
Count int64
2024-02-18 10:42:21 +00:00
Consumer string
}
func (c cmdable) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 9)
2024-02-18 10:42:21 +00:00
args = append(args, "xpending", a.Stream, a.Group)
2024-02-18 10:42:21 +00:00
if a.Idle != 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "idle", formatMs(ctx, a.Idle))
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
args = append(args, a.Start, a.End, a.Count)
2024-02-18 10:42:21 +00:00
if a.Consumer != "" {
2024-02-18 10:42:21 +00:00
args = append(args, a.Consumer)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewXPendingExtCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
type XAutoClaimArgs struct {
Stream string
Group string
MinIdle time.Duration
Start string
Count int64
2024-02-18 10:42:21 +00:00
Consumer string
}
func (c cmdable) XAutoClaim(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimCmd {
2024-02-18 10:42:21 +00:00
args := xAutoClaimArgs(ctx, a)
2024-02-18 10:42:21 +00:00
cmd := NewXAutoClaimCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimJustIDCmd {
2024-02-18 10:42:21 +00:00
args := xAutoClaimArgs(ctx, a)
2024-02-18 10:42:21 +00:00
args = append(args, "justid")
2024-02-18 10:42:21 +00:00
cmd := NewXAutoClaimJustIDCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func xAutoClaimArgs(ctx context.Context, a *XAutoClaimArgs) []interface{} {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 8)
2024-02-18 10:42:21 +00:00
args = append(args, "xautoclaim", a.Stream, a.Group, a.Consumer, formatMs(ctx, a.MinIdle), a.Start)
2024-02-18 10:42:21 +00:00
if a.Count > 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "count", a.Count)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return args
2024-02-18 10:42:21 +00:00
}
type XClaimArgs struct {
Stream string
Group string
2024-02-18 10:42:21 +00:00
Consumer string
MinIdle time.Duration
2024-02-18 10:42:21 +00:00
Messages []string
}
func (c cmdable) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd {
2024-02-18 10:42:21 +00:00
args := xClaimArgs(a)
2024-02-18 10:42:21 +00:00
cmd := NewXMessageSliceCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd {
2024-02-18 10:42:21 +00:00
args := xClaimArgs(a)
2024-02-18 10:42:21 +00:00
args = append(args, "justid")
2024-02-18 10:42:21 +00:00
cmd := NewStringSliceCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func xClaimArgs(a *XClaimArgs) []interface{} {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 5+len(a.Messages))
2024-02-18 10:42:21 +00:00
args = append(args,
2024-02-18 10:42:21 +00:00
"xclaim",
2024-02-18 10:42:21 +00:00
a.Stream,
2024-02-18 10:42:21 +00:00
a.Group, a.Consumer,
2024-02-18 10:42:21 +00:00
int64(a.MinIdle/time.Millisecond))
2024-02-18 10:42:21 +00:00
for _, id := range a.Messages {
2024-02-18 10:42:21 +00:00
args = append(args, id)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return args
2024-02-18 10:42:21 +00:00
}
// xTrim If approx is true, add the "~" parameter, otherwise it is the default "=" (redis default).
2024-02-18 10:42:21 +00:00
// example:
2024-02-18 10:42:21 +00:00
//
2024-02-18 10:42:21 +00:00
// XTRIM key MAXLEN/MINID threshold LIMIT limit.
2024-02-18 10:42:21 +00:00
// XTRIM key MAXLEN/MINID ~ threshold LIMIT limit.
2024-02-18 10:42:21 +00:00
//
2024-02-18 10:42:21 +00:00
// The redis-server version is lower than 6.2, please set limit to 0.
2024-02-18 10:42:21 +00:00
func (c cmdable) xTrim(
2024-02-18 10:42:21 +00:00
ctx context.Context, key, strategy string,
2024-02-18 10:42:21 +00:00
approx bool, threshold interface{}, limit int64,
2024-02-18 10:42:21 +00:00
) *IntCmd {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 7)
2024-02-18 10:42:21 +00:00
args = append(args, "xtrim", key, strategy)
2024-02-18 10:42:21 +00:00
if approx {
2024-02-18 10:42:21 +00:00
args = append(args, "~")
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
args = append(args, threshold)
2024-02-18 10:42:21 +00:00
if limit > 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "limit", limit)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
// XTrimMaxLen No `~` rules are used, `limit` cannot be used.
2024-02-18 10:42:21 +00:00
// cmd: XTRIM key MAXLEN maxLen
2024-02-18 10:42:21 +00:00
func (c cmdable) XTrimMaxLen(ctx context.Context, key string, maxLen int64) *IntCmd {
2024-02-18 10:42:21 +00:00
return c.xTrim(ctx, key, "maxlen", false, maxLen, 0)
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XTrimMaxLenApprox(ctx context.Context, key string, maxLen, limit int64) *IntCmd {
2024-02-18 10:42:21 +00:00
return c.xTrim(ctx, key, "maxlen", true, maxLen, limit)
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XTrimMinID(ctx context.Context, key string, minID string) *IntCmd {
2024-02-18 10:42:21 +00:00
return c.xTrim(ctx, key, "minid", false, minID, 0)
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd {
2024-02-18 10:42:21 +00:00
return c.xTrim(ctx, key, "minid", true, minID, limit)
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXInfoConsumersCmd(ctx, key, group)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXInfoGroupsCmd(ctx, key)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd {
2024-02-18 10:42:21 +00:00
cmd := NewXInfoStreamCmd(ctx, key)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
// XInfoStreamFull XINFO STREAM FULL [COUNT count]
2024-02-18 10:42:21 +00:00
// redis-server >= 6.0.
2024-02-18 10:42:21 +00:00
func (c cmdable) XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd {
2024-02-18 10:42:21 +00:00
args := make([]interface{}, 0, 6)
2024-02-18 10:42:21 +00:00
args = append(args, "xinfo", "stream", key, "full")
2024-02-18 10:42:21 +00:00
if count > 0 {
2024-02-18 10:42:21 +00:00
args = append(args, "count", count)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewXInfoStreamFullCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}