Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the suffix for probablistic commands acceptings arguments to WithArgs from Args #2701

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions probabilistic.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type probabilisticCmdable interface {
BFReserve(ctx context.Context, key string, errorRate float64, capacity int64) *StatusCmd
BFReserveExpansion(ctx context.Context, key string, errorRate float64, capacity, expansion int64) *StatusCmd
BFReserveNonScaling(ctx context.Context, key string, errorRate float64, capacity int64) *StatusCmd
BFReserveArgs(ctx context.Context, key string, options *BFReserveOptions) *StatusCmd
BFReserveWithArgs(ctx context.Context, key string, options *BFReserveOptions) *StatusCmd
BFScanDump(ctx context.Context, key string, iterator int64) *ScanDumpCmd
BFLoadChunk(ctx context.Context, key string, iterator int64, data interface{}) *StatusCmd

Expand All @@ -38,7 +38,7 @@ type probabilisticCmdable interface {
CFInsertNX(ctx context.Context, key string, options *CFInsertOptions, elements ...interface{}) *IntSliceCmd
CFMExists(ctx context.Context, key string, elements ...interface{}) *BoolSliceCmd
CFReserve(ctx context.Context, key string, capacity int64) *StatusCmd
CFReserveArgs(ctx context.Context, key string, options *CFReserveOptions) *StatusCmd
CFReserveWithArgs(ctx context.Context, key string, options *CFReserveOptions) *StatusCmd
CFReserveExpansion(ctx context.Context, key string, capacity int64, expansion int64) *StatusCmd
CFReserveBucketSize(ctx context.Context, key string, capacity int64, bucketsize int64) *StatusCmd
CFReserveMaxIterations(ctx context.Context, key string, capacity int64, maxiterations int64) *StatusCmd
Expand Down Expand Up @@ -143,11 +143,11 @@ func (c cmdable) BFReserveNonScaling(ctx context.Context, key string, errorRate
return cmd
}

// BFReserveArgs creates an empty Bloom filter with a single sub-filter
// BFReserveWithArgs creates an empty Bloom filter with a single sub-filter
// for the initial specified capacity and with an upper bound error_rate.
// This function also allows for specifying additional options such as expansion rate and non-scaling behavior.
// For more information - https://redis.io/commands/bf.reserve/
func (c cmdable) BFReserveArgs(ctx context.Context, key string, options *BFReserveOptions) *StatusCmd {
func (c cmdable) BFReserveWithArgs(ctx context.Context, key string, options *BFReserveOptions) *StatusCmd {
args := []interface{}{"BF.RESERVE", key}
if options != nil {
if options.Error != 0 {
Expand Down Expand Up @@ -493,10 +493,10 @@ func (c cmdable) CFReserveMaxIterations(ctx context.Context, key string, capacit
return cmd
}

// CFReserveArgs creates an empty Cuckoo filter with the specified options.
// CFReserveWithArgs creates an empty Cuckoo filter with the specified options.
// This function allows for specifying additional options such as bucket size and maximum number of iterations.
// For more information - https://redis.io/commands/cf.reserve/
func (c cmdable) CFReserveArgs(ctx context.Context, key string, options *CFReserveOptions) *StatusCmd {
func (c cmdable) CFReserveWithArgs(ctx context.Context, key string, options *CFReserveOptions) *StatusCmd {
args := []interface{}{"CF.RESERVE", key, options.Capacity}
if options.BucketSize != 0 {
args = append(args, "BUCKETSIZE", options.BucketSize)
Expand Down Expand Up @@ -679,7 +679,7 @@ func (c cmdable) CFInfo(ctx context.Context, key string) *CFInfoCmd {
// For more information - https://redis.io/commands/cf.insert/
func (c cmdable) CFInsert(ctx context.Context, key string, options *CFInsertOptions, elements ...interface{}) *BoolSliceCmd {
args := []interface{}{"CF.INSERT", key}
args = c.getCfInsertArgs(args, options, elements...)
args = c.getCfInsertWithArgs(args, options, elements...)

cmd := NewBoolSliceCmd(ctx, args...)
_ = c(ctx, cmd)
Expand All @@ -693,14 +693,14 @@ func (c cmdable) CFInsert(ctx context.Context, key string, options *CFInsertOpti
// For more information - https://redis.io/commands/cf.insertnx/
func (c cmdable) CFInsertNX(ctx context.Context, key string, options *CFInsertOptions, elements ...interface{}) *IntSliceCmd {
args := []interface{}{"CF.INSERTNX", key}
args = c.getCfInsertArgs(args, options, elements...)
args = c.getCfInsertWithArgs(args, options, elements...)

cmd := NewIntSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}

func (c cmdable) getCfInsertArgs(args []interface{}, options *CFInsertOptions, elements ...interface{}) []interface{} {
func (c cmdable) getCfInsertWithArgs(args []interface{}, options *CFInsertOptions, elements ...interface{}) []interface{} {
if options != nil {
if options.Capacity != 0 {
args = append(args, "CAPACITY", options.Capacity)
Expand Down
8 changes: 4 additions & 4 deletions probabilistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ var _ = Describe("Probabilistic commands", Label("probabilistic"), func() {
Expect(infBefore).To(BeEquivalentTo(infAfter))
})

It("should BFReserveArgs", Label("bloom", "bfreserveargs"), func() {
It("should BFReserveWithArgs", Label("bloom", "bfreserveargs"), func() {
options := &redis.BFReserveOptions{
Capacity: 2000,
Error: 0.001,
Expansion: 3,
NonScaling: false,
}
err := client.BFReserveArgs(ctx, "testbf", options).Err()
err := client.BFReserveWithArgs(ctx, "testbf", options).Err()
Expect(err).NotTo(HaveOccurred())

result, err := client.BFInfo(ctx, "testbf").Result()
Expand Down Expand Up @@ -352,15 +352,15 @@ var _ = Describe("Probabilistic commands", Label("probabilistic"), func() {
Expect(infBefore).To(BeEquivalentTo(infAfter))
})

It("should CFInfo and CFReserveArgs", Label("cuckoo", "cfinfo", "cfreserveargs"), func() {
It("should CFInfo and CFReserveWithArgs", Label("cuckoo", "cfinfo", "cfreserveargs"), func() {
args := &redis.CFReserveOptions{
Capacity: 2048,
BucketSize: 3,
MaxIterations: 15,
Expansion: 2,
}

err := client.CFReserveArgs(ctx, "testcf1", args).Err()
err := client.CFReserveWithArgs(ctx, "testcf1", args).Err()
Expect(err).NotTo(HaveOccurred())

result, err := client.CFInfo(ctx, "testcf1").Result()
Expand Down
Loading