Cleaned up getSlotOrReply is return -1 instead of C_ERR (#1211)

Minor cleanup since getSlotOrReply return -1 on error, not return C_ERR.

Signed-off-by: Binbin <binloveplay1314@qq.com>
This commit is contained in:
Binbin 2024-10-23 17:11:42 +08:00 committed by GitHub
parent 5d70ccd70e
commit b803f7aeff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -5805,6 +5805,8 @@ const char *clusterGetMessageTypeString(int type) {
return "unknown"; 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) { int getSlotOrReply(client *c, robj *o) {
long long slot; long long slot;
@ -6530,7 +6532,7 @@ int clusterCommandSpecial(client *c) {
memset(slots, 0, CLUSTER_SLOTS); memset(slots, 0, CLUSTER_SLOTS);
/* Check that all the arguments are parseable.*/ /* Check that all the arguments are parseable.*/
for (j = 2; j < c->argc; j++) { 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); zfree(slots);
return 1; return 1;
} }
@ -6563,11 +6565,11 @@ int clusterCommandSpecial(client *c) {
/* Check that all the arguments are parseable and that all the /* Check that all the arguments are parseable and that all the
* slots are not already busy. */ * slots are not already busy. */
for (j = 2; j < c->argc; j += 2) { 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); zfree(slots);
return 1; return 1;
} }
if ((endslot = getSlotOrReply(c, c->argv[j + 1])) == C_ERR) { if ((endslot = getSlotOrReply(c, c->argv[j + 1])) == -1) {
zfree(slots); zfree(slots);
return 1; return 1;
} }

View File

@ -279,8 +279,8 @@ void clusterSlotStatsCommand(client *c) {
if (c->argc == 5 && !strcasecmp(c->argv[2]->ptr, "slotsrange")) { if (c->argc == 5 && !strcasecmp(c->argv[2]->ptr, "slotsrange")) {
/* CLUSTER SLOT-STATS SLOTSRANGE start-slot end-slot */ /* CLUSTER SLOT-STATS SLOTSRANGE start-slot end-slot */
int startslot, endslot; int startslot, endslot;
if ((startslot = getSlotOrReply(c, c->argv[3])) == C_ERR || if ((startslot = getSlotOrReply(c, c->argv[3])) == -1 ||
(endslot = getSlotOrReply(c, c->argv[4])) == C_ERR) { (endslot = getSlotOrReply(c, c->argv[4])) == -1) {
return; return;
} }
if (startslot > endslot) { if (startslot > endslot) {