Skip to content

Commit

Permalink
Cleaned up getSlotOrReply to return -1 instead of C_ERR
Browse files Browse the repository at this point in the history
Minor cleanup since getSlotOrReply return -1 on error, not
return C_ERR.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Oct 23, 2024
1 parent 5d70ccd commit 6aabbef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -5805,6 +5805,8 @@ const char *clusterGetMessageTypeString(int type) {
return "unknown";
}

/* Get the slot from robj and return it. If the slot is not valid,
* return -1 and send an error to the client. */
int getSlotOrReply(client *c, robj *o) {
long long slot;

Expand Down Expand Up @@ -6530,7 +6532,7 @@ int clusterCommandSpecial(client *c) {
memset(slots, 0, CLUSTER_SLOTS);
/* Check that all the arguments are parseable.*/
for (j = 2; j < c->argc; j++) {
if ((slot = getSlotOrReply(c, c->argv[j])) == C_ERR) {
if ((slot = getSlotOrReply(c, c->argv[j])) == -1) {
zfree(slots);
return 1;
}
Expand Down Expand Up @@ -6563,11 +6565,11 @@ int clusterCommandSpecial(client *c) {
/* Check that all the arguments are parseable and that all the
* slots are not already busy. */
for (j = 2; j < c->argc; j += 2) {
if ((startslot = getSlotOrReply(c, c->argv[j])) == C_ERR) {
if ((startslot = getSlotOrReply(c, c->argv[j])) == -1) {
zfree(slots);
return 1;
}
if ((endslot = getSlotOrReply(c, c->argv[j + 1])) == C_ERR) {
if ((endslot = getSlotOrReply(c, c->argv[j + 1])) == -1) {
zfree(slots);
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/cluster_slot_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ void clusterSlotStatsCommand(client *c) {
if (c->argc == 5 && !strcasecmp(c->argv[2]->ptr, "slotsrange")) {
/* CLUSTER SLOT-STATS SLOTSRANGE start-slot end-slot */
int startslot, endslot;
if ((startslot = getSlotOrReply(c, c->argv[3])) == C_ERR ||
(endslot = getSlotOrReply(c, c->argv[4])) == C_ERR) {
if ((startslot = getSlotOrReply(c, c->argv[3])) == -1 ||
(endslot = getSlotOrReply(c, c->argv[4])) == -1) {
return;
}
if (startslot > endslot) {
Expand Down

0 comments on commit 6aabbef

Please sign in to comment.