From 6833d2f8e18bf050d3d34a3a2bd9881a4de1525c Mon Sep 17 00:00:00 2001 From: Monkey Date: Sat, 6 Apr 2024 21:21:14 +0800 Subject: [PATCH] fix: #2956 (#2957) Signed-off-by: monkey92t Co-authored-by: Vladimir Mihailenco --- bitmap_commands.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/bitmap_commands.go b/bitmap_commands.go index d9fc50dc..9cd80899 100644 --- a/bitmap_commands.go +++ b/bitmap_commands.go @@ -45,22 +45,19 @@ const BitCountIndexByte string = "BYTE" const BitCountIndexBit string = "BIT" func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd { - args := []interface{}{"bitcount", key} + args := make([]any, 2, 5) + args[0] = "bitcount" + args[1] = key if bitCount != nil { - if bitCount.Unit == "" { - bitCount.Unit = "BYTE" + args = append(args, bitCount.Start, bitCount.End) + if bitCount.Unit != "" { + if bitCount.Unit != BitCountIndexByte && bitCount.Unit != BitCountIndexBit { + cmd := NewIntCmd(ctx) + cmd.SetErr(errors.New("redis: invalid bitcount index")) + return cmd + } + args = append(args, bitCount.Unit) } - if bitCount.Unit != BitCountIndexByte && bitCount.Unit != BitCountIndexBit { - cmd := NewIntCmd(ctx) - cmd.SetErr(errors.New("redis: invalid bitcount index")) - return cmd - } - args = append( - args, - bitCount.Start, - bitCount.End, - string(bitCount.Unit), - ) } cmd := NewIntCmd(ctx, args...) _ = c(ctx, cmd)