2024-02-18 10:42:21 +00:00
package redis
import (
"context"
"fmt"
"github.com/redis/go-redis/v9/internal/proto"
)
type ProbabilisticCmdable interface {
BFAdd ( ctx context . Context , key string , element interface { } ) * BoolCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFCard ( ctx context . Context , key string ) * IntCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFExists ( ctx context . Context , key string , element interface { } ) * BoolCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfo ( ctx context . Context , key string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfoArg ( ctx context . Context , key , option string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfoCapacity ( ctx context . Context , key string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfoSize ( ctx context . Context , key string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfoFilters ( ctx context . Context , key string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfoItems ( ctx context . Context , key string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInfoExpansion ( ctx context . Context , key string ) * BFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFInsert ( ctx context . Context , key string , options * BFInsertOptions , elements ... interface { } ) * BoolSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFMAdd ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFMExists ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFReserve ( ctx context . Context , key string , errorRate float64 , capacity int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFReserveExpansion ( ctx context . Context , key string , errorRate float64 , capacity , expansion int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFReserveNonScaling ( ctx context . Context , key string , errorRate float64 , capacity int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFReserveWithArgs ( ctx context . Context , key string , options * BFReserveOptions ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFScanDump ( ctx context . Context , key string , iterator int64 ) * ScanDumpCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
BFLoadChunk ( ctx context . Context , key string , iterator int64 , data interface { } ) * StatusCmd
CFAdd ( ctx context . Context , key string , element interface { } ) * BoolCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFAddNX ( ctx context . Context , key string , element interface { } ) * BoolCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFCount ( ctx context . Context , key string , element interface { } ) * IntCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFDel ( ctx context . Context , key string , element interface { } ) * BoolCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFExists ( ctx context . Context , key string , element interface { } ) * BoolCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFInfo ( ctx context . Context , key string ) * CFInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFInsert ( ctx context . Context , key string , options * CFInsertOptions , elements ... interface { } ) * BoolSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFInsertNX ( ctx context . Context , key string , options * CFInsertOptions , elements ... interface { } ) * IntSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFMExists ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFReserve ( ctx context . Context , key string , capacity int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFReserveWithArgs ( ctx context . Context , key string , options * CFReserveOptions ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFReserveExpansion ( ctx context . Context , key string , capacity int64 , expansion int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFReserveBucketSize ( ctx context . Context , key string , capacity int64 , bucketsize int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFReserveMaxIterations ( ctx context . Context , key string , capacity int64 , maxiterations int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFScanDump ( ctx context . Context , key string , iterator int64 ) * ScanDumpCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CFLoadChunk ( ctx context . Context , key string , iterator int64 , data interface { } ) * StatusCmd
CMSIncrBy ( ctx context . Context , key string , elements ... interface { } ) * IntSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CMSInfo ( ctx context . Context , key string ) * CMSInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CMSInitByDim ( ctx context . Context , key string , width , height int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CMSInitByProb ( ctx context . Context , key string , errorRate , probability float64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CMSMerge ( ctx context . Context , destKey string , sourceKeys ... string ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CMSMergeWithWeight ( ctx context . Context , destKey string , sourceKeys map [ string ] int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
CMSQuery ( ctx context . Context , key string , elements ... interface { } ) * IntSliceCmd
TopKAdd ( ctx context . Context , key string , elements ... interface { } ) * StringSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKCount ( ctx context . Context , key string , elements ... interface { } ) * IntSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKIncrBy ( ctx context . Context , key string , elements ... interface { } ) * StringSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKInfo ( ctx context . Context , key string ) * TopKInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKList ( ctx context . Context , key string ) * StringSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKListWithCount ( ctx context . Context , key string ) * MapStringIntCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKQuery ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKReserve ( ctx context . Context , key string , k int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TopKReserveWithOptions ( ctx context . Context , key string , k int64 , width , depth int64 , decay float64 ) * StatusCmd
TDigestAdd ( ctx context . Context , key string , elements ... float64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestByRank ( ctx context . Context , key string , rank ... uint64 ) * FloatSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestByRevRank ( ctx context . Context , key string , rank ... uint64 ) * FloatSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestCDF ( ctx context . Context , key string , elements ... float64 ) * FloatSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestCreate ( ctx context . Context , key string ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestCreateWithCompression ( ctx context . Context , key string , compression int64 ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestInfo ( ctx context . Context , key string ) * TDigestInfoCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestMax ( ctx context . Context , key string ) * FloatCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestMin ( ctx context . Context , key string ) * FloatCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestMerge ( ctx context . Context , destKey string , options * TDigestMergeOptions , sourceKeys ... string ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestQuantile ( ctx context . Context , key string , elements ... float64 ) * FloatSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestRank ( ctx context . Context , key string , values ... float64 ) * IntSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestReset ( ctx context . Context , key string ) * StatusCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestRevRank ( ctx context . Context , key string , values ... float64 ) * IntSliceCmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
TDigestTrimmedMean ( ctx context . Context , key string , lowCutQuantile , highCutQuantile float64 ) * FloatCmd
}
type BFInsertOptions struct {
2024-07-24 23:45:04 +00:00
Capacity int64
Error float64
Expansion int64
2024-02-18 10:42:21 +00:00
NonScaling bool
2024-07-24 23:45:04 +00:00
NoCreate bool
2024-02-18 10:42:21 +00:00
}
type BFReserveOptions struct {
2024-07-24 23:45:04 +00:00
Capacity int64
Error float64
Expansion int64
2024-02-18 10:42:21 +00:00
NonScaling bool
}
type CFReserveOptions struct {
2024-07-24 23:45:04 +00:00
Capacity int64
BucketSize int64
2024-02-18 10:42:21 +00:00
MaxIterations int64
2024-07-24 23:45:04 +00:00
Expansion int64
2024-02-18 10:42:21 +00:00
}
type CFInsertOptions struct {
Capacity int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
NoCreate bool
}
// -------------------------------------------
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Bloom filter commands
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
//-------------------------------------------
// BFReserve creates an empty Bloom filter with a single sub-filter
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// for the initial specified capacity and with an upper bound error_rate.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFReserve ( ctx context . Context , key string , errorRate float64 , capacity int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.RESERVE" , key , errorRate , capacity }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFReserveExpansion creates an empty Bloom filter with a single sub-filter
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// for the initial specified capacity and with an upper bound error_rate.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying an expansion rate for the filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFReserveExpansion ( ctx context . Context , key string , errorRate float64 , capacity , expansion int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.RESERVE" , key , errorRate , capacity , "EXPANSION" , expansion }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFReserveNonScaling creates an empty Bloom filter with a single sub-filter
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// for the initial specified capacity and with an upper bound error_rate.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying that the filter should not scale.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFReserveNonScaling ( ctx context . Context , key string , errorRate float64 , capacity int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.RESERVE" , key , errorRate , capacity , "NONSCALING" }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFReserveWithArgs creates an empty Bloom filter with a single sub-filter
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// for the initial specified capacity and with an upper bound error_rate.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying additional options such as expansion rate and non-scaling behavior.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFReserveWithArgs ( ctx context . Context , key string , options * BFReserveOptions ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.RESERVE" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , options . Error , options . Capacity )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Expansion != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "EXPANSION" , options . Expansion )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . NonScaling {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "NONSCALING" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFAdd adds an item to a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.add/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFAdd ( ctx context . Context , key string , element interface { } ) * BoolCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.ADD" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFCard returns the cardinality of a Bloom filter -
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// number of items that were added to a Bloom filter and detected as unique
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// (items that caused at least one bit to be set in at least one sub-filter).
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.card/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFCard ( ctx context . Context , key string ) * IntCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.CARD" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFExists determines whether a given item was added to a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.exists/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFExists ( ctx context . Context , key string , element interface { } ) * BoolCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.EXISTS" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFLoadChunk restores a Bloom filter previously saved using BF.SCANDUMP.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.loadchunk/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFLoadChunk ( ctx context . Context , key string , iterator int64 , data interface { } ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.LOADCHUNK" , key , iterator , data }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// Begins an incremental save of the Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This command is useful for large Bloom filters that cannot fit into the DUMP and RESTORE model.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.scandump/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFScanDump ( ctx context . Context , key string , iterator int64 ) * ScanDumpCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.SCANDUMP" , key , iterator }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := newScanDumpCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type ScanDump struct {
Iter int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
Data string
}
type ScanDumpCmd struct {
baseCmd
val ScanDump
}
func newScanDumpCmd ( ctx context . Context , args ... interface { } ) * ScanDumpCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return & ScanDumpCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
baseCmd : baseCmd {
2024-07-24 23:45:04 +00:00
ctx : ctx ,
2024-02-18 10:42:21 +00:00
args : args ,
} ,
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * ScanDumpCmd ) String ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmdString ( cmd , cmd . val )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * ScanDumpCmd ) SetVal ( val ScanDump ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * ScanDumpCmd ) Result ( ) ( ScanDump , error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val , cmd . err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * ScanDumpCmd ) Val ( ) ScanDump {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * ScanDumpCmd ) readReply ( rd * proto . Reader ) ( err error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
n , err := rd . ReadMapLen ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = ScanDump { }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i := 0 ; i < n ; i ++ {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
iter , err := rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
data , err := rd . ReadString ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val . Data = data
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val . Iter = iter
}
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// Returns information about a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfo ( ctx context . Context , key string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.INFO" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBFInfoCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type BFInfo struct {
2024-07-24 23:45:04 +00:00
Capacity int64
Size int64
Filters int64
2024-02-18 10:42:21 +00:00
ItemsInserted int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
ExpansionRate int64
}
type BFInfoCmd struct {
baseCmd
val BFInfo
}
func NewBFInfoCmd ( ctx context . Context , args ... interface { } ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return & BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
baseCmd : baseCmd {
2024-07-24 23:45:04 +00:00
ctx : ctx ,
2024-02-18 10:42:21 +00:00
args : args ,
} ,
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * BFInfoCmd ) SetVal ( val BFInfo ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * BFInfoCmd ) String ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmdString ( cmd , cmd . val )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * BFInfoCmd ) Val ( ) BFInfo {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * BFInfoCmd ) Result ( ) ( BFInfo , error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val , cmd . err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * BFInfoCmd ) readReply ( rd * proto . Reader ) ( err error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
n , err := rd . ReadMapLen ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
var key string
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
var result BFInfo
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for f := 0 ; f < n ; f ++ {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
key , err = rd . ReadString ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
switch key {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Capacity" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Capacity , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Size" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Size , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Number of filters" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Filters , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Number of items inserted" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . ItemsInserted , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Expansion rate" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . ExpansionRate , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
default :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return fmt . Errorf ( "redis: BLOOM.INFO unexpected key %s" , key )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd . val = result
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInfoCapacity returns information about the capacity of a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfoCapacity ( ctx context . Context , key string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return c . BFInfoArg ( ctx , key , "CAPACITY" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInfoSize returns information about the size of a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfoSize ( ctx context . Context , key string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return c . BFInfoArg ( ctx , key , "SIZE" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInfoFilters returns information about the filters of a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfoFilters ( ctx context . Context , key string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return c . BFInfoArg ( ctx , key , "FILTERS" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInfoItems returns information about the items of a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfoItems ( ctx context . Context , key string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return c . BFInfoArg ( ctx , key , "ITEMS" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInfoExpansion returns information about the expansion rate of a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfoExpansion ( ctx context . Context , key string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return c . BFInfoArg ( ctx , key , "EXPANSION" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInfoArg returns information about a specific option of a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInfoArg ( ctx context . Context , key , option string ) * BFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.INFO" , key , option }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBFInfoCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFInsert inserts elements into a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying additional options such as:
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// capacity, error rate, expansion rate, and non-scaling behavior.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.insert/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFInsert ( ctx context . Context , key string , options * BFInsertOptions , elements ... interface { } ) * BoolSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.INSERT" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Capacity != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "CAPACITY" , options . Capacity )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Error != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "ERROR" , options . Error )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Expansion != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "EXPANSION" , options . Expansion )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . NoCreate {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "NOCREATE" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . NonScaling {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "NONSCALING" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "ITEMS" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , elements ... )
cmd := NewBoolSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFMAdd adds multiple elements to a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of booleans indicating whether each element was added to the filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.madd/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFMAdd ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.MADD" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , elements ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// BFMExists check if multiple elements exist in a Bloom filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of booleans indicating whether each element exists in the filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/bf.mexists/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) BFMExists ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "BF.MEXISTS" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , elements ... )
cmd := NewBoolSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// -------------------------------------------
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Cuckoo filter commands
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
//-------------------------------------------
// CFReserve creates an empty Cuckoo filter with the specified capacity.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFReserve ( ctx context . Context , key string , capacity int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.RESERVE" , key , capacity }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFReserveExpansion creates an empty Cuckoo filter with the specified capacity and expansion rate.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFReserveExpansion ( ctx context . Context , key string , capacity int64 , expansion int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.RESERVE" , key , capacity , "EXPANSION" , expansion }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFReserveBucketSize creates an empty Cuckoo filter with the specified capacity and bucket size.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFReserveBucketSize ( ctx context . Context , key string , capacity int64 , bucketsize int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.RESERVE" , key , capacity , "BUCKETSIZE" , bucketsize }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFReserveMaxIterations creates an empty Cuckoo filter with the specified capacity and maximum number of iterations.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFReserveMaxIterations ( ctx context . Context , key string , capacity int64 , maxiterations int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.RESERVE" , key , capacity , "MAXITERATIONS" , maxiterations }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFReserveWithArgs creates an empty Cuckoo filter with the specified options.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function allows for specifying additional options such as bucket size and maximum number of iterations.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFReserveWithArgs ( ctx context . Context , key string , options * CFReserveOptions ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.RESERVE" , key , options . Capacity }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . BucketSize != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "BUCKETSIZE" , options . BucketSize )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . MaxIterations != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "MAXITERATIONS" , options . MaxIterations )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Expansion != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "EXPANSION" , options . Expansion )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFAdd adds an element to a Cuckoo filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns true if the element was added to the filter or false if it already exists in the filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.add/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFAdd ( ctx context . Context , key string , element interface { } ) * BoolCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.ADD" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFAddNX adds an element to a Cuckoo filter only if it does not already exist in the filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns true if the element was added to the filter or false if it already exists in the filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.addnx/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFAddNX ( ctx context . Context , key string , element interface { } ) * BoolCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.ADDNX" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFCount returns an estimate of the number of times an element may be in a Cuckoo Filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.count/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFCount ( ctx context . Context , key string , element interface { } ) * IntCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.COUNT" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewIntCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFDel deletes an item once from the cuckoo filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.del/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFDel ( ctx context . Context , key string , element interface { } ) * BoolCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.DEL" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFExists determines whether an item may exist in the Cuckoo Filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.exists/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFExists ( ctx context . Context , key string , element interface { } ) * BoolCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.EXISTS" , key , element }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFLoadChunk restores a filter previously saved using SCANDUMP.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.loadchunk/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFLoadChunk ( ctx context . Context , key string , iterator int64 , data interface { } ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.LOADCHUNK" , key , iterator , data }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFScanDump begins an incremental save of the cuckoo filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.scandump/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFScanDump ( ctx context . Context , key string , iterator int64 ) * ScanDumpCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.SCANDUMP" , key , iterator }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := newScanDumpCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type CFInfo struct {
2024-07-24 23:45:04 +00:00
Size int64
NumBuckets int64
NumFilters int64
2024-02-18 10:42:21 +00:00
NumItemsInserted int64
2024-07-24 23:45:04 +00:00
NumItemsDeleted int64
BucketSize int64
ExpansionRate int64
MaxIteration int64
2024-02-18 10:42:21 +00:00
}
type CFInfoCmd struct {
baseCmd
val CFInfo
}
func NewCFInfoCmd ( ctx context . Context , args ... interface { } ) * CFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return & CFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
baseCmd : baseCmd {
2024-07-24 23:45:04 +00:00
ctx : ctx ,
2024-02-18 10:42:21 +00:00
args : args ,
} ,
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CFInfoCmd ) SetVal ( val CFInfo ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CFInfoCmd ) String ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmdString ( cmd , cmd . val )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CFInfoCmd ) Val ( ) CFInfo {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CFInfoCmd ) Result ( ) ( CFInfo , error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val , cmd . err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CFInfoCmd ) readReply ( rd * proto . Reader ) ( err error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
n , err := rd . ReadMapLen ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
var key string
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
var result CFInfo
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for f := 0 ; f < n ; f ++ {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
key , err = rd . ReadString ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
switch key {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Size" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Size , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Number of buckets" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . NumBuckets , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Number of filters" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . NumFilters , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Number of items inserted" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . NumItemsInserted , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Number of items deleted" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . NumItemsDeleted , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Bucket size" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . BucketSize , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Expansion rate" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . ExpansionRate , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Max iterations" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . MaxIteration , err = rd . ReadInt ( )
default :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return fmt . Errorf ( "redis: CF.INFO unexpected key %s" , key )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd . val = result
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFInfo returns information about a Cuckoo filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFInfo ( ctx context . Context , key string ) * CFInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.INFO" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewCFInfoCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFInsert inserts elements into a Cuckoo filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying additional options such as capacity, error rate, expansion rate, and non-scaling behavior.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of booleans indicating whether each element was added to the filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.insert/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFInsert ( ctx context . Context , key string , options * CFInsertOptions , elements ... interface { } ) * BoolSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.INSERT" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = c . getCfInsertWithArgs ( args , options , elements ... )
cmd := NewBoolSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFInsertNX inserts elements into a Cuckoo filter only if they do not already exist in the filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying additional options such as:
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// capacity, error rate, expansion rate, and non-scaling behavior.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of integers indicating whether each element was added to the filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.insertnx/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFInsertNX ( ctx context . Context , key string , options * CFInsertOptions , elements ... interface { } ) * IntSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.INSERTNX" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = c . getCfInsertWithArgs ( args , options , elements ... )
cmd := NewIntSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( c cmdable ) getCfInsertWithArgs ( args [ ] interface { } , options * CFInsertOptions , elements ... interface { } ) [ ] interface { } {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Capacity != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "CAPACITY" , options . Capacity )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . NoCreate {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "NOCREATE" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "ITEMS" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , elements ... )
return args
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CFMExists check if multiple elements exist in a Cuckoo filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of booleans indicating whether each element exists in the filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cf.mexists/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CFMExists ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CF.MEXISTS" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , elements ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewBoolSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// -------------------------------------------
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// CMS commands
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
//-------------------------------------------
// CMSIncrBy increments the count of one or more items in a Count-Min Sketch filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of integers representing the updated count of each item.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.incrby/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSIncrBy ( ctx context . Context , key string , elements ... interface { } ) * IntSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "CMS.INCRBY"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = appendArgs ( args , elements )
cmd := NewIntSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type CMSInfo struct {
Width int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
Depth int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
Count int64
}
type CMSInfoCmd struct {
baseCmd
val CMSInfo
}
func NewCMSInfoCmd ( ctx context . Context , args ... interface { } ) * CMSInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return & CMSInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
baseCmd : baseCmd {
2024-07-24 23:45:04 +00:00
ctx : ctx ,
2024-02-18 10:42:21 +00:00
args : args ,
} ,
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CMSInfoCmd ) SetVal ( val CMSInfo ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CMSInfoCmd ) String ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmdString ( cmd , cmd . val )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CMSInfoCmd ) Val ( ) CMSInfo {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CMSInfoCmd ) Result ( ) ( CMSInfo , error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val , cmd . err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * CMSInfoCmd ) readReply ( rd * proto . Reader ) ( err error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
n , err := rd . ReadMapLen ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
var key string
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
var result CMSInfo
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for f := 0 ; f < n ; f ++ {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
key , err = rd . ReadString ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
switch key {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "width" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Width , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "depth" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Depth , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "count" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Count , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
default :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return fmt . Errorf ( "redis: CMS.INFO unexpected key %s" , key )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd . val = result
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CMSInfo returns information about a Count-Min Sketch filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSInfo ( ctx context . Context , key string ) * CMSInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CMS.INFO" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewCMSInfoCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CMSInitByDim creates an empty Count-Min Sketch filter with the specified dimensions.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.initbydim/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSInitByDim ( ctx context . Context , key string , width , depth int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CMS.INITBYDIM" , key , width , depth }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CMSInitByProb creates an empty Count-Min Sketch filter with the specified error rate and probability.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.initbyprob/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSInitByProb ( ctx context . Context , key string , errorRate , probability float64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CMS.INITBYPROB" , key , errorRate , probability }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CMSMerge merges multiple Count-Min Sketch filters into a single filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The destination filter must not exist and will be created with the dimensions of the first source filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The number of items in each source filter must be equal.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the filters could not be merged.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.merge/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSMerge ( ctx context . Context , destKey string , sourceKeys ... string ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CMS.MERGE" , destKey , len ( sourceKeys ) }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for _ , s := range sourceKeys {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , s )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CMSMergeWithWeight merges multiple Count-Min Sketch filters into a single filter with weights for each source filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The destination filter must not exist and will be created with the dimensions of the first source filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The number of items in each source filter must be equal.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the filters could not be merged.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.merge/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSMergeWithWeight ( ctx context . Context , destKey string , sourceKeys map [ string ] int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 0 , 4 + ( len ( sourceKeys ) * 2 + 1 ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "CMS.MERGE" , destKey , len ( sourceKeys ) )
if len ( sourceKeys ) > 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
sk := make ( [ ] interface { } , len ( sourceKeys ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
sw := make ( [ ] interface { } , len ( sourceKeys ) )
i := 0
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for k , w := range sourceKeys {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
sk [ i ] = k
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
sw [ i ] = w
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
i ++
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , sk ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "WEIGHTS" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , sw ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// CMSQuery returns count for item(s).
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/cms.query/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) CMSQuery ( ctx context . Context , key string , elements ... interface { } ) * IntSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "CMS.QUERY" , key }
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , elements ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd := NewIntSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// -------------------------------------------
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// TopK commands
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
//--------------------------------------------
// TopKAdd adds one or more elements to a Top-K filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of strings representing the items that were removed from the filter, if any.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.add/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKAdd ( ctx context . Context , key string , elements ... interface { } ) * StringSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TOPK.ADD"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = appendArgs ( args , elements )
cmd := NewStringSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKReserve creates an empty Top-K filter with the specified number of top items to keep.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKReserve ( ctx context . Context , key string , k int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TOPK.RESERVE" , key , k }
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKReserveWithOptions creates an empty Top-K filter with the specified number of top items to keep and additional options.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function allows for specifying additional options such as width, depth and decay.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.reserve/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKReserveWithOptions ( ctx context . Context , key string , k int64 , width , depth int64 , decay float64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TOPK.RESERVE" , key , k , width , depth , decay }
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type TopKInfo struct {
2024-07-24 23:45:04 +00:00
K int64
2024-02-18 10:42:21 +00:00
Width int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
Depth int64
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
Decay float64
}
type TopKInfoCmd struct {
baseCmd
val TopKInfo
}
func NewTopKInfoCmd ( ctx context . Context , args ... interface { } ) * TopKInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return & TopKInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
baseCmd : baseCmd {
2024-07-24 23:45:04 +00:00
ctx : ctx ,
2024-02-18 10:42:21 +00:00
args : args ,
} ,
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TopKInfoCmd ) SetVal ( val TopKInfo ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TopKInfoCmd ) String ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmdString ( cmd , cmd . val )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TopKInfoCmd ) Val ( ) TopKInfo {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TopKInfoCmd ) Result ( ) ( TopKInfo , error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val , cmd . err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TopKInfoCmd ) readReply ( rd * proto . Reader ) ( err error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
n , err := rd . ReadMapLen ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
var key string
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
var result TopKInfo
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for f := 0 ; f < n ; f ++ {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
key , err = rd . ReadString ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
switch key {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "k" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . K , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "width" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Width , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "depth" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Depth , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "decay" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Decay , err = rd . ReadFloat ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
default :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return fmt . Errorf ( "redis: topk.info unexpected key %s" , key )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd . val = result
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKInfo returns information about a Top-K filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKInfo ( ctx context . Context , key string ) * TopKInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TOPK.INFO" , key }
cmd := NewTopKInfoCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKQuery check if multiple elements exist in a Top-K filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of booleans indicating whether each element exists in the filter or not.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.query/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKQuery ( ctx context . Context , key string , elements ... interface { } ) * BoolSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TOPK.QUERY"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = appendArgs ( args , elements )
cmd := NewBoolSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKCount returns an estimate of the number of times an item may be in a Top-K filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.count/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKCount ( ctx context . Context , key string , elements ... interface { } ) * IntSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TOPK.COUNT"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = appendArgs ( args , elements )
cmd := NewIntSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKIncrBy increases the count of one or more items in a Top-K filter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.incrby/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKIncrBy ( ctx context . Context , key string , elements ... interface { } ) * StringSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TOPK.INCRBY"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = appendArgs ( args , elements )
cmd := NewStringSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKList returns all items in Top-K list.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.list/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKList ( ctx context . Context , key string ) * StringSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TOPK.LIST" , key }
cmd := NewStringSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TopKListWithCount returns all items in Top-K list with their respective count.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/topk.list/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TopKListWithCount ( ctx context . Context , key string ) * MapStringIntCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TOPK.LIST" , key , "WITHCOUNT" }
cmd := NewMapStringIntCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// -------------------------------------------
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// t-digest commands
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// --------------------------------------------
// TDigestAdd adds one or more elements to a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.add/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestAdd ( ctx context . Context , key string , elements ... float64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.ADD"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert floatSlice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range elements {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestByRank returns an array of values from a t-Digest data structure based on their rank.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The rank of an element is its position in the sorted list of all elements in the t-Digest.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of floats representing the values at the specified ranks or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.byrank/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestByRank ( ctx context . Context , key string , rank ... uint64 ) * FloatSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( rank ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.BYRANK"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert uint slice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( rank ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range rank {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewFloatSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestByRevRank returns an array of values from a t-Digest data structure based on their reverse rank.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The reverse rank of an element is its position in the sorted list of all elements in the t-Digest when sorted in descending order.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of floats representing the values at the specified ranks or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.byrevrank/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestByRevRank ( ctx context . Context , key string , rank ... uint64 ) * FloatSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( rank ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.BYREVRANK"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert uint slice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( rank ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range rank {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewFloatSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestCDF returns an array of cumulative distribution function (CDF) values for one or more elements in a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The CDF value for an element is the fraction of all elements in the t-Digest that are less than or equal to it.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of floats representing the CDF values for each element or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.cdf/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestCDF ( ctx context . Context , key string , elements ... float64 ) * FloatSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.CDF"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert floatSlice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range elements {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewFloatSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestCreate creates an empty t-Digest data structure with default parameters.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.create/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestCreate ( ctx context . Context , key string ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.CREATE" , key }
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestCreateWithCompression creates an empty t-Digest data structure with a specified compression parameter.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The compression parameter controls the accuracy and memory usage of the t-Digest.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.create/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestCreateWithCompression ( ctx context . Context , key string , compression int64 ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.CREATE" , key , "COMPRESSION" , compression }
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type TDigestInfo struct {
2024-07-24 23:45:04 +00:00
Compression int64
Capacity int64
MergedNodes int64
UnmergedNodes int64
MergedWeight int64
UnmergedWeight int64
Observations int64
2024-02-18 10:42:21 +00:00
TotalCompressions int64
2024-07-24 23:45:04 +00:00
MemoryUsage int64
2024-02-18 10:42:21 +00:00
}
type TDigestInfoCmd struct {
baseCmd
val TDigestInfo
}
func NewTDigestInfoCmd ( ctx context . Context , args ... interface { } ) * TDigestInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return & TDigestInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
baseCmd : baseCmd {
2024-07-24 23:45:04 +00:00
ctx : ctx ,
2024-02-18 10:42:21 +00:00
args : args ,
} ,
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TDigestInfoCmd ) SetVal ( val TDigestInfo ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
cmd . val = val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TDigestInfoCmd ) String ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmdString ( cmd , cmd . val )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TDigestInfoCmd ) Val ( ) TDigestInfo {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TDigestInfoCmd ) Result ( ) ( TDigestInfo , error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd . val , cmd . err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
func ( cmd * TDigestInfoCmd ) readReply ( rd * proto . Reader ) ( err error ) {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
n , err := rd . ReadMapLen ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
var key string
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
var result TDigestInfo
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for f := 0 ; f < n ; f ++ {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
key , err = rd . ReadString ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
switch key {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Compression" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Compression , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Capacity" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Capacity , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Merged nodes" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . MergedNodes , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Unmerged nodes" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . UnmergedNodes , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Merged weight" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . MergedWeight , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Unmerged weight" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . UnmergedWeight , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Observations" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . Observations , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Total compressions" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . TotalCompressions , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
case "Memory usage" :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
result . MemoryUsage , err = rd . ReadInt ( )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
default :
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return fmt . Errorf ( "redis: tdigest.info unexpected key %s" , key )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
if err != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return err
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd . val = result
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestInfo returns information about a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.info/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestInfo ( ctx context . Context , key string ) * TDigestInfoCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.INFO" , key }
cmd := NewTDigestInfoCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestMax returns the maximum value from a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.max/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestMax ( ctx context . Context , key string ) * FloatCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.MAX" , key }
cmd := NewFloatCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
type TDigestMergeOptions struct {
Compression int64
2024-07-24 23:45:04 +00:00
Override bool
2024-02-18 10:42:21 +00:00
}
// TDigestMerge merges multiple t-Digest data structures into a single t-Digest.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This function also allows for specifying additional options such as compression and override behavior.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.merge/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestMerge ( ctx context . Context , destKey string , options * TDigestMergeOptions , sourceKeys ... string ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.MERGE" , destKey , len ( sourceKeys ) }
for _ , sourceKey := range sourceKeys {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , sourceKey )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
if options != nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Compression != 0 {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "COMPRESSION" , options . Compression )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if options . Override {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args = append ( args , "OVERRIDE" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestMin returns the minimum value from a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.min/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestMin ( ctx context . Context , key string ) * FloatCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.MIN" , key }
cmd := NewFloatCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestQuantile returns an array of quantile values for one or more elements in a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The quantile value for an element is the fraction of all elements in the t-Digest that are less than or equal to it.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of floats representing the quantile values for each element or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.quantile/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestQuantile ( ctx context . Context , key string , elements ... float64 ) * FloatSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.QUANTILE"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert floatSlice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( elements ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range elements {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewFloatSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestRank returns an array of rank values for one or more elements in a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The rank of an element is its position in the sorted list of all elements in the t-Digest.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of integers representing the rank values for each element or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.rank/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestRank ( ctx context . Context , key string , values ... float64 ) * IntSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( values ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.RANK"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert floatSlice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( values ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range values {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewIntSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestReset resets a t-Digest data structure to its initial state.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns OK on success or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.reset/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestReset ( ctx context . Context , key string ) * StatusCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.RESET" , key }
cmd := NewStatusCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestRevRank returns an array of reverse rank values for one or more elements in a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The reverse rank of an element is its position in the sorted list of all elements in the t-Digest when sorted in descending order.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns an array of integers representing the reverse rank values for each element or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.revrank/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestRevRank ( ctx context . Context , key string , values ... float64 ) * IntSliceCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := make ( [ ] interface { } , 2 , 2 + len ( values ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 0 ] = "TDIGEST.REVRANK"
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args [ 1 ] = key
// Convert floatSlice to []interface{}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice := make ( [ ] interface { } , len ( values ) )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
for i , v := range values {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
interfaceSlice [ i ] = v
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
args = append ( args , interfaceSlice ... )
cmd := NewIntSliceCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// TDigestTrimmedMean returns the trimmed mean value from a t-Digest data structure.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The trimmed mean is calculated by removing a specified fraction of the highest and lowest values from the t-Digest and then calculating the mean of the remaining values.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Returns a float representing the trimmed mean value or an error if the operation could not be completed.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tdigest.trimmed_mean/
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func ( c cmdable ) TDigestTrimmedMean ( ctx context . Context , key string , lowCutQuantile , highCutQuantile float64 ) * FloatCmd {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
args := [ ] interface { } { "TDIGEST.TRIMMED_MEAN" , key , lowCutQuantile , highCutQuantile }
cmd := NewFloatCmd ( ctx , args ... )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
_ = c ( ctx , cmd )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return cmd
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}