-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change BITCOUNT 'end' as optional like BITPOS (#118)
_This change is the thing I suggested to redis when it was BSD, and is not just migration - this is of course more advanced_ ### Issue There is weird difference in syntax between BITPOS and BITCOUNT: ``` BITPOS key bit [start [end [BYTE | BIT]]] BITCOUNT key [start end [BYTE | BIT]] ``` I think this might cause confusion in terms of usability. It was not just a syntax typo error, and really works differently. The results below are with unstable build: ``` > get TEST:ABCD "ABCD" > BITPOS TEST:ABCD 1 0 -1 (integer) 1 > BITCOUNT TEST:ABCD 0 -1 (integer) 9 > BITPOS TEST:ABCD 1 0 (integer) 1 > BITCOUNT TEST:ABCD 0 (error) ERR syntax error ``` ### What did I fix simply changes logic, to accept BITCOUNT also without 'end' - 'end' become optional, like BITPOS ``` > GET TEST:ABCD "ABCD" > BITPOS TEST:ABCD 1 0 -1 (integer) 1 > BITCOUNT TEST:ABCD 0 -1 (integer) 9 > BITPOS TEST:ABCD 1 0 (integer) 1 > BITCOUNT TEST:ABCD 0 (integer) 9 ``` Of course, I also fixed syntax hint: ``` # ASIS > BITCOUNT key [start end [BYTE|BIT]] # TOBE > BITCOUNT key [start [end [BYTE|BIT]]] ``` ![image](https://github.com/valkey-io/valkey/assets/38001238/8485f58e-6785-4106-9f3f-45e62f90d24b) ### Moreover ... I hadn't noticed that there was very small dead code in these command logic, when I wrote PR to redis. I found it now, when write code again, so I wrote it in valkey. ``` c /* asis unstable */ /* bitcountCommand() */ if (!strcasecmp(c->argv[4]->ptr,"bit")) isbit = 1; // ... if (c->argc < 4) { if (isbit) end = (totlen<<3) + 7; else end = totlen-1; } /* bitposCommand() */ if (!strcasecmp(c->argv[5]->ptr,"bit")) isbit = 1; // ... if (c->argc < 5) { if (isbit) end = (totlen<<3) + 7; else end = totlen-1; } ``` Bit variable (actually int) "isbit" is only being set as 1, when 'BIT' is declared. But we were checking whether 'isbit' is true or false in this 'if' phrase, even if isbit could never be 1, because argc is always less than 4 (or 5 in bitpos). I think this minor fixes will make valkey command operation more consistent. Of course, this PR contains just changing args from "required" to "optional", so it will never hurt previous users. Thanks, --------- Signed-off-by: LiiNen <kjeonghoon065@gmail.com> Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
62 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters