kvrocks icon indicating copy to clipboard operation
kvrocks copied to clipboard

LPOS with COUNT replies with bulk strings instead of integers

Open DeviousDrops opened this issue 3 weeks ago • 0 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Version

  • Kvrocks: unstable, commit 84e88322
  • Compared with Redis 7.2.17 and Redis 8.0.5

Minimal reproduce step

DEL l
RPUSH l a b a
LPOS l a COUNT 1
LPOS l a COUNT 0
LPOS l a RANK -1 COUNT 2

What did you expect to see?

An array of integers, as in Redis. Redis 7.2.17 and 8.0.5 give the same output (redis-cli --no-raw):

> LPOS l a COUNT 1
1) (integer) 0
> LPOS l a COUNT 0
1) (integer) 0
2) (integer) 2
> LPOS l a RANK -1 COUNT 2
1) (integer) 2
2) (integer) 0

The LPOS docs say, for both RESP2 and RESP3:

Array reply: If the COUNT option is given, an array of integers representing the matching elements (or an empty array if there are no matches).

What did you see instead?

Kvrocks returns an array of bulk strings:

> LPOS l a COUNT 1
1) "0"
> LPOS l a COUNT 0
1) "0"
2) "2"
> LPOS l a RANK -1 COUNT 2
1) "2"
2) "0"

LPOS without COUNT already returns an integer (or nil) correctly, and the no-match case with COUNT returns an empty array correctly. Only the element type inside the COUNT array is wrong.

Anything Else?

The cause is in CommandLPos::Execute (src/commands/cmd_list.cc:886-891 on unstable). The indexes are converted with std::to_string() and sent with ArrayOfBulkStrings(), so each element is a bulk string instead of an integer reply.

The existing Go tests don't catch this because go-redis's LPosCount parses bulk strings like "2" into int64 without complaint. Clients that check reply types (or RESP3 clients that map types strictly) see strings.

Are you willing to submit a PR?

  • [x] I'm willing to submit a PR!

I'd like to work on this.

DeviousDrops avatar Nov 10 '26 17:11 DeviousDrops