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)