Use exit code 1 on error in redis-cli (#10468)

On error, redis-cli was returning `REDIS_ERR` on some cases by mistake. `REDIS_ERR` is `-1` which becomes `255` as exit code. This commit changes it and returns `1` on errors to be consistent.
This commit is contained in:
Ozan Tezcan 2022-03-30 21:16:02 +03:00 committed by GitHub
parent 6075f50663
commit 7da1cc3e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2758,7 +2758,7 @@ static int noninteractive(int argc, char **argv) {
retval = issueCommand(argc, sds_args);
sdsfreesplitres(sds_args, argc);
return retval;
return retval == REDIS_OK ? 0 : 1;
}
/*------------------------------------------------------------------------------
@ -2845,7 +2845,7 @@ static int evalMode(int argc, char **argv) {
break; /* Return to the caller. */
}
}
return retval;
return retval == REDIS_OK ? 0 : 1;
}
/*------------------------------------------------------------------------------
@ -9064,11 +9064,7 @@ int main(int argc, char **argv) {
if (cliConnect(0) != REDIS_OK) exit(1);
return evalMode(argc,argv);
} else {
int connected = (cliConnect(CC_QUIET) == REDIS_OK);
/* Try to serve command even we are not connected. e.g. help command */
int retval = noninteractive(argc,argv);
/* If failed to connect, exit with "1" for backward compatibility */
if (retval != REDIS_OK && !connected) exit(1);
return retval;
cliConnect(CC_QUIET);
return noninteractive(argc,argv);
}
}