go-redis/redis · error
redis: invalid bitcount index
Error message
redis: invalid bitcount index
What it means
Error "redis: invalid bitcount index" thrown in go-redis/redis.
Source
Thrown at bitmap_commands.go:61
type BitCount struct {
Start, End int64
Unit string // BYTE(default) | BIT
}
const BitCountIndexByte string = "BYTE"
const BitCountIndexBit string = "BIT"
func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd {
args := make([]any, 2, 5)
args[0] = "bitcount"
args[1] = key
if bitCount != nil {
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)
}
}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}
func (c cmdable) bitOp(ctx context.Context, op, destKey string, keys ...string) *IntCmd {
args := make([]interface{}, 3+len(keys))
args[0] = "bitop"
args[1] = op
args[2] = destKey
for i, key := range keys {
args[3+i] = key
}View on GitHub (pinned to 36d97525cd)
Solutions
- Pass bit offsets (not byte offsets) within the key's bit length to BitCount, or omit the range entirely
- When using the BYTE unit form, ensure start/end indexes are valid for the string length
When it happens
Trigger: Thrown at bitmap_commands.go:61 when the library encounters an invalid state.
Common situations: Clamp computed bit ranges against the known value size before issuing BITCOUNT.
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/c93ada02b013ddd5.json.
Report an issue: GitHub.