@@ -226,15 +226,22 @@ type Cmdable interface {
226226 XGroupCreateMkStream (ctx context.Context , stream , group , start string ) * StatusCmd
227227 XGroupSetID (ctx context.Context , stream , group , start string ) * StatusCmd
228228 XGroupDestroy (ctx context.Context , stream , group string ) * IntCmd
229+ XGroupCreateConsumer (ctx context.Context , stream , group , consumer string ) * IntCmd
229230 XGroupDelConsumer (ctx context.Context , stream , group , consumer string ) * IntCmd
230231 XReadGroup (ctx context.Context , a * XReadGroupArgs ) * XStreamSliceCmd
231232 XAck (ctx context.Context , stream , group string , ids ... string ) * IntCmd
232233 XPending (ctx context.Context , stream , group string ) * XPendingCmd
233234 XPendingExt (ctx context.Context , a * XPendingExtArgs ) * XPendingExtCmd
234235 XClaim (ctx context.Context , a * XClaimArgs ) * XMessageSliceCmd
235236 XClaimJustID (ctx context.Context , a * XClaimArgs ) * StringSliceCmd
237+
238+ // TODO: XTrim and XTrimApprox remove in v9.
236239 XTrim (ctx context.Context , key string , maxLen int64 ) * IntCmd
237240 XTrimApprox (ctx context.Context , key string , maxLen int64 ) * IntCmd
241+ XTrimMaxLen (ctx context.Context , key string , maxLen int64 ) * IntCmd
242+ XTrimMaxLenApprox (ctx context.Context , key string , maxLen , limit int64 ) * IntCmd
243+ XTrimMinID (ctx context.Context , key string , minID string ) * IntCmd
244+ XTrimMinIDApprox (ctx context.Context , key string , minID string , limit int64 ) * IntCmd
238245 XInfoGroups (ctx context.Context , key string ) * XInfoGroupsCmd
239246 XInfoStream (ctx context.Context , key string ) * XInfoStreamCmd
240247 XInfoConsumers (ctx context.Context , key string , group string ) * XInfoConsumersCmd
@@ -1621,22 +1628,50 @@ func (c cmdable) SUnionStore(ctx context.Context, destination string, keys ...st
16211628// - XAddArgs.Values = map[string]interface{}{"key1": "value1", "key2": "value2"}
16221629//
16231630// Note that map will not preserve the order of key-value pairs.
1631+ // MaxLen/MaxLenApprox and MinID are in conflict, only one of them can be used.
16241632type XAddArgs struct {
1625- Stream string
1626- MaxLen int64 // MAXLEN N
1633+ Stream string
1634+ NoMkStream bool
1635+ MaxLen int64 // MAXLEN N
1636+
1637+ // Deprecated: use MaxLen+Approx, remove in v9.
16271638 MaxLenApprox int64 // MAXLEN ~ N
1628- ID string
1629- Values interface {}
1639+
1640+ MinID string
1641+ // Approx causes MaxLen and MinID to use "~" matcher (instead of "=").
1642+ Approx bool
1643+ Limit int64
1644+ ID string
1645+ Values interface {}
16301646}
16311647
1648+ // XAdd a.Limit has a bug, please confirm it and use it.
1649+ // issue: https://github.com/redis/redis/issues/9046
16321650func (c cmdable ) XAdd (ctx context.Context , a * XAddArgs ) * StringCmd {
1633- args := make ([]interface {}, 0 , 8 )
1634- args = append (args , "xadd" )
1635- args = append (args , a .Stream )
1636- if a .MaxLen > 0 {
1637- args = append (args , "maxlen" , a .MaxLen )
1638- } else if a .MaxLenApprox > 0 {
1651+ args := make ([]interface {}, 0 , 11 )
1652+ args = append (args , "xadd" , a .Stream )
1653+ if a .NoMkStream {
1654+ args = append (args , "nomkstream" )
1655+ }
1656+ switch {
1657+ case a .MaxLen > 0 :
1658+ if a .Approx {
1659+ args = append (args , "maxlen" , "~" , a .MaxLen )
1660+ } else {
1661+ args = append (args , "maxlen" , a .MaxLen )
1662+ }
1663+ case a .MaxLenApprox > 0 :
1664+ // TODO remove in v9.
16391665 args = append (args , "maxlen" , "~" , a .MaxLenApprox )
1666+ case a .MinID != "" :
1667+ if a .Approx {
1668+ args = append (args , "minid" , "~" , a .MinID )
1669+ } else {
1670+ args = append (args , "minid" , a .MinID )
1671+ }
1672+ }
1673+ if a .Limit > 0 {
1674+ args = append (args , "limit" , a .Limit )
16401675 }
16411676 if a .ID != "" {
16421677 args = append (args , a .ID )
@@ -1757,6 +1792,12 @@ func (c cmdable) XGroupDestroy(ctx context.Context, stream, group string) *IntCm
17571792 return cmd
17581793}
17591794
1795+ func (c cmdable ) XGroupCreateConsumer (ctx context.Context , stream , group , consumer string ) * IntCmd {
1796+ cmd := NewIntCmd (ctx , "xgroup" , "createconsumer" , stream , group , consumer )
1797+ _ = c (ctx , cmd )
1798+ return cmd
1799+ }
1800+
17601801func (c cmdable ) XGroupDelConsumer (ctx context.Context , stream , group , consumer string ) * IntCmd {
17611802 cmd := NewIntCmd (ctx , "xgroup" , "delconsumer" , stream , group , consumer )
17621803 _ = c (ctx , cmd )
@@ -1914,16 +1955,63 @@ func xClaimArgs(a *XClaimArgs) []interface{} {
19141955 return args
19151956}
19161957
1917- func (c cmdable ) XTrim (ctx context.Context , key string , maxLen int64 ) * IntCmd {
1918- cmd := NewIntCmd (ctx , "xtrim" , key , "maxlen" , maxLen )
1958+ // xTrim If approx is true, add the "~" parameter, otherwise it is the default "=" (redis default).
1959+ // example:
1960+ // XTRIM key MAXLEN/MINID threshold LIMIT limit.
1961+ // XTRIM key MAXLEN/MINID ~ threshold LIMIT limit.
1962+ // The redis-server version is lower than 6.2, please set limit to 0.
1963+ func (c cmdable ) xTrim (
1964+ ctx context.Context , key , strategy string ,
1965+ approx bool , threshold interface {}, limit int64 ,
1966+ ) * IntCmd {
1967+ args := make ([]interface {}, 0 , 7 )
1968+ args = append (args , "xtrim" , key , strategy )
1969+ if approx {
1970+ args = append (args , "~" )
1971+ }
1972+ args = append (args , threshold )
1973+ if limit > 0 {
1974+ args = append (args , "limit" , limit )
1975+ }
1976+ cmd := NewIntCmd (ctx , args ... )
19191977 _ = c (ctx , cmd )
19201978 return cmd
19211979}
19221980
1981+ // Deprecated: use XTrimMaxLen, remove in v9.
1982+ func (c cmdable ) XTrim (ctx context.Context , key string , maxLen int64 ) * IntCmd {
1983+ return c .xTrim (ctx , key , "maxlen" , false , maxLen , 0 )
1984+ }
1985+
1986+ // Deprecated: use XTrimMaxLenApprox, remove in v9.
19231987func (c cmdable ) XTrimApprox (ctx context.Context , key string , maxLen int64 ) * IntCmd {
1924- cmd := NewIntCmd (ctx , "xtrim" , key , "maxlen" , "~" , maxLen )
1925- _ = c (ctx , cmd )
1926- return cmd
1988+ return c .xTrim (ctx , key , "maxlen" , true , maxLen , 0 )
1989+ }
1990+
1991+ // XTrimMaxLen No `~` rules are used, `limit` cannot be used.
1992+ // cmd: XTRIM key MAXLEN maxLen
1993+ func (c cmdable ) XTrimMaxLen (ctx context.Context , key string , maxLen int64 ) * IntCmd {
1994+ return c .xTrim (ctx , key , "maxlen" , false , maxLen , 0 )
1995+ }
1996+
1997+ // XTrimMaxLenApprox LIMIT has a bug, please confirm it and use it.
1998+ // issue: https://github.com/redis/redis/issues/9046
1999+ // cmd: XTRIM key MAXLEN ~ maxLen LIMIT limit
2000+ func (c cmdable ) XTrimMaxLenApprox (ctx context.Context , key string , maxLen , limit int64 ) * IntCmd {
2001+ return c .xTrim (ctx , key , "maxlen" , true , maxLen , limit )
2002+ }
2003+
2004+ // XTrimMinID No `~` rules are used, `limit` cannot be used.
2005+ // cmd: XTRIM key MINID minID
2006+ func (c cmdable ) XTrimMinID (ctx context.Context , key string , minID string ) * IntCmd {
2007+ return c .xTrim (ctx , key , "minid" , false , minID , 0 )
2008+ }
2009+
2010+ // XTrimMinIDApprox LIMIT has a bug, please confirm it and use it.
2011+ // issue: https://github.com/redis/redis/issues/9046
2012+ // cmd: XTRIM key MINID ~ minID LIMIT limit
2013+ func (c cmdable ) XTrimMinIDApprox (ctx context.Context , key string , minID string , limit int64 ) * IntCmd {
2014+ return c .xTrim (ctx , key , "minid" , true , minID , limit )
19272015}
19282016
19292017func (c cmdable ) XInfoConsumers (ctx context.Context , key string , group string ) * XInfoConsumersCmd {
0 commit comments