RDMF: REDIS_OK REDIS_ERR -> C_OK C_ERR.

This commit is contained in:
antirez 2015-07-26 23:17:55 +02:00
parent 2d9e3eb107
commit 40eb548a80
24 changed files with 512 additions and 512 deletions

View File

@ -238,17 +238,17 @@ int startAppendOnly(void) {
serverAssert(server.aof_state == REDIS_AOF_OFF); serverAssert(server.aof_state == REDIS_AOF_OFF);
if (server.aof_fd == -1) { if (server.aof_fd == -1) {
serverLog(REDIS_WARNING,"Redis needs to enable the AOF but can't open the append only file: %s",strerror(errno)); serverLog(REDIS_WARNING,"Redis needs to enable the AOF but can't open the append only file: %s",strerror(errno));
return REDIS_ERR; return C_ERR;
} }
if (rewriteAppendOnlyFileBackground() == REDIS_ERR) { if (rewriteAppendOnlyFileBackground() == C_ERR) {
close(server.aof_fd); close(server.aof_fd);
serverLog(REDIS_WARNING,"Redis needs to enable the AOF but can't trigger a background AOF rewrite operation. Check the above logs for more info about the error."); serverLog(REDIS_WARNING,"Redis needs to enable the AOF but can't trigger a background AOF rewrite operation. Check the above logs for more info about the error.");
return REDIS_ERR; return C_ERR;
} }
/* We correctly switched on AOF, now wait for the rewrite to be complete /* We correctly switched on AOF, now wait for the rewrite to be complete
* in order to append data on disk. */ * in order to append data on disk. */
server.aof_state = REDIS_AOF_WAIT_REWRITE; server.aof_state = REDIS_AOF_WAIT_REWRITE;
return REDIS_OK; return C_OK;
} }
/* Write the append only file buffer on disk. /* Write the append only file buffer on disk.
@ -380,7 +380,7 @@ void flushAppendOnlyFile(int force) {
/* Recover from failed write leaving data into the buffer. However /* Recover from failed write leaving data into the buffer. However
* set an error to stop accepting writes as long as the error * set an error to stop accepting writes as long as the error
* condition is not cleared. */ * condition is not cleared. */
server.aof_last_write_status = REDIS_ERR; server.aof_last_write_status = C_ERR;
/* Trim the sds buffer if there was a partial write, and there /* Trim the sds buffer if there was a partial write, and there
* was no way to undo it with ftruncate(2). */ * was no way to undo it with ftruncate(2). */
@ -393,10 +393,10 @@ void flushAppendOnlyFile(int force) {
} else { } else {
/* Successful write(2). If AOF was in error state, restore the /* Successful write(2). If AOF was in error state, restore the
* OK state and log the event. */ * OK state and log the event. */
if (server.aof_last_write_status == REDIS_ERR) { if (server.aof_last_write_status == C_ERR) {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"AOF write error looks solved, Redis can write again."); "AOF write error looks solved, Redis can write again.");
server.aof_last_write_status = REDIS_OK; server.aof_last_write_status = C_OK;
} }
} }
server.aof_current_size += nwritten; server.aof_current_size += nwritten;
@ -593,8 +593,8 @@ void freeFakeClient(struct client *c) {
zfree(c); zfree(c);
} }
/* Replay the append log file. On success REDIS_OK is returned. On non fatal /* Replay the append log file. On success C_OK is returned. On non fatal
* error (the append only file is zero-length) REDIS_ERR is returned. On * error (the append only file is zero-length) C_ERR is returned. On
* fatal error an error message is logged and the program exists. */ * fatal error an error message is logged and the program exists. */
int loadAppendOnlyFile(char *filename) { int loadAppendOnlyFile(char *filename) {
struct client *fakeClient; struct client *fakeClient;
@ -607,7 +607,7 @@ int loadAppendOnlyFile(char *filename) {
if (fp && redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) { if (fp && redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
server.aof_current_size = 0; server.aof_current_size = 0;
fclose(fp); fclose(fp);
return REDIS_ERR; return C_ERR;
} }
if (fp == NULL) { if (fp == NULL) {
@ -699,14 +699,14 @@ int loadAppendOnlyFile(char *filename) {
* If the client is in the middle of a MULTI/EXEC, log error and quit. */ * If the client is in the middle of a MULTI/EXEC, log error and quit. */
if (fakeClient->flags & REDIS_MULTI) goto uxeof; if (fakeClient->flags & REDIS_MULTI) goto uxeof;
loaded_ok: /* DB loaded, cleanup and return REDIS_OK to the caller. */ loaded_ok: /* DB loaded, cleanup and return C_OK to the caller. */
fclose(fp); fclose(fp);
freeFakeClient(fakeClient); freeFakeClient(fakeClient);
server.aof_state = old_aof_state; server.aof_state = old_aof_state;
stopLoading(); stopLoading();
aofUpdateCurrentSize(); aofUpdateCurrentSize();
server.aof_rewrite_base_size = server.aof_current_size; server.aof_rewrite_base_size = server.aof_current_size;
return REDIS_OK; return C_OK;
readerr: /* Read error. If feof(fp) is true, fall through to unexpected EOF. */ readerr: /* Read error. If feof(fp) is true, fall through to unexpected EOF. */
if (!feof(fp)) { if (!feof(fp)) {
@ -952,7 +952,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
long long count = 0, items = hashTypeLength(o); long long count = 0, items = hashTypeLength(o);
hi = hashTypeInitIterator(o); hi = hashTypeInitIterator(o);
while (hashTypeNext(hi) != REDIS_ERR) { while (hashTypeNext(hi) != C_ERR) {
if (count == 0) { if (count == 0) {
int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ? int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ?
REDIS_AOF_REWRITE_ITEMS_PER_CMD : items; REDIS_AOF_REWRITE_ITEMS_PER_CMD : items;
@ -1012,7 +1012,7 @@ int rewriteAppendOnlyFile(char *filename) {
fp = fopen(tmpfile,"w"); fp = fopen(tmpfile,"w");
if (!fp) { if (!fp) {
serverLog(REDIS_WARNING, "Opening the temp file for AOF rewrite in rewriteAppendOnlyFile(): %s", strerror(errno)); serverLog(REDIS_WARNING, "Opening the temp file for AOF rewrite in rewriteAppendOnlyFile(): %s", strerror(errno));
return REDIS_ERR; return C_ERR;
} }
server.aof_child_diff = sdsempty(); server.aof_child_diff = sdsempty();
@ -1027,7 +1027,7 @@ int rewriteAppendOnlyFile(char *filename) {
di = dictGetSafeIterator(d); di = dictGetSafeIterator(d);
if (!di) { if (!di) {
fclose(fp); fclose(fp);
return REDIS_ERR; return C_ERR;
} }
/* SELECT the new DB */ /* SELECT the new DB */
@ -1140,17 +1140,17 @@ int rewriteAppendOnlyFile(char *filename) {
if (rename(tmpfile,filename) == -1) { if (rename(tmpfile,filename) == -1) {
serverLog(REDIS_WARNING,"Error moving temp append only file on the final destination: %s", strerror(errno)); serverLog(REDIS_WARNING,"Error moving temp append only file on the final destination: %s", strerror(errno));
unlink(tmpfile); unlink(tmpfile);
return REDIS_ERR; return C_ERR;
} }
serverLog(REDIS_NOTICE,"SYNC append only file rewrite performed"); serverLog(REDIS_NOTICE,"SYNC append only file rewrite performed");
return REDIS_OK; return C_OK;
werr: werr:
serverLog(REDIS_WARNING,"Write error writing append only file on disk: %s", strerror(errno)); serverLog(REDIS_WARNING,"Write error writing append only file on disk: %s", strerror(errno));
fclose(fp); fclose(fp);
unlink(tmpfile); unlink(tmpfile);
if (di) dictReleaseIterator(di); if (di) dictReleaseIterator(di);
return REDIS_ERR; return C_ERR;
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
@ -1207,13 +1207,13 @@ int aofCreatePipes(void) {
server.aof_pipe_write_ack_to_child = fds[5]; server.aof_pipe_write_ack_to_child = fds[5];
server.aof_pipe_read_ack_from_parent = fds[4]; server.aof_pipe_read_ack_from_parent = fds[4];
server.aof_stop_sending_diff = 0; server.aof_stop_sending_diff = 0;
return REDIS_OK; return C_OK;
error: error:
serverLog(REDIS_WARNING,"Error opening /setting AOF rewrite IPC pipes: %s", serverLog(REDIS_WARNING,"Error opening /setting AOF rewrite IPC pipes: %s",
strerror(errno)); strerror(errno));
for (j = 0; j < 6; j++) if(fds[j] != -1) close(fds[j]); for (j = 0; j < 6; j++) if(fds[j] != -1) close(fds[j]);
return REDIS_ERR; return C_ERR;
} }
void aofClosePipes(void) { void aofClosePipes(void) {
@ -1247,8 +1247,8 @@ int rewriteAppendOnlyFileBackground(void) {
pid_t childpid; pid_t childpid;
long long start; long long start;
if (server.aof_child_pid != -1) return REDIS_ERR; if (server.aof_child_pid != -1) return C_ERR;
if (aofCreatePipes() != REDIS_OK) return REDIS_ERR; if (aofCreatePipes() != C_OK) return C_ERR;
start = ustime(); start = ustime();
if ((childpid = fork()) == 0) { if ((childpid = fork()) == 0) {
char tmpfile[256]; char tmpfile[256];
@ -1257,7 +1257,7 @@ int rewriteAppendOnlyFileBackground(void) {
closeListeningSockets(0); closeListeningSockets(0);
redisSetProcTitle("redis-aof-rewrite"); redisSetProcTitle("redis-aof-rewrite");
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid()); snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
if (rewriteAppendOnlyFile(tmpfile) == REDIS_OK) { if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
size_t private_dirty = zmalloc_get_private_dirty(); size_t private_dirty = zmalloc_get_private_dirty();
if (private_dirty) { if (private_dirty) {
@ -1278,7 +1278,7 @@ int rewriteAppendOnlyFileBackground(void) {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"Can't rewrite append only file in background: fork: %s", "Can't rewrite append only file in background: fork: %s",
strerror(errno)); strerror(errno));
return REDIS_ERR; return C_ERR;
} }
serverLog(REDIS_NOTICE, serverLog(REDIS_NOTICE,
"Background append only file rewriting started by pid %d",childpid); "Background append only file rewriting started by pid %d",childpid);
@ -1292,9 +1292,9 @@ int rewriteAppendOnlyFileBackground(void) {
* with a SELECT statement and it will be safe to merge. */ * with a SELECT statement and it will be safe to merge. */
server.aof_selected_db = -1; server.aof_selected_db = -1;
replicationScriptCacheFlush(); replicationScriptCacheFlush();
return REDIS_OK; return C_OK;
} }
return REDIS_OK; /* unreached */ return C_OK; /* unreached */
} }
void bgrewriteaofCommand(client *c) { void bgrewriteaofCommand(client *c) {
@ -1303,7 +1303,7 @@ void bgrewriteaofCommand(client *c) {
} else if (server.rdb_child_pid != -1) { } else if (server.rdb_child_pid != -1) {
server.aof_rewrite_scheduled = 1; server.aof_rewrite_scheduled = 1;
addReplyStatus(c,"Background append only file rewriting scheduled"); addReplyStatus(c,"Background append only file rewriting scheduled");
} else if (rewriteAppendOnlyFileBackground() == REDIS_OK) { } else if (rewriteAppendOnlyFileBackground() == C_OK) {
addReplyStatus(c,"Background append only file rewriting started"); addReplyStatus(c,"Background append only file rewriting started");
} else { } else {
addReply(c,shared.err); addReply(c,shared.err);
@ -1446,7 +1446,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
server.aof_buf = sdsempty(); server.aof_buf = sdsempty();
} }
server.aof_lastbgrewrite_status = REDIS_OK; server.aof_lastbgrewrite_status = C_OK;
serverLog(REDIS_NOTICE, "Background AOF rewrite finished successfully"); serverLog(REDIS_NOTICE, "Background AOF rewrite finished successfully");
/* Change state from WAIT_REWRITE to ON if needed */ /* Change state from WAIT_REWRITE to ON if needed */
@ -1459,12 +1459,12 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
serverLog(REDIS_VERBOSE, serverLog(REDIS_VERBOSE,
"Background AOF rewrite signal handler took %lldus", ustime()-now); "Background AOF rewrite signal handler took %lldus", ustime()-now);
} else if (!bysignal && exitcode != 0) { } else if (!bysignal && exitcode != 0) {
server.aof_lastbgrewrite_status = REDIS_ERR; server.aof_lastbgrewrite_status = C_ERR;
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"Background AOF rewrite terminated with error"); "Background AOF rewrite terminated with error");
} else { } else {
server.aof_lastbgrewrite_status = REDIS_ERR; server.aof_lastbgrewrite_status = C_ERR;
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"Background AOF rewrite terminated by signal %d", bysignal); "Background AOF rewrite terminated by signal %d", bysignal);

View File

@ -41,18 +41,18 @@ static int getBitOffsetFromArgument(client *c, robj *o, size_t *offset) {
long long loffset; long long loffset;
char *err = "bit offset is not an integer or out of range"; char *err = "bit offset is not an integer or out of range";
if (getLongLongFromObjectOrReply(c,o,&loffset,err) != REDIS_OK) if (getLongLongFromObjectOrReply(c,o,&loffset,err) != C_OK)
return REDIS_ERR; return C_ERR;
/* Limit offset to 512MB in bytes */ /* Limit offset to 512MB in bytes */
if ((loffset < 0) || ((unsigned long long)loffset >> 3) >= (512*1024*1024)) if ((loffset < 0) || ((unsigned long long)loffset >> 3) >= (512*1024*1024))
{ {
addReplyError(c,err); addReplyError(c,err);
return REDIS_ERR; return C_ERR;
} }
*offset = (size_t)loffset; *offset = (size_t)loffset;
return REDIS_OK; return C_OK;
} }
/* Count number of bits set in the binary array pointed by 's' and long /* Count number of bits set in the binary array pointed by 's' and long
@ -217,10 +217,10 @@ void setbitCommand(client *c) {
int byteval, bitval; int byteval, bitval;
long on; long on;
if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != REDIS_OK) if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != C_OK)
return; return;
if (getLongFromObjectOrReply(c,c->argv[3],&on,err) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[3],&on,err) != C_OK)
return; return;
/* Bits can only be set or cleared... */ /* Bits can only be set or cleared... */
@ -263,7 +263,7 @@ void getbitCommand(client *c) {
size_t byte, bit; size_t byte, bit;
size_t bitval = 0; size_t bitval = 0;
if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != REDIS_OK) if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != C_OK)
return; return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL || if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
@ -479,9 +479,9 @@ void bitcountCommand(client *c) {
/* Parse start/end range if any. */ /* Parse start/end range if any. */
if (c->argc == 4) { if (c->argc == 4) {
if (getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK)
return; return;
if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK)
return; return;
/* Convert negative indexes */ /* Convert negative indexes */
if (start < 0) start = strlen+start; if (start < 0) start = strlen+start;
@ -520,7 +520,7 @@ void bitposCommand(client *c) {
/* Parse the bit argument to understand what we are looking for, set /* Parse the bit argument to understand what we are looking for, set
* or clear bits. */ * or clear bits. */
if (getLongFromObjectOrReply(c,c->argv[2],&bit,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[2],&bit,NULL) != C_OK)
return; return;
if (bit != 0 && bit != 1) { if (bit != 0 && bit != 1) {
addReplyError(c, "The bit argument must be 1 or 0."); addReplyError(c, "The bit argument must be 1 or 0.");
@ -548,10 +548,10 @@ void bitposCommand(client *c) {
/* Parse start/end range if any. */ /* Parse start/end range if any. */
if (c->argc == 4 || c->argc == 5) { if (c->argc == 4 || c->argc == 5) {
if (getLongFromObjectOrReply(c,c->argv[3],&start,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[3],&start,NULL) != C_OK)
return; return;
if (c->argc == 5) { if (c->argc == 5) {
if (getLongFromObjectOrReply(c,c->argv[4],&end,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[4],&end,NULL) != C_OK)
return; return;
end_given = 1; end_given = 1;
} else { } else {

View File

@ -77,12 +77,12 @@ int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int
long long tval; long long tval;
if (getLongLongFromObjectOrReply(c,object,&tval, if (getLongLongFromObjectOrReply(c,object,&tval,
"timeout is not an integer or out of range") != REDIS_OK) "timeout is not an integer or out of range") != C_OK)
return REDIS_ERR; return C_ERR;
if (tval < 0) { if (tval < 0) {
addReplyError(c,"timeout is negative"); addReplyError(c,"timeout is negative");
return REDIS_ERR; return C_ERR;
} }
if (tval > 0) { if (tval > 0) {
@ -91,7 +91,7 @@ int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int
} }
*timeout = tval; *timeout = tval;
return REDIS_OK; return C_OK;
} }
/* Block a client for the specific operation type. Once the REDIS_BLOCKED /* Block a client for the specific operation type. Once the REDIS_BLOCKED

View File

@ -85,8 +85,8 @@ int clusterBumpConfigEpochWithoutConsensus(void);
* *
* If the file does not exist or is zero-length (this may happen because * If the file does not exist or is zero-length (this may happen because
* when we lock the nodes.conf file, we create a zero-length one for the * when we lock the nodes.conf file, we create a zero-length one for the
* sake of locking if it does not already exist), REDIS_ERR is returned. * sake of locking if it does not already exist), C_ERR is returned.
* If the configuration was loaded from the file, REDIS_OK is returned. */ * If the configuration was loaded from the file, C_OK is returned. */
int clusterLoadConfig(char *filename) { int clusterLoadConfig(char *filename) {
FILE *fp = fopen(filename,"r"); FILE *fp = fopen(filename,"r");
struct stat sb; struct stat sb;
@ -95,7 +95,7 @@ int clusterLoadConfig(char *filename) {
if (fp == NULL) { if (fp == NULL) {
if (errno == ENOENT) { if (errno == ENOENT) {
return REDIS_ERR; return C_ERR;
} else { } else {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"Loading the cluster node config from %s: %s", "Loading the cluster node config from %s: %s",
@ -104,11 +104,11 @@ int clusterLoadConfig(char *filename) {
} }
} }
/* Check if the file is zero-length: if so return REDIS_ERR to signal /* Check if the file is zero-length: if so return C_ERR to signal
* we have to write the config. */ * we have to write the config. */
if (fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) { if (fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
fclose(fp); fclose(fp);
return REDIS_ERR; return C_ERR;
} }
/* Parse the file. Note that single lines of the cluster config file can /* Parse the file. Note that single lines of the cluster config file can
@ -272,7 +272,7 @@ int clusterLoadConfig(char *filename) {
if (clusterGetMaxEpoch() > server.cluster->currentEpoch) { if (clusterGetMaxEpoch() > server.cluster->currentEpoch) {
server.cluster->currentEpoch = clusterGetMaxEpoch(); server.cluster->currentEpoch = clusterGetMaxEpoch();
} }
return REDIS_OK; return C_OK;
fmterr: fmterr:
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
@ -355,8 +355,8 @@ void clusterSaveConfigOrDie(int do_fsync) {
* in-place, reopening the file, and writing to it in place (later adjusting * in-place, reopening the file, and writing to it in place (later adjusting
* the length with ftruncate()). * the length with ftruncate()).
* *
* On success REDIS_OK is returned, otherwise an error is logged and * On success C_OK is returned, otherwise an error is logged and
* the function returns REDIS_ERR to signal a lock was not acquired. */ * the function returns C_ERR to signal a lock was not acquired. */
int clusterLockConfig(char *filename) { int clusterLockConfig(char *filename) {
/* flock() does not exist on Solaris /* flock() does not exist on Solaris
* and a fcntl-based solution won't help, as we constantly re-open that file, * and a fcntl-based solution won't help, as we constantly re-open that file,
@ -371,7 +371,7 @@ int clusterLockConfig(char *filename) {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"Can't open %s in order to acquire a lock: %s", "Can't open %s in order to acquire a lock: %s",
filename, strerror(errno)); filename, strerror(errno));
return REDIS_ERR; return C_ERR;
} }
if (flock(fd,LOCK_EX|LOCK_NB) == -1) { if (flock(fd,LOCK_EX|LOCK_NB) == -1) {
@ -386,13 +386,13 @@ int clusterLockConfig(char *filename) {
"Impossible to lock %s: %s", filename, strerror(errno)); "Impossible to lock %s: %s", filename, strerror(errno));
} }
close(fd); close(fd);
return REDIS_ERR; return C_ERR;
} }
/* Lock acquired: leak the 'fd' by not closing it, so that we'll retain the /* Lock acquired: leak the 'fd' by not closing it, so that we'll retain the
* lock to the file as long as the process exists. */ * lock to the file as long as the process exists. */
#endif /* __sun */ #endif /* __sun */
return REDIS_OK; return C_OK;
} }
void clusterInit(void) { void clusterInit(void) {
@ -420,11 +420,11 @@ void clusterInit(void) {
/* Lock the cluster config file to make sure every node uses /* Lock the cluster config file to make sure every node uses
* its own nodes.conf. */ * its own nodes.conf. */
if (clusterLockConfig(server.cluster_configfile) == REDIS_ERR) if (clusterLockConfig(server.cluster_configfile) == C_ERR)
exit(1); exit(1);
/* Load or create a new nodes configuration. */ /* Load or create a new nodes configuration. */
if (clusterLoadConfig(server.cluster_configfile) == REDIS_ERR) { if (clusterLoadConfig(server.cluster_configfile) == C_ERR) {
/* No configuration found. We will just use the random name provided /* No configuration found. We will just use the random name provided
* by the createClusterNode() function. */ * by the createClusterNode() function. */
myself = server.cluster->myself = myself = server.cluster->myself =
@ -452,7 +452,7 @@ void clusterInit(void) {
} }
if (listenToPort(server.port+REDIS_CLUSTER_PORT_INCR, if (listenToPort(server.port+REDIS_CLUSTER_PORT_INCR,
server.cfd,&server.cfd_count) == REDIS_ERR) server.cfd,&server.cfd_count) == C_ERR)
{ {
exit(1); exit(1);
} else { } else {
@ -783,10 +783,10 @@ int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) {
(sizeof(*master->slaves) * remaining_slaves)); (sizeof(*master->slaves) * remaining_slaves));
} }
master->numslaves--; master->numslaves--;
return REDIS_OK; return C_OK;
} }
} }
return REDIS_ERR; return C_ERR;
} }
int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) { int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) {
@ -794,12 +794,12 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) {
/* If it's already a slave, don't add it again. */ /* If it's already a slave, don't add it again. */
for (j = 0; j < master->numslaves; j++) for (j = 0; j < master->numslaves; j++)
if (master->slaves[j] == slave) return REDIS_ERR; if (master->slaves[j] == slave) return C_ERR;
master->slaves = zrealloc(master->slaves, master->slaves = zrealloc(master->slaves,
sizeof(clusterNode*)*(master->numslaves+1)); sizeof(clusterNode*)*(master->numslaves+1));
master->slaves[master->numslaves] = slave; master->slaves[master->numslaves] = slave;
master->numslaves++; master->numslaves++;
return REDIS_OK; return C_OK;
} }
void clusterNodeResetSlaves(clusterNode *n) { void clusterNodeResetSlaves(clusterNode *n) {
@ -849,7 +849,7 @@ int clusterAddNode(clusterNode *node) {
retval = dictAdd(server.cluster->nodes, retval = dictAdd(server.cluster->nodes,
sdsnewlen(node->name,REDIS_CLUSTER_NAMELEN), node); sdsnewlen(node->name,REDIS_CLUSTER_NAMELEN), node);
return (retval == DICT_OK) ? REDIS_OK : REDIS_ERR; return (retval == DICT_OK) ? C_OK : C_ERR;
} }
/* Remove a node from the cluster. The functio performs the high level /* Remove a node from the cluster. The functio performs the high level
@ -949,8 +949,8 @@ uint64_t clusterGetMaxEpoch(void) {
* 3) Persist the configuration on disk before sending packets with the * 3) Persist the configuration on disk before sending packets with the
* new configuration. * new configuration.
* *
* If the new config epoch is generated and assigend, REDIS_OK is returned, * If the new config epoch is generated and assigend, C_OK is returned,
* otherwise REDIS_ERR is returned (since the node has already the greatest * otherwise C_ERR is returned (since the node has already the greatest
* configuration around) and no operation is performed. * configuration around) and no operation is performed.
* *
* Important note: this function violates the principle that config epochs * Important note: this function violates the principle that config epochs
@ -983,9 +983,9 @@ int clusterBumpConfigEpochWithoutConsensus(void) {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"New configEpoch set to %llu", "New configEpoch set to %llu",
(unsigned long long) myself->configEpoch); (unsigned long long) myself->configEpoch);
return REDIS_OK; return C_OK;
} else { } else {
return REDIS_ERR; return C_ERR;
} }
} }
@ -3343,26 +3343,26 @@ int clusterNodeGetSlotBit(clusterNode *n, int slot) {
} }
/* Add the specified slot to the list of slots that node 'n' will /* Add the specified slot to the list of slots that node 'n' will
* serve. Return REDIS_OK if the operation ended with success. * serve. Return C_OK if the operation ended with success.
* If the slot is already assigned to another instance this is considered * If the slot is already assigned to another instance this is considered
* an error and REDIS_ERR is returned. */ * an error and C_ERR is returned. */
int clusterAddSlot(clusterNode *n, int slot) { int clusterAddSlot(clusterNode *n, int slot) {
if (server.cluster->slots[slot]) return REDIS_ERR; if (server.cluster->slots[slot]) return C_ERR;
clusterNodeSetSlotBit(n,slot); clusterNodeSetSlotBit(n,slot);
server.cluster->slots[slot] = n; server.cluster->slots[slot] = n;
return REDIS_OK; return C_OK;
} }
/* Delete the specified slot marking it as unassigned. /* Delete the specified slot marking it as unassigned.
* Returns REDIS_OK if the slot was assigned, otherwise if the slot was * Returns C_OK if the slot was assigned, otherwise if the slot was
* already unassigned REDIS_ERR is returned. */ * already unassigned C_ERR is returned. */
int clusterDelSlot(int slot) { int clusterDelSlot(int slot) {
clusterNode *n = server.cluster->slots[slot]; clusterNode *n = server.cluster->slots[slot];
if (!n) return REDIS_ERR; if (!n) return C_ERR;
serverAssert(clusterNodeClearSlotBit(n,slot) == 1); serverAssert(clusterNodeClearSlotBit(n,slot) == 1);
server.cluster->slots[slot] = NULL; server.cluster->slots[slot] = NULL;
return REDIS_OK; return C_OK;
} }
/* Delete all the slots associated with the specified node. /* Delete all the slots associated with the specified node.
@ -3505,13 +3505,13 @@ void clusterUpdateState(void) {
* this lots, we set the slots as IMPORTING from our point of view * this lots, we set the slots as IMPORTING from our point of view
* in order to justify we have those slots, and in order to make * in order to justify we have those slots, and in order to make
* redis-trib aware of the issue, so that it can try to fix it. * redis-trib aware of the issue, so that it can try to fix it.
* 2) If we find data in a DB different than DB0 we return REDIS_ERR to * 2) If we find data in a DB different than DB0 we return C_ERR to
* signal the caller it should quit the server with an error message * signal the caller it should quit the server with an error message
* or take other actions. * or take other actions.
* *
* The function always returns REDIS_OK even if it will try to correct * The function always returns C_OK even if it will try to correct
* the error described in "1". However if data is found in DB different * the error described in "1". However if data is found in DB different
* from DB0, REDIS_ERR is returned. * from DB0, C_ERR is returned.
* *
* The function also uses the logging facility in order to warn the user * The function also uses the logging facility in order to warn the user
* about desynchronizations between the data we have in memory and the * about desynchronizations between the data we have in memory and the
@ -3522,11 +3522,11 @@ int verifyClusterConfigWithData(void) {
/* If this node is a slave, don't perform the check at all as we /* If this node is a slave, don't perform the check at all as we
* completely depend on the replication stream. */ * completely depend on the replication stream. */
if (nodeIsSlave(myself)) return REDIS_OK; if (nodeIsSlave(myself)) return C_OK;
/* Make sure we only have keys in DB0. */ /* Make sure we only have keys in DB0. */
for (j = 1; j < server.dbnum; j++) { for (j = 1; j < server.dbnum; j++) {
if (dictSize(server.db[j].dict)) return REDIS_ERR; if (dictSize(server.db[j].dict)) return C_ERR;
} }
/* Check that all the slots we see populated memory have a corresponding /* Check that all the slots we see populated memory have a corresponding
@ -3557,7 +3557,7 @@ int verifyClusterConfigWithData(void) {
} }
} }
if (update_config) clusterSaveConfigOrDie(1); if (update_config) clusterSaveConfigOrDie(1);
return REDIS_OK; return C_OK;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -3725,7 +3725,7 @@ sds clusterGenNodesDescription(int filter) {
int getSlotOrReply(client *c, robj *o) { int getSlotOrReply(client *c, robj *o) {
long long slot; long long slot;
if (getLongLongFromObject(o,&slot) != REDIS_OK || if (getLongLongFromObject(o,&slot) != C_OK ||
slot < 0 || slot >= REDIS_CLUSTER_SLOTS) slot < 0 || slot >= REDIS_CLUSTER_SLOTS)
{ {
addReplyError(c,"Invalid or out of range slot"); addReplyError(c,"Invalid or out of range slot");
@ -3813,7 +3813,7 @@ void clusterCommand(client *c) {
if (!strcasecmp(c->argv[1]->ptr,"meet") && c->argc == 4) { if (!strcasecmp(c->argv[1]->ptr,"meet") && c->argc == 4) {
long long port; long long port;
if (getLongLongFromObject(c->argv[3], &port) != REDIS_OK) { if (getLongLongFromObject(c->argv[3], &port) != C_OK) {
addReplyErrorFormat(c,"Invalid TCP port specified: %s", addReplyErrorFormat(c,"Invalid TCP port specified: %s",
(char*)c->argv[3]->ptr); (char*)c->argv[3]->ptr);
return; return;
@ -3894,7 +3894,7 @@ void clusterCommand(client *c) {
retval = del ? clusterDelSlot(j) : retval = del ? clusterDelSlot(j) :
clusterAddSlot(myself,j); clusterAddSlot(myself,j);
serverAssertWithInfo(c,NULL,retval == REDIS_OK); serverAssertWithInfo(c,NULL,retval == C_OK);
} }
} }
zfree(slots); zfree(slots);
@ -3977,7 +3977,7 @@ void clusterCommand(client *c) {
* failover happens at the same time we close the slot, the * failover happens at the same time we close the slot, the
* configEpoch collision resolution will fix it assigning * configEpoch collision resolution will fix it assigning
* a different epoch to each node. */ * a different epoch to each node. */
if (clusterBumpConfigEpochWithoutConsensus() == REDIS_OK) { if (clusterBumpConfigEpochWithoutConsensus() == C_OK) {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"configEpoch updated after importing slot %d", slot); "configEpoch updated after importing slot %d", slot);
} }
@ -4061,7 +4061,7 @@ void clusterCommand(client *c) {
/* CLUSTER COUNTKEYSINSLOT <slot> */ /* CLUSTER COUNTKEYSINSLOT <slot> */
long long slot; long long slot;
if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != C_OK)
return; return;
if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS) { if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS) {
addReplyError(c,"Invalid slot"); addReplyError(c,"Invalid slot");
@ -4074,10 +4074,10 @@ void clusterCommand(client *c) {
unsigned int numkeys, j; unsigned int numkeys, j;
robj **keys; robj **keys;
if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != C_OK)
return; return;
if (getLongLongFromObjectOrReply(c,c->argv[3],&maxkeys,NULL) if (getLongLongFromObjectOrReply(c,c->argv[3],&maxkeys,NULL)
!= REDIS_OK) != C_OK)
return; return;
if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS || maxkeys < 0) { if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS || maxkeys < 0) {
addReplyError(c,"Invalid slot or number of keys"); addReplyError(c,"Invalid slot or number of keys");
@ -4245,7 +4245,7 @@ void clusterCommand(client *c) {
* resolution system which is too slow when a big cluster is created. */ * resolution system which is too slow when a big cluster is created. */
long long epoch; long long epoch;
if (getLongLongFromObjectOrReply(c,c->argv[2],&epoch,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[2],&epoch,NULL) != C_OK)
return; return;
if (epoch < 0) { if (epoch < 0) {
@ -4339,7 +4339,7 @@ void createDumpPayload(rio *payload, robj *o) {
/* Verify that the RDB version of the dump payload matches the one of this Redis /* Verify that the RDB version of the dump payload matches the one of this Redis
* instance and that the checksum is ok. * instance and that the checksum is ok.
* If the DUMP payload looks valid REDIS_OK is returned, otherwise REDIS_ERR * If the DUMP payload looks valid C_OK is returned, otherwise C_ERR
* is returned. */ * is returned. */
int verifyDumpPayload(unsigned char *p, size_t len) { int verifyDumpPayload(unsigned char *p, size_t len) {
unsigned char *footer; unsigned char *footer;
@ -4347,17 +4347,17 @@ int verifyDumpPayload(unsigned char *p, size_t len) {
uint64_t crc; uint64_t crc;
/* At least 2 bytes of RDB version and 8 of CRC64 should be present. */ /* At least 2 bytes of RDB version and 8 of CRC64 should be present. */
if (len < 10) return REDIS_ERR; if (len < 10) return C_ERR;
footer = p+(len-10); footer = p+(len-10);
/* Verify RDB version */ /* Verify RDB version */
rdbver = (footer[1] << 8) | footer[0]; rdbver = (footer[1] << 8) | footer[0];
if (rdbver != REDIS_RDB_VERSION) return REDIS_ERR; if (rdbver != REDIS_RDB_VERSION) return C_ERR;
/* Verify CRC64 */ /* Verify CRC64 */
crc = crc64(0,p,len-8); crc = crc64(0,p,len-8);
memrev64ifbe(&crc); memrev64ifbe(&crc);
return (memcmp(&crc,footer+2,8) == 0) ? REDIS_OK : REDIS_ERR; return (memcmp(&crc,footer+2,8) == 0) ? C_OK : C_ERR;
} }
/* DUMP keyname /* DUMP keyname
@ -4407,7 +4407,7 @@ void restoreCommand(client *c) {
} }
/* Check if the TTL value makes sense */ /* Check if the TTL value makes sense */
if (getLongLongFromObjectOrReply(c,c->argv[2],&ttl,NULL) != REDIS_OK) { if (getLongLongFromObjectOrReply(c,c->argv[2],&ttl,NULL) != C_OK) {
return; return;
} else if (ttl < 0) { } else if (ttl < 0) {
addReplyError(c,"Invalid TTL value, must be >= 0"); addReplyError(c,"Invalid TTL value, must be >= 0");
@ -4415,7 +4415,7 @@ void restoreCommand(client *c) {
} }
/* Verify RDB version and data checksum. */ /* Verify RDB version and data checksum. */
if (verifyDumpPayload(c->argv[3]->ptr,sdslen(c->argv[3]->ptr)) == REDIS_ERR) if (verifyDumpPayload(c->argv[3]->ptr,sdslen(c->argv[3]->ptr)) == C_ERR)
{ {
addReplyError(c,"DUMP payload version or checksum are wrong"); addReplyError(c,"DUMP payload version or checksum are wrong");
return; return;
@ -4587,9 +4587,9 @@ try_again:
} }
/* Sanity check */ /* Sanity check */
if (getLongFromObjectOrReply(c,c->argv[5],&timeout,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[5],&timeout,NULL) != C_OK)
return; return;
if (getLongFromObjectOrReply(c,c->argv[4],&dbid,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[4],&dbid,NULL) != C_OK)
return; return;
if (timeout <= 0) timeout = 1000; if (timeout <= 0) timeout = 1000;

View File

@ -677,7 +677,7 @@ void loadServerConfig(char *filename, char *options) {
#define config_set_numerical_field(_name,_var,min,max) \ #define config_set_numerical_field(_name,_var,min,max) \
} else if (!strcasecmp(c->argv[2]->ptr,_name)) { \ } else if (!strcasecmp(c->argv[2]->ptr,_name)) { \
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 0) goto badfmt; \ if (getLongLongFromObject(o,&ll) == C_ERR || ll < 0) goto badfmt; \
if (min != LLONG_MIN && ll < min) goto badfmt; \ if (min != LLONG_MIN && ll < min) goto badfmt; \
if (max != LLONG_MAX && ll > max) goto badfmt; \ if (max != LLONG_MAX && ll > max) goto badfmt; \
_var = ll; _var = ll;
@ -727,7 +727,7 @@ void configSetCommand(client *c) {
} config_set_special_field("maxclients") { } config_set_special_field("maxclients") {
int orig_value = server.maxclients; int orig_value = server.maxclients;
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll < 1) goto badfmt; if (getLongLongFromObject(o,&ll) == C_ERR || ll < 1) goto badfmt;
/* Try to check if the OS is capable of supporting so many FDs. */ /* Try to check if the OS is capable of supporting so many FDs. */
server.maxclients = ll; server.maxclients = ll;
@ -757,7 +757,7 @@ void configSetCommand(client *c) {
if (enable == 0 && server.aof_state != REDIS_AOF_OFF) { if (enable == 0 && server.aof_state != REDIS_AOF_OFF) {
stopAppendOnly(); stopAppendOnly();
} else if (enable && server.aof_state == REDIS_AOF_OFF) { } else if (enable && server.aof_state == REDIS_AOF_OFF) {
if (startAppendOnly() == REDIS_ERR) { if (startAppendOnly() == C_ERR) {
addReplyError(c, addReplyError(c,
"Unable to turn on AOF. Check server logs."); "Unable to turn on AOF. Check server logs.");
return; return;

View File

@ -119,7 +119,7 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
sds copy = sdsdup(key->ptr); sds copy = sdsdup(key->ptr);
int retval = dictAdd(db->dict, copy, val); int retval = dictAdd(db->dict, copy, val);
serverAssertWithInfo(NULL,key,retval == REDIS_OK); serverAssertWithInfo(NULL,key,retval == C_OK);
if (val->type == OBJ_LIST) signalListAsReady(db, key); if (val->type == OBJ_LIST) signalListAsReady(db, key);
if (server.cluster_enabled) slotToKeyAdd(key); if (server.cluster_enabled) slotToKeyAdd(key);
} }
@ -249,9 +249,9 @@ long long emptyDb(void(callback)(void*)) {
int selectDb(client *c, int id) { int selectDb(client *c, int id) {
if (id < 0 || id >= server.dbnum) if (id < 0 || id >= server.dbnum)
return REDIS_ERR; return C_ERR;
c->db = &server.db[id]; c->db = &server.db[id];
return REDIS_OK; return C_OK;
} }
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
@ -335,14 +335,14 @@ void selectCommand(client *c) {
long id; long id;
if (getLongFromObjectOrReply(c, c->argv[1], &id, if (getLongFromObjectOrReply(c, c->argv[1], &id,
"invalid DB index") != REDIS_OK) "invalid DB index") != C_OK)
return; return;
if (server.cluster_enabled && id != 0) { if (server.cluster_enabled && id != 0) {
addReplyError(c,"SELECT is not allowed in cluster mode"); addReplyError(c,"SELECT is not allowed in cluster mode");
return; return;
} }
if (selectDb(c,id) == REDIS_ERR) { if (selectDb(c,id) == C_ERR) {
addReplyError(c,"invalid DB index"); addReplyError(c,"invalid DB index");
} else { } else {
addReply(c,shared.ok); addReply(c,shared.ok);
@ -421,7 +421,7 @@ void scanCallback(void *privdata, const dictEntry *de) {
/* Try to parse a SCAN cursor stored at object 'o': /* Try to parse a SCAN cursor stored at object 'o':
* if the cursor is valid, store it as unsigned integer into *cursor and * if the cursor is valid, store it as unsigned integer into *cursor and
* returns REDIS_OK. Otherwise return REDIS_ERR and send an error to the * returns C_OK. Otherwise return C_ERR and send an error to the
* client. */ * client. */
int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor) { int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor) {
char *eptr; char *eptr;
@ -433,9 +433,9 @@ int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor) {
if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || errno == ERANGE) if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || errno == ERANGE)
{ {
addReplyError(c, "invalid cursor"); addReplyError(c, "invalid cursor");
return REDIS_ERR; return C_ERR;
} }
return REDIS_OK; return C_OK;
} }
/* This command implements SCAN, HSCAN and SSCAN commands. /* This command implements SCAN, HSCAN and SSCAN commands.
@ -471,7 +471,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
j = c->argc - i; j = c->argc - i;
if (!strcasecmp(c->argv[i]->ptr, "count") && j >= 2) { if (!strcasecmp(c->argv[i]->ptr, "count") && j >= 2) {
if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL) if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL)
!= REDIS_OK) != C_OK)
{ {
goto cleanup; goto cleanup;
} }
@ -629,7 +629,7 @@ cleanup:
/* The SCAN command completely relies on scanGenericCommand. */ /* The SCAN command completely relies on scanGenericCommand. */
void scanCommand(client *c) { void scanCommand(client *c) {
unsigned long cursor; unsigned long cursor;
if (parseScanCursorOrReply(c,c->argv[1],&cursor) == REDIS_ERR) return; if (parseScanCursorOrReply(c,c->argv[1],&cursor) == C_ERR) return;
scanGenericCommand(c,NULL,cursor); scanGenericCommand(c,NULL,cursor);
} }
@ -685,7 +685,7 @@ void shutdownCommand(client *c) {
* Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */ * Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */
if (server.loading || server.sentinel_mode) if (server.loading || server.sentinel_mode)
flags = (flags & ~REDIS_SHUTDOWN_SAVE) | REDIS_SHUTDOWN_NOSAVE; flags = (flags & ~REDIS_SHUTDOWN_SAVE) | REDIS_SHUTDOWN_NOSAVE;
if (prepareForShutdown(flags) == REDIS_OK) exit(0); if (prepareForShutdown(flags) == C_OK) exit(0);
addReplyError(c,"Errors trying to SHUTDOWN. Check logs."); addReplyError(c,"Errors trying to SHUTDOWN. Check logs.");
} }
@ -754,9 +754,9 @@ void moveCommand(client *c) {
src = c->db; src = c->db;
srcid = c->db->id; srcid = c->db->id;
if (getLongLongFromObject(c->argv[2],&dbid) == REDIS_ERR || if (getLongLongFromObject(c->argv[2],&dbid) == C_ERR ||
dbid < INT_MIN || dbid > INT_MAX || dbid < INT_MIN || dbid > INT_MAX ||
selectDb(c,dbid) == REDIS_ERR) selectDb(c,dbid) == C_ERR)
{ {
addReply(c,shared.outofrangeerr); addReply(c,shared.outofrangeerr);
return; return;
@ -903,7 +903,7 @@ void expireGenericCommand(client *c, long long basetime, int unit) {
robj *key = c->argv[1], *param = c->argv[2]; robj *key = c->argv[1], *param = c->argv[2];
long long when; /* unix time in milliseconds when the key will expire. */ long long when; /* unix time in milliseconds when the key will expire. */
if (getLongLongFromObjectOrReply(c, param, &when, NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c, param, &when, NULL) != C_OK)
return; return;
if (unit == UNIT_SECONDS) when *= 1000; if (unit == UNIT_SECONDS) when *= 1000;

View File

@ -226,7 +226,7 @@ void computeDatasetDigest(unsigned char *final) {
robj *obj; robj *obj;
hi = hashTypeInitIterator(o); hi = hashTypeInitIterator(o);
while (hashTypeNext(hi) != REDIS_ERR) { while (hashTypeNext(hi) != C_ERR) {
unsigned char eledigest[20]; unsigned char eledigest[20];
memset(eledigest,0,20); memset(eledigest,0,20);
@ -269,12 +269,12 @@ void debugCommand(client *c) {
if (c->argc >= 3) c->argv[2] = tryObjectEncoding(c->argv[2]); if (c->argc >= 3) c->argv[2] = tryObjectEncoding(c->argv[2]);
serverAssertWithInfo(c,c->argv[0],1 == 2); serverAssertWithInfo(c,c->argv[0],1 == 2);
} else if (!strcasecmp(c->argv[1]->ptr,"reload")) { } else if (!strcasecmp(c->argv[1]->ptr,"reload")) {
if (rdbSave(server.rdb_filename) != REDIS_OK) { if (rdbSave(server.rdb_filename) != C_OK) {
addReply(c,shared.err); addReply(c,shared.err);
return; return;
} }
emptyDb(NULL); emptyDb(NULL);
if (rdbLoad(server.rdb_filename) != REDIS_OK) { if (rdbLoad(server.rdb_filename) != C_OK) {
addReplyError(c,"Error trying to load the RDB dump"); addReplyError(c,"Error trying to load the RDB dump");
return; return;
} }
@ -282,7 +282,7 @@ void debugCommand(client *c) {
addReply(c,shared.ok); addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"loadaof")) { } else if (!strcasecmp(c->argv[1]->ptr,"loadaof")) {
emptyDb(NULL); emptyDb(NULL);
if (loadAppendOnlyFile(server.aof_filename) != REDIS_OK) { if (loadAppendOnlyFile(server.aof_filename) != C_OK) {
addReply(c,shared.err); addReply(c,shared.err);
return; return;
} }
@ -370,7 +370,7 @@ void debugCommand(client *c) {
robj *key, *val; robj *key, *val;
char buf[128]; char buf[128];
if (getLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != REDIS_OK) if (getLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != C_OK)
return; return;
dictExpand(c->db->dict,keys); dictExpand(c->db->dict,keys);
for (j = 0; j < keys; j++) { for (j = 0; j < keys; j++) {
@ -434,7 +434,7 @@ void debugCommand(client *c) {
sds stats = sdsempty(); sds stats = sdsempty();
char buf[4096]; char buf[4096];
if (getLongFromObjectOrReply(c, c->argv[2], &dbid, NULL) != REDIS_OK) if (getLongFromObjectOrReply(c, c->argv[2], &dbid, NULL) != C_OK)
return; return;
if (dbid < 0 || dbid >= server.dbnum) { if (dbid < 0 || dbid >= server.dbnum) {
addReplyError(c,"Out of range database"); addReplyError(c,"Out of range database");

View File

@ -88,33 +88,33 @@ int decodeGeohash(double bits, double *xy) {
/* Input Argument Helper */ /* Input Argument Helper */
/* Take a pointer to the latitude arg then use the next arg for longitude. /* Take a pointer to the latitude arg then use the next arg for longitude.
* On parse error REDIS_ERR is returned, otherwise REDIS_OK. */ * On parse error C_ERR is returned, otherwise C_OK. */
int extractLongLatOrReply(client *c, robj **argv, int extractLongLatOrReply(client *c, robj **argv,
double *xy) { double *xy) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
if (getDoubleFromObjectOrReply(c, argv[i], xy + i, NULL) != if (getDoubleFromObjectOrReply(c, argv[i], xy + i, NULL) !=
REDIS_OK) { C_OK) {
return REDIS_ERR; return C_ERR;
} }
if (xy[0] < GEO_LONG_MIN || xy[0] > GEO_LONG_MAX || if (xy[0] < GEO_LONG_MIN || xy[0] > GEO_LONG_MAX ||
xy[1] < GEO_LAT_MIN || xy[1] > GEO_LAT_MAX) { xy[1] < GEO_LAT_MIN || xy[1] > GEO_LAT_MAX) {
addReplySds(c, sdscatprintf(sdsempty(), addReplySds(c, sdscatprintf(sdsempty(),
"-ERR invalid longitude,latitude pair %f,%f\r\n",xy[0],xy[1])); "-ERR invalid longitude,latitude pair %f,%f\r\n",xy[0],xy[1]));
return REDIS_ERR; return C_ERR;
} }
} }
return REDIS_OK; return C_OK;
} }
/* Input Argument Helper */ /* Input Argument Helper */
/* Decode lat/long from a zset member's score. /* Decode lat/long from a zset member's score.
* Returns REDIS_OK on successful decoding, otherwise REDIS_ERR is returned. */ * Returns C_OK on successful decoding, otherwise C_ERR is returned. */
int longLatFromMember(robj *zobj, robj *member, double *xy) { int longLatFromMember(robj *zobj, robj *member, double *xy) {
double score = 0; double score = 0;
if (zsetScore(zobj, member, &score) == REDIS_ERR) return REDIS_ERR; if (zsetScore(zobj, member, &score) == C_ERR) return C_ERR;
if (!decodeGeohash(score, xy)) return REDIS_ERR; if (!decodeGeohash(score, xy)) return C_ERR;
return REDIS_OK; return C_OK;
} }
/* Check that the unit argument matches one of the known units, and returns /* Check that the unit argument matches one of the known units, and returns
@ -152,7 +152,7 @@ double extractDistanceOrReply(client *c, robj **argv,
double *conversion) { double *conversion) {
double distance; double distance;
if (getDoubleFromObjectOrReply(c, argv[0], &distance, if (getDoubleFromObjectOrReply(c, argv[0], &distance,
"need numeric radius") != REDIS_OK) { "need numeric radius") != C_OK) {
return -1; return -1;
} }
@ -179,17 +179,17 @@ void addReplyDoubleDistance(client *c, double d) {
* a radius, appends this entry as a geoPoint into the specified geoArray * a radius, appends this entry as a geoPoint into the specified geoArray
* only if the point is within the search area. * only if the point is within the search area.
* *
* returns REDIS_OK if the point is included, or REIDS_ERR if it is outside. */ * returns C_OK if the point is included, or REIDS_ERR if it is outside. */
int geoAppendIfWithinRadius(geoArray *ga, double lon, double lat, double radius, double score, sds member) { int geoAppendIfWithinRadius(geoArray *ga, double lon, double lat, double radius, double score, sds member) {
double distance, xy[2]; double distance, xy[2];
if (!decodeGeohash(score,xy)) return REDIS_ERR; /* Can't decode. */ if (!decodeGeohash(score,xy)) return C_ERR; /* Can't decode. */
/* Note that geohashGetDistanceIfInRadiusWGS84() takes arguments in /* Note that geohashGetDistanceIfInRadiusWGS84() takes arguments in
* reverse order: longitude first, latitude later. */ * reverse order: longitude first, latitude later. */
if (!geohashGetDistanceIfInRadiusWGS84(lon,lat, xy[0], xy[1], if (!geohashGetDistanceIfInRadiusWGS84(lon,lat, xy[0], xy[1],
radius, &distance)) radius, &distance))
{ {
return REDIS_ERR; return C_ERR;
} }
/* Append the new element. */ /* Append the new element. */
@ -199,7 +199,7 @@ int geoAppendIfWithinRadius(geoArray *ga, double lon, double lat, double radius,
gp->dist = distance; gp->dist = distance;
gp->member = member; gp->member = member;
gp->score = score; gp->score = score;
return REDIS_OK; return C_OK;
} }
/* Query a Redis sorted set to extract all the elements between 'min' and /* Query a Redis sorted set to extract all the elements between 'min' and
@ -247,7 +247,7 @@ int geoGetPointsInRange(robj *zobj, double min, double max, double lon, double l
member = (vstr == NULL) ? sdsfromlonglong(vlong) : member = (vstr == NULL) ? sdsfromlonglong(vlong) :
sdsnewlen(vstr,vlen); sdsnewlen(vstr,vlen);
if (geoAppendIfWithinRadius(ga,lon,lat,radius,score,member) if (geoAppendIfWithinRadius(ga,lon,lat,radius,score,member)
== REDIS_ERR) sdsfree(member); == C_ERR) sdsfree(member);
zzlNext(zl, &eptr, &sptr); zzlNext(zl, &eptr, &sptr);
} }
} else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) { } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
@ -270,7 +270,7 @@ int geoGetPointsInRange(robj *zobj, double min, double max, double lon, double l
sdsfromlonglong((long)o->ptr) : sdsfromlonglong((long)o->ptr) :
sdsdup(o->ptr); sdsdup(o->ptr);
if (geoAppendIfWithinRadius(ga,lon,lat,radius,ln->score,member) if (geoAppendIfWithinRadius(ga,lon,lat,radius,ln->score,member)
== REDIS_ERR) sdsfree(member); == C_ERR) sdsfree(member);
ln = ln->level[0].forward; ln = ln->level[0].forward;
} }
} }
@ -386,7 +386,7 @@ void geoaddCommand(client *c) {
for (i = 0; i < elements; i++) { for (i = 0; i < elements; i++) {
double xy[2]; double xy[2];
if (extractLongLatOrReply(c, (c->argv+2)+(i*3),xy) == REDIS_ERR) { if (extractLongLatOrReply(c, (c->argv+2)+(i*3),xy) == C_ERR) {
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
if (argv[i]) decrRefCount(argv[i]); if (argv[i]) decrRefCount(argv[i]);
zfree(argv); zfree(argv);
@ -434,12 +434,12 @@ void georadiusGeneric(client *c, int type) {
double xy[2] = { 0 }; double xy[2] = { 0 };
if (type == RADIUS_COORDS) { if (type == RADIUS_COORDS) {
base_args = 6; base_args = 6;
if (extractLongLatOrReply(c, c->argv + 2, xy) == REDIS_ERR) if (extractLongLatOrReply(c, c->argv + 2, xy) == C_ERR)
return; return;
} else if (type == RADIUS_MEMBER) { } else if (type == RADIUS_MEMBER) {
base_args = 5; base_args = 5;
robj *member = c->argv[2]; robj *member = c->argv[2];
if (longLatFromMember(zobj, member, xy) == REDIS_ERR) { if (longLatFromMember(zobj, member, xy) == C_ERR) {
addReplyError(c, "could not decode requested zset member"); addReplyError(c, "could not decode requested zset member");
return; return;
} }
@ -475,7 +475,7 @@ void georadiusGeneric(client *c, int type) {
sort = SORT_DESC; sort = SORT_DESC;
} else if (!strcasecmp(arg, "count") && remaining > 0) { } else if (!strcasecmp(arg, "count") && remaining > 0) {
if (getLongLongFromObjectOrReply(c, c->argv[base_args+i+1], if (getLongLongFromObjectOrReply(c, c->argv[base_args+i+1],
&count, NULL) != REDIS_OK) return; &count, NULL) != C_OK) return;
if (count <= 0) { if (count <= 0) {
addReplyError(c,"COUNT must be > 0"); addReplyError(c,"COUNT must be > 0");
return; return;
@ -596,7 +596,7 @@ void geohashCommand(client *c) {
addReplyMultiBulkLen(c,c->argc-2); addReplyMultiBulkLen(c,c->argc-2);
for (j = 2; j < c->argc; j++) { for (j = 2; j < c->argc; j++) {
double score; double score;
if (zsetScore(zobj, c->argv[j], &score) == REDIS_ERR) { if (zsetScore(zobj, c->argv[j], &score) == C_ERR) {
addReply(c,shared.nullbulk); addReply(c,shared.nullbulk);
} else { } else {
/* The internal format we use for geocoding is a bit different /* The internal format we use for geocoding is a bit different
@ -650,7 +650,7 @@ void geoposCommand(client *c) {
addReplyMultiBulkLen(c,c->argc-2); addReplyMultiBulkLen(c,c->argc-2);
for (j = 2; j < c->argc; j++) { for (j = 2; j < c->argc; j++) {
double score; double score;
if (zsetScore(zobj, c->argv[j], &score) == REDIS_ERR) { if (zsetScore(zobj, c->argv[j], &score) == C_ERR) {
addReply(c,shared.nullmultibulk); addReply(c,shared.nullmultibulk);
} else { } else {
/* Decode... */ /* Decode... */
@ -690,8 +690,8 @@ void geodistCommand(client *c) {
/* Get the scores. We need both otherwise NULL is returned. */ /* Get the scores. We need both otherwise NULL is returned. */
double score1, score2, xyxy[4]; double score1, score2, xyxy[4];
if (zsetScore(zobj, c->argv[2], &score1) == REDIS_ERR || if (zsetScore(zobj, c->argv[2], &score1) == C_ERR ||
zsetScore(zobj, c->argv[3], &score2) == REDIS_ERR) zsetScore(zobj, c->argv[3], &score2) == C_ERR)
{ {
addReply(c,shared.nullbulk); addReply(c,shared.nullbulk);
return; return;

View File

@ -563,8 +563,8 @@ double hllDenseSum(uint8_t *registers, double *PE, int *ezp) {
* representation. Both representations are represented by SDS strings, and * representation. Both representations are represented by SDS strings, and
* the input representation is freed as a side effect. * the input representation is freed as a side effect.
* *
* The function returns REDIS_OK if the sparse representation was valid, * The function returns C_OK if the sparse representation was valid,
* otherwise REDIS_ERR is returned if the representation was corrupted. */ * otherwise C_ERR is returned if the representation was corrupted. */
int hllSparseToDense(robj *o) { int hllSparseToDense(robj *o) {
sds sparse = o->ptr, dense; sds sparse = o->ptr, dense;
struct hllhdr *hdr, *oldhdr = (struct hllhdr*)sparse; struct hllhdr *hdr, *oldhdr = (struct hllhdr*)sparse;
@ -573,7 +573,7 @@ int hllSparseToDense(robj *o) {
/* If the representation is already the right one return ASAP. */ /* If the representation is already the right one return ASAP. */
hdr = (struct hllhdr*) sparse; hdr = (struct hllhdr*) sparse;
if (hdr->encoding == HLL_DENSE) return REDIS_OK; if (hdr->encoding == HLL_DENSE) return C_OK;
/* Create a string of the right size filled with zero bytes. /* Create a string of the right size filled with zero bytes.
* Note that the cached cardinality is set to 0 as a side effect * Note that the cached cardinality is set to 0 as a side effect
@ -610,13 +610,13 @@ int hllSparseToDense(robj *o) {
* set to HLL_REGISTERS. */ * set to HLL_REGISTERS. */
if (idx != HLL_REGISTERS) { if (idx != HLL_REGISTERS) {
sdsfree(dense); sdsfree(dense);
return REDIS_ERR; return C_ERR;
} }
/* Free the old representation and set the new one. */ /* Free the old representation and set the new one. */
sdsfree(o->ptr); sdsfree(o->ptr);
o->ptr = dense; o->ptr = dense;
return REDIS_OK; return C_OK;
} }
/* "Add" the element in the sparse hyperloglog data structure. /* "Add" the element in the sparse hyperloglog data structure.
@ -866,7 +866,7 @@ updated:
return 1; return 1;
promote: /* Promote to dense representation. */ promote: /* Promote to dense representation. */
if (hllSparseToDense(o) == REDIS_ERR) return -1; /* Corrupted HLL. */ if (hllSparseToDense(o) == C_ERR) return -1; /* Corrupted HLL. */
hdr = o->ptr; hdr = o->ptr;
/* We need to call hllDenseAdd() to perform the operation after the /* We need to call hllDenseAdd() to perform the operation after the
@ -1039,7 +1039,7 @@ int hllAdd(robj *o, unsigned char *ele, size_t elesize) {
* The hll object must be already validated via isHLLObjectOrReply() * The hll object must be already validated via isHLLObjectOrReply()
* or in some other way. * or in some other way.
* *
* If the HyperLogLog is sparse and is found to be invalid, REDIS_ERR * If the HyperLogLog is sparse and is found to be invalid, C_ERR
* is returned, otherwise the function always succeeds. */ * is returned, otherwise the function always succeeds. */
int hllMerge(uint8_t *max, robj *hll) { int hllMerge(uint8_t *max, robj *hll) {
struct hllhdr *hdr = hll->ptr; struct hllhdr *hdr = hll->ptr;
@ -1077,9 +1077,9 @@ int hllMerge(uint8_t *max, robj *hll) {
p++; p++;
} }
} }
if (i != HLL_REGISTERS) return REDIS_ERR; if (i != HLL_REGISTERS) return C_ERR;
} }
return REDIS_OK; return C_OK;
} }
/* ========================== HyperLogLog commands ========================== */ /* ========================== HyperLogLog commands ========================== */
@ -1119,14 +1119,14 @@ robj *createHLLObject(void) {
} }
/* Check if the object is a String with a valid HLL representation. /* Check if the object is a String with a valid HLL representation.
* Return REDIS_OK if this is true, otherwise reply to the client * Return C_OK if this is true, otherwise reply to the client
* with an error and return REDIS_ERR. */ * with an error and return C_ERR. */
int isHLLObjectOrReply(client *c, robj *o) { int isHLLObjectOrReply(client *c, robj *o) {
struct hllhdr *hdr; struct hllhdr *hdr;
/* Key exists, check type */ /* Key exists, check type */
if (checkType(c,o,OBJ_STRING)) if (checkType(c,o,OBJ_STRING))
return REDIS_ERR; /* Error already sent. */ return C_ERR; /* Error already sent. */
if (stringObjectLen(o) < sizeof(*hdr)) goto invalid; if (stringObjectLen(o) < sizeof(*hdr)) goto invalid;
hdr = o->ptr; hdr = o->ptr;
@ -1142,13 +1142,13 @@ int isHLLObjectOrReply(client *c, robj *o) {
stringObjectLen(o) != HLL_DENSE_SIZE) goto invalid; stringObjectLen(o) != HLL_DENSE_SIZE) goto invalid;
/* All tests passed. */ /* All tests passed. */
return REDIS_OK; return C_OK;
invalid: invalid:
addReplySds(c, addReplySds(c,
sdsnew("-WRONGTYPE Key is not a valid " sdsnew("-WRONGTYPE Key is not a valid "
"HyperLogLog string value.\r\n")); "HyperLogLog string value.\r\n"));
return REDIS_ERR; return C_ERR;
} }
/* PFADD var ele ele ele ... ele => :0 or :1 */ /* PFADD var ele ele ele ... ele => :0 or :1 */
@ -1165,7 +1165,7 @@ void pfaddCommand(client *c) {
dbAdd(c->db,c->argv[1],o); dbAdd(c->db,c->argv[1],o);
updated++; updated++;
} else { } else {
if (isHLLObjectOrReply(c,o) != REDIS_OK) return; if (isHLLObjectOrReply(c,o) != C_OK) return;
o = dbUnshareStringValue(c->db,c->argv[1],o); o = dbUnshareStringValue(c->db,c->argv[1],o);
} }
/* Perform the low level ADD operation for every element. */ /* Perform the low level ADD operation for every element. */
@ -1214,11 +1214,11 @@ void pfcountCommand(client *c) {
/* Check type and size. */ /* Check type and size. */
robj *o = lookupKeyRead(c->db,c->argv[j]); robj *o = lookupKeyRead(c->db,c->argv[j]);
if (o == NULL) continue; /* Assume empty HLL for non existing var.*/ if (o == NULL) continue; /* Assume empty HLL for non existing var.*/
if (isHLLObjectOrReply(c,o) != REDIS_OK) return; if (isHLLObjectOrReply(c,o) != C_OK) return;
/* Merge with this HLL with our 'max' HHL by setting max[i] /* Merge with this HLL with our 'max' HHL by setting max[i]
* to MAX(max[i],hll[i]). */ * to MAX(max[i],hll[i]). */
if (hllMerge(registers,o) == REDIS_ERR) { if (hllMerge(registers,o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplySds(c,sdsnew(invalid_hll_err));
return; return;
} }
@ -1239,7 +1239,7 @@ void pfcountCommand(client *c) {
* we would have a key as HLLADD creates it as a side effect. */ * we would have a key as HLLADD creates it as a side effect. */
addReply(c,shared.czero); addReply(c,shared.czero);
} else { } else {
if (isHLLObjectOrReply(c,o) != REDIS_OK) return; if (isHLLObjectOrReply(c,o) != C_OK) return;
o = dbUnshareStringValue(c->db,c->argv[1],o); o = dbUnshareStringValue(c->db,c->argv[1],o);
/* Check if the cached cardinality is valid. */ /* Check if the cached cardinality is valid. */
@ -1295,11 +1295,11 @@ void pfmergeCommand(client *c) {
/* Check type and size. */ /* Check type and size. */
robj *o = lookupKeyRead(c->db,c->argv[j]); robj *o = lookupKeyRead(c->db,c->argv[j]);
if (o == NULL) continue; /* Assume empty HLL for non existing var. */ if (o == NULL) continue; /* Assume empty HLL for non existing var. */
if (isHLLObjectOrReply(c,o) != REDIS_OK) return; if (isHLLObjectOrReply(c,o) != C_OK) return;
/* Merge with this HLL with our 'max' HHL by setting max[i] /* Merge with this HLL with our 'max' HHL by setting max[i]
* to MAX(max[i],hll[i]). */ * to MAX(max[i],hll[i]). */
if (hllMerge(max,o) == REDIS_ERR) { if (hllMerge(max,o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplySds(c,sdsnew(invalid_hll_err));
return; return;
} }
@ -1321,7 +1321,7 @@ void pfmergeCommand(client *c) {
} }
/* Only support dense objects as destination. */ /* Only support dense objects as destination. */
if (hllSparseToDense(o) == REDIS_ERR) { if (hllSparseToDense(o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplySds(c,sdsnew(invalid_hll_err));
return; return;
} }
@ -1463,7 +1463,7 @@ void pfdebugCommand(client *c) {
addReplyError(c,"The specified key does not exist"); addReplyError(c,"The specified key does not exist");
return; return;
} }
if (isHLLObjectOrReply(c,o) != REDIS_OK) return; if (isHLLObjectOrReply(c,o) != C_OK) return;
o = dbUnshareStringValue(c->db,c->argv[2],o); o = dbUnshareStringValue(c->db,c->argv[2],o);
hdr = o->ptr; hdr = o->ptr;
@ -1472,7 +1472,7 @@ void pfdebugCommand(client *c) {
if (c->argc != 3) goto arityerr; if (c->argc != 3) goto arityerr;
if (hdr->encoding == HLL_SPARSE) { if (hdr->encoding == HLL_SPARSE) {
if (hllSparseToDense(o) == REDIS_ERR) { if (hllSparseToDense(o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplySds(c,sdsnew(invalid_hll_err));
return; return;
} }
@ -1536,7 +1536,7 @@ void pfdebugCommand(client *c) {
if (c->argc != 3) goto arityerr; if (c->argc != 3) goto arityerr;
if (hdr->encoding == HLL_SPARSE) { if (hdr->encoding == HLL_SPARSE) {
if (hllSparseToDense(o) == REDIS_ERR) { if (hllSparseToDense(o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplySds(c,sdsnew(invalid_hll_err));
return; return;
} }

View File

@ -132,14 +132,14 @@ client *createClient(int fd) {
* to the client. The behavior is the following: * to the client. The behavior is the following:
* *
* If the client should receive new data (normal clients will) the function * If the client should receive new data (normal clients will) the function
* returns REDIS_OK, and make sure to install the write handler in our event * returns C_OK, and make sure to install the write handler in our event
* loop so that when the socket is writable new data gets written. * loop so that when the socket is writable new data gets written.
* *
* If the client should not receive new data, because it is a fake client * If the client should not receive new data, because it is a fake client
* (used to load AOF in memory), a master or because the setup of the write * (used to load AOF in memory), a master or because the setup of the write
* handler failed, the function returns REDIS_ERR. * handler failed, the function returns C_ERR.
* *
* The function may return REDIS_OK without actually installing the write * The function may return C_OK without actually installing the write
* event handler in the following cases: * event handler in the following cases:
* *
* 1) The event handler should already be installed since the output buffer * 1) The event handler should already be installed since the output buffer
@ -148,19 +148,19 @@ client *createClient(int fd) {
* writes in the buffer but not actually sending them yet. * writes in the buffer but not actually sending them yet.
* *
* Typically gets called every time a reply is built, before adding more * Typically gets called every time a reply is built, before adding more
* data to the clients output buffers. If the function returns REDIS_ERR no * data to the clients output buffers. If the function returns C_ERR no
* data should be appended to the output buffers. */ * data should be appended to the output buffers. */
int prepareClientToWrite(client *c) { int prepareClientToWrite(client *c) {
/* If it's the Lua client we always return ok without installing any /* If it's the Lua client we always return ok without installing any
* handler since there is no socket at all. */ * handler since there is no socket at all. */
if (c->flags & REDIS_LUA_CLIENT) return REDIS_OK; if (c->flags & REDIS_LUA_CLIENT) return C_OK;
/* Masters don't receive replies, unless REDIS_MASTER_FORCE_REPLY flag /* Masters don't receive replies, unless REDIS_MASTER_FORCE_REPLY flag
* is set. */ * is set. */
if ((c->flags & REDIS_MASTER) && if ((c->flags & REDIS_MASTER) &&
!(c->flags & REDIS_MASTER_FORCE_REPLY)) return REDIS_ERR; !(c->flags & REDIS_MASTER_FORCE_REPLY)) return C_ERR;
if (c->fd <= 0) return REDIS_ERR; /* Fake client for AOF loading. */ if (c->fd <= 0) return C_ERR; /* Fake client for AOF loading. */
/* Only install the handler if not already installed and, in case of /* Only install the handler if not already installed and, in case of
* slaves, if the client can actually receive writes. */ * slaves, if the client can actually receive writes. */
@ -173,12 +173,12 @@ int prepareClientToWrite(client *c) {
sendReplyToClient, c) == AE_ERR) sendReplyToClient, c) == AE_ERR)
{ {
freeClientAsync(c); freeClientAsync(c);
return REDIS_ERR; return C_ERR;
} }
} }
/* Authorize the caller to queue in the output buffer of this client. */ /* Authorize the caller to queue in the output buffer of this client. */
return REDIS_OK; return C_OK;
} }
/* Create a duplicate of the last object in the reply list when /* Create a duplicate of the last object in the reply list when
@ -204,18 +204,18 @@ robj *dupLastObjectIfNeeded(list *reply) {
int _addReplyToBuffer(client *c, const char *s, size_t len) { int _addReplyToBuffer(client *c, const char *s, size_t len) {
size_t available = sizeof(c->buf)-c->bufpos; size_t available = sizeof(c->buf)-c->bufpos;
if (c->flags & REDIS_CLOSE_AFTER_REPLY) return REDIS_OK; if (c->flags & REDIS_CLOSE_AFTER_REPLY) return C_OK;
/* If there already are entries in the reply list, we cannot /* If there already are entries in the reply list, we cannot
* add anything more to the static buffer. */ * add anything more to the static buffer. */
if (listLength(c->reply) > 0) return REDIS_ERR; if (listLength(c->reply) > 0) return C_ERR;
/* Check that the buffer has enough space available for this string. */ /* Check that the buffer has enough space available for this string. */
if (len > available) return REDIS_ERR; if (len > available) return C_ERR;
memcpy(c->buf+c->bufpos,s,len); memcpy(c->buf+c->bufpos,s,len);
c->bufpos+=len; c->bufpos+=len;
return REDIS_OK; return C_OK;
} }
void _addReplyObjectToList(client *c, robj *o) { void _addReplyObjectToList(client *c, robj *o) {
@ -318,7 +318,7 @@ void _addReplyStringToList(client *c, const char *s, size_t len) {
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
void addReply(client *c, robj *obj) { void addReply(client *c, robj *obj) {
if (prepareClientToWrite(c) != REDIS_OK) return; if (prepareClientToWrite(c) != C_OK) return;
/* This is an important place where we can avoid copy-on-write /* This is an important place where we can avoid copy-on-write
* when there is a saving child running, avoiding touching the * when there is a saving child running, avoiding touching the
@ -328,7 +328,7 @@ void addReply(client *c, robj *obj) {
* we'll be able to send the object to the client without * we'll be able to send the object to the client without
* messing with its page. */ * messing with its page. */
if (sdsEncodedObject(obj)) { if (sdsEncodedObject(obj)) {
if (_addReplyToBuffer(c,obj->ptr,sdslen(obj->ptr)) != REDIS_OK) if (_addReplyToBuffer(c,obj->ptr,sdslen(obj->ptr)) != C_OK)
_addReplyObjectToList(c,obj); _addReplyObjectToList(c,obj);
} else if (obj->encoding == OBJ_ENCODING_INT) { } else if (obj->encoding == OBJ_ENCODING_INT) {
/* Optimization: if there is room in the static buffer for 32 bytes /* Optimization: if there is room in the static buffer for 32 bytes
@ -339,13 +339,13 @@ void addReply(client *c, robj *obj) {
int len; int len;
len = ll2string(buf,sizeof(buf),(long)obj->ptr); len = ll2string(buf,sizeof(buf),(long)obj->ptr);
if (_addReplyToBuffer(c,buf,len) == REDIS_OK) if (_addReplyToBuffer(c,buf,len) == C_OK)
return; return;
/* else... continue with the normal code path, but should never /* else... continue with the normal code path, but should never
* happen actually since we verified there is room. */ * happen actually since we verified there is room. */
} }
obj = getDecodedObject(obj); obj = getDecodedObject(obj);
if (_addReplyToBuffer(c,obj->ptr,sdslen(obj->ptr)) != REDIS_OK) if (_addReplyToBuffer(c,obj->ptr,sdslen(obj->ptr)) != C_OK)
_addReplyObjectToList(c,obj); _addReplyObjectToList(c,obj);
decrRefCount(obj); decrRefCount(obj);
} else { } else {
@ -354,12 +354,12 @@ void addReply(client *c, robj *obj) {
} }
void addReplySds(client *c, sds s) { void addReplySds(client *c, sds s) {
if (prepareClientToWrite(c) != REDIS_OK) { if (prepareClientToWrite(c) != C_OK) {
/* The caller expects the sds to be free'd. */ /* The caller expects the sds to be free'd. */
sdsfree(s); sdsfree(s);
return; return;
} }
if (_addReplyToBuffer(c,s,sdslen(s)) == REDIS_OK) { if (_addReplyToBuffer(c,s,sdslen(s)) == C_OK) {
sdsfree(s); sdsfree(s);
} else { } else {
/* This method free's the sds when it is no longer needed. */ /* This method free's the sds when it is no longer needed. */
@ -368,8 +368,8 @@ void addReplySds(client *c, sds s) {
} }
void addReplyString(client *c, const char *s, size_t len) { void addReplyString(client *c, const char *s, size_t len) {
if (prepareClientToWrite(c) != REDIS_OK) return; if (prepareClientToWrite(c) != C_OK) return;
if (_addReplyToBuffer(c,s,len) != REDIS_OK) if (_addReplyToBuffer(c,s,len) != C_OK)
_addReplyStringToList(c,s,len); _addReplyStringToList(c,s,len);
} }
@ -424,7 +424,7 @@ void *addDeferredMultiBulkLength(client *c) {
/* Note that we install the write event here even if the object is not /* Note that we install the write event here even if the object is not
* ready to be sent, since we are sure that before returning to the * ready to be sent, since we are sure that before returning to the
* event loop setDeferredMultiBulkLength() will be called. */ * event loop setDeferredMultiBulkLength() will be called. */
if (prepareClientToWrite(c) != REDIS_OK) return NULL; if (prepareClientToWrite(c) != C_OK) return NULL;
listAddNodeTail(c->reply,createObject(OBJ_STRING,NULL)); listAddNodeTail(c->reply,createObject(OBJ_STRING,NULL));
return listLast(c->reply); return listLast(c->reply);
} }
@ -934,7 +934,7 @@ int processInlineBuffer(client *c) {
addReplyError(c,"Protocol error: too big inline request"); addReplyError(c,"Protocol error: too big inline request");
setProtocolError(c,0); setProtocolError(c,0);
} }
return REDIS_ERR; return C_ERR;
} }
/* Handle the \r\n case. */ /* Handle the \r\n case. */
@ -949,7 +949,7 @@ int processInlineBuffer(client *c) {
if (argv == NULL) { if (argv == NULL) {
addReplyError(c,"Protocol error: unbalanced quotes in request"); addReplyError(c,"Protocol error: unbalanced quotes in request");
setProtocolError(c,0); setProtocolError(c,0);
return REDIS_ERR; return C_ERR;
} }
/* Newline from slaves can be used to refresh the last ACK time. /* Newline from slaves can be used to refresh the last ACK time.
@ -977,7 +977,7 @@ int processInlineBuffer(client *c) {
} }
} }
zfree(argv); zfree(argv);
return REDIS_OK; return C_OK;
} }
/* Helper function. Trims query buffer to make the function that processes /* Helper function. Trims query buffer to make the function that processes
@ -1009,12 +1009,12 @@ int processMultibulkBuffer(client *c) {
addReplyError(c,"Protocol error: too big mbulk count string"); addReplyError(c,"Protocol error: too big mbulk count string");
setProtocolError(c,0); setProtocolError(c,0);
} }
return REDIS_ERR; return C_ERR;
} }
/* Buffer should also contain \n */ /* Buffer should also contain \n */
if (newline-(c->querybuf) > ((signed)sdslen(c->querybuf)-2)) if (newline-(c->querybuf) > ((signed)sdslen(c->querybuf)-2))
return REDIS_ERR; return C_ERR;
/* We know for sure there is a whole line since newline != NULL, /* We know for sure there is a whole line since newline != NULL,
* so go ahead and find out the multi bulk length. */ * so go ahead and find out the multi bulk length. */
@ -1023,13 +1023,13 @@ int processMultibulkBuffer(client *c) {
if (!ok || ll > 1024*1024) { if (!ok || ll > 1024*1024) {
addReplyError(c,"Protocol error: invalid multibulk length"); addReplyError(c,"Protocol error: invalid multibulk length");
setProtocolError(c,pos); setProtocolError(c,pos);
return REDIS_ERR; return C_ERR;
} }
pos = (newline-c->querybuf)+2; pos = (newline-c->querybuf)+2;
if (ll <= 0) { if (ll <= 0) {
sdsrange(c->querybuf,pos,-1); sdsrange(c->querybuf,pos,-1);
return REDIS_OK; return C_OK;
} }
c->multibulklen = ll; c->multibulklen = ll;
@ -1049,7 +1049,7 @@ int processMultibulkBuffer(client *c) {
addReplyError(c, addReplyError(c,
"Protocol error: too big bulk count string"); "Protocol error: too big bulk count string");
setProtocolError(c,0); setProtocolError(c,0);
return REDIS_ERR; return C_ERR;
} }
break; break;
} }
@ -1063,14 +1063,14 @@ int processMultibulkBuffer(client *c) {
"Protocol error: expected '$', got '%c'", "Protocol error: expected '$', got '%c'",
c->querybuf[pos]); c->querybuf[pos]);
setProtocolError(c,pos); setProtocolError(c,pos);
return REDIS_ERR; return C_ERR;
} }
ok = string2ll(c->querybuf+pos+1,newline-(c->querybuf+pos+1),&ll); ok = string2ll(c->querybuf+pos+1,newline-(c->querybuf+pos+1),&ll);
if (!ok || ll < 0 || ll > 512*1024*1024) { if (!ok || ll < 0 || ll > 512*1024*1024) {
addReplyError(c,"Protocol error: invalid bulk length"); addReplyError(c,"Protocol error: invalid bulk length");
setProtocolError(c,pos); setProtocolError(c,pos);
return REDIS_ERR; return C_ERR;
} }
pos += newline-(c->querybuf+pos)+2; pos += newline-(c->querybuf+pos)+2;
@ -1125,10 +1125,10 @@ int processMultibulkBuffer(client *c) {
if (pos) sdsrange(c->querybuf,pos,-1); if (pos) sdsrange(c->querybuf,pos,-1);
/* We're done when c->multibulk == 0 */ /* We're done when c->multibulk == 0 */
if (c->multibulklen == 0) return REDIS_OK; if (c->multibulklen == 0) return C_OK;
/* Still not read to process the command */ /* Still not read to process the command */
return REDIS_ERR; return C_ERR;
} }
void processInputBuffer(client *c) { void processInputBuffer(client *c) {
@ -1156,9 +1156,9 @@ void processInputBuffer(client *c) {
} }
if (c->reqtype == REDIS_REQ_INLINE) { if (c->reqtype == REDIS_REQ_INLINE) {
if (processInlineBuffer(c) != REDIS_OK) break; if (processInlineBuffer(c) != C_OK) break;
} else if (c->reqtype == REDIS_REQ_MULTIBULK) { } else if (c->reqtype == REDIS_REQ_MULTIBULK) {
if (processMultibulkBuffer(c) != REDIS_OK) break; if (processMultibulkBuffer(c) != C_OK) break;
} else { } else {
redisPanic("Unknown request type"); redisPanic("Unknown request type");
} }
@ -1168,7 +1168,7 @@ void processInputBuffer(client *c) {
resetClient(c); resetClient(c);
} else { } else {
/* Only reset the client when the command was executed. */ /* Only reset the client when the command was executed. */
if (processCommand(c) == REDIS_OK) if (processCommand(c) == C_OK)
resetClient(c); resetClient(c);
} }
} }
@ -1388,7 +1388,7 @@ void clientCommand(client *c) {
long long tmp; long long tmp;
if (getLongLongFromObjectOrReply(c,c->argv[i+1],&tmp,NULL) if (getLongLongFromObjectOrReply(c,c->argv[i+1],&tmp,NULL)
!= REDIS_OK) return; != C_OK) return;
id = tmp; id = tmp;
} else if (!strcasecmp(c->argv[i]->ptr,"type") && moreargs) { } else if (!strcasecmp(c->argv[i]->ptr,"type") && moreargs) {
type = getClientTypeByName(c->argv[i+1]->ptr); type = getClientTypeByName(c->argv[i+1]->ptr);
@ -1489,7 +1489,7 @@ void clientCommand(client *c) {
long long duration; long long duration;
if (getTimeoutFromObjectOrReply(c,c->argv[2],&duration,UNIT_MILLISECONDS) if (getTimeoutFromObjectOrReply(c,c->argv[2],&duration,UNIT_MILLISECONDS)
!= REDIS_OK) return; != C_OK) return;
pauseClients(duration); pauseClients(duration);
addReply(c,shared.ok); addReply(c,shared.ok);
} else { } else {

View File

@ -351,9 +351,9 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING); serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
if (o->encoding == OBJ_ENCODING_INT) { if (o->encoding == OBJ_ENCODING_INT) {
if (llval) *llval = (long) o->ptr; if (llval) *llval = (long) o->ptr;
return REDIS_OK; return C_OK;
} else { } else {
return string2ll(o->ptr,sdslen(o->ptr),llval) ? REDIS_OK : REDIS_ERR; return string2ll(o->ptr,sdslen(o->ptr),llval) ? C_OK : C_ERR;
} }
} }
@ -551,7 +551,7 @@ int getDoubleFromObject(robj *o, double *target) {
(value == HUGE_VAL || value == -HUGE_VAL || value == 0)) || (value == HUGE_VAL || value == -HUGE_VAL || value == 0)) ||
errno == EINVAL || errno == EINVAL ||
isnan(value)) isnan(value))
return REDIS_ERR; return C_ERR;
} else if (o->encoding == OBJ_ENCODING_INT) { } else if (o->encoding == OBJ_ENCODING_INT) {
value = (long)o->ptr; value = (long)o->ptr;
} else { } else {
@ -559,21 +559,21 @@ int getDoubleFromObject(robj *o, double *target) {
} }
} }
*target = value; *target = value;
return REDIS_OK; return C_OK;
} }
int getDoubleFromObjectOrReply(client *c, robj *o, double *target, const char *msg) { int getDoubleFromObjectOrReply(client *c, robj *o, double *target, const char *msg) {
double value; double value;
if (getDoubleFromObject(o, &value) != REDIS_OK) { if (getDoubleFromObject(o, &value) != C_OK) {
if (msg != NULL) { if (msg != NULL) {
addReplyError(c,(char*)msg); addReplyError(c,(char*)msg);
} else { } else {
addReplyError(c,"value is not a valid float"); addReplyError(c,"value is not a valid float");
} }
return REDIS_ERR; return C_ERR;
} }
*target = value; *target = value;
return REDIS_OK; return C_OK;
} }
int getLongDoubleFromObject(robj *o, long double *target) { int getLongDoubleFromObject(robj *o, long double *target) {
@ -589,7 +589,7 @@ int getLongDoubleFromObject(robj *o, long double *target) {
value = strtold(o->ptr, &eptr); value = strtold(o->ptr, &eptr);
if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
errno == ERANGE || isnan(value)) errno == ERANGE || isnan(value))
return REDIS_ERR; return C_ERR;
} else if (o->encoding == OBJ_ENCODING_INT) { } else if (o->encoding == OBJ_ENCODING_INT) {
value = (long)o->ptr; value = (long)o->ptr;
} else { } else {
@ -597,21 +597,21 @@ int getLongDoubleFromObject(robj *o, long double *target) {
} }
} }
*target = value; *target = value;
return REDIS_OK; return C_OK;
} }
int getLongDoubleFromObjectOrReply(client *c, robj *o, long double *target, const char *msg) { int getLongDoubleFromObjectOrReply(client *c, robj *o, long double *target, const char *msg) {
long double value; long double value;
if (getLongDoubleFromObject(o, &value) != REDIS_OK) { if (getLongDoubleFromObject(o, &value) != C_OK) {
if (msg != NULL) { if (msg != NULL) {
addReplyError(c,(char*)msg); addReplyError(c,(char*)msg);
} else { } else {
addReplyError(c,"value is not a valid float"); addReplyError(c,"value is not a valid float");
} }
return REDIS_ERR; return C_ERR;
} }
*target = value; *target = value;
return REDIS_OK; return C_OK;
} }
int getLongLongFromObject(robj *o, long long *target) { int getLongLongFromObject(robj *o, long long *target) {
@ -627,7 +627,7 @@ int getLongLongFromObject(robj *o, long long *target) {
value = strtoll(o->ptr, &eptr, 10); value = strtoll(o->ptr, &eptr, 10);
if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
errno == ERANGE) errno == ERANGE)
return REDIS_ERR; return C_ERR;
} else if (o->encoding == OBJ_ENCODING_INT) { } else if (o->encoding == OBJ_ENCODING_INT) {
value = (long)o->ptr; value = (long)o->ptr;
} else { } else {
@ -635,37 +635,37 @@ int getLongLongFromObject(robj *o, long long *target) {
} }
} }
if (target) *target = value; if (target) *target = value;
return REDIS_OK; return C_OK;
} }
int getLongLongFromObjectOrReply(client *c, robj *o, long long *target, const char *msg) { int getLongLongFromObjectOrReply(client *c, robj *o, long long *target, const char *msg) {
long long value; long long value;
if (getLongLongFromObject(o, &value) != REDIS_OK) { if (getLongLongFromObject(o, &value) != C_OK) {
if (msg != NULL) { if (msg != NULL) {
addReplyError(c,(char*)msg); addReplyError(c,(char*)msg);
} else { } else {
addReplyError(c,"value is not an integer or out of range"); addReplyError(c,"value is not an integer or out of range");
} }
return REDIS_ERR; return C_ERR;
} }
*target = value; *target = value;
return REDIS_OK; return C_OK;
} }
int getLongFromObjectOrReply(client *c, robj *o, long *target, const char *msg) { int getLongFromObjectOrReply(client *c, robj *o, long *target, const char *msg) {
long long value; long long value;
if (getLongLongFromObjectOrReply(c, o, &value, msg) != REDIS_OK) return REDIS_ERR; if (getLongLongFromObjectOrReply(c, o, &value, msg) != C_OK) return C_ERR;
if (value < LONG_MIN || value > LONG_MAX) { if (value < LONG_MIN || value > LONG_MAX) {
if (msg != NULL) { if (msg != NULL) {
addReplyError(c,(char*)msg); addReplyError(c,(char*)msg);
} else { } else {
addReplyError(c,"value is out of range"); addReplyError(c,"value is out of range");
} }
return REDIS_ERR; return C_ERR;
} }
*target = value; *target = value;
return REDIS_OK; return C_OK;
} }
char *strEncoding(int encoding) { char *strEncoding(int encoding) {

View File

@ -726,11 +726,11 @@ int rdbSaveInfoAuxFields(rio *rdb) {
} }
/* Produces a dump of the database in RDB format sending it to the specified /* Produces a dump of the database in RDB format sending it to the specified
* Redis I/O channel. On success REDIS_OK is returned, otherwise REDIS_ERR * Redis I/O channel. On success C_OK is returned, otherwise C_ERR
* is returned and part of the output, or all the output, can be * is returned and part of the output, or all the output, can be
* missing because of I/O errors. * missing because of I/O errors.
* *
* When the function returns REDIS_ERR and if 'error' is not NULL, the * When the function returns C_ERR and if 'error' is not NULL, the
* integer pointed by 'error' is set to the value of errno just after the I/O * integer pointed by 'error' is set to the value of errno just after the I/O
* error. */ * error. */
int rdbSaveRio(rio *rdb, int *error) { int rdbSaveRio(rio *rdb, int *error) {
@ -752,7 +752,7 @@ int rdbSaveRio(rio *rdb, int *error) {
dict *d = db->dict; dict *d = db->dict;
if (dictSize(d) == 0) continue; if (dictSize(d) == 0) continue;
di = dictGetSafeIterator(d); di = dictGetSafeIterator(d);
if (!di) return REDIS_ERR; if (!di) return C_ERR;
/* Write the SELECT DB opcode */ /* Write the SELECT DB opcode */
if (rdbSaveType(rdb,REDIS_RDB_OPCODE_SELECTDB) == -1) goto werr; if (rdbSaveType(rdb,REDIS_RDB_OPCODE_SELECTDB) == -1) goto werr;
@ -795,12 +795,12 @@ int rdbSaveRio(rio *rdb, int *error) {
cksum = rdb->cksum; cksum = rdb->cksum;
memrev64ifbe(&cksum); memrev64ifbe(&cksum);
if (rioWrite(rdb,&cksum,8) == 0) goto werr; if (rioWrite(rdb,&cksum,8) == 0) goto werr;
return REDIS_OK; return C_OK;
werr: werr:
if (error) *error = errno; if (error) *error = errno;
if (di) dictReleaseIterator(di); if (di) dictReleaseIterator(di);
return REDIS_ERR; return C_ERR;
} }
/* This is just a wrapper to rdbSaveRio() that additionally adds a prefix /* This is just a wrapper to rdbSaveRio() that additionally adds a prefix
@ -819,17 +819,17 @@ int rdbSaveRioWithEOFMark(rio *rdb, int *error) {
if (rioWrite(rdb,"$EOF:",5) == 0) goto werr; if (rioWrite(rdb,"$EOF:",5) == 0) goto werr;
if (rioWrite(rdb,eofmark,REDIS_EOF_MARK_SIZE) == 0) goto werr; if (rioWrite(rdb,eofmark,REDIS_EOF_MARK_SIZE) == 0) goto werr;
if (rioWrite(rdb,"\r\n",2) == 0) goto werr; if (rioWrite(rdb,"\r\n",2) == 0) goto werr;
if (rdbSaveRio(rdb,error) == REDIS_ERR) goto werr; if (rdbSaveRio(rdb,error) == C_ERR) goto werr;
if (rioWrite(rdb,eofmark,REDIS_EOF_MARK_SIZE) == 0) goto werr; if (rioWrite(rdb,eofmark,REDIS_EOF_MARK_SIZE) == 0) goto werr;
return REDIS_OK; return C_OK;
werr: /* Write error. */ werr: /* Write error. */
/* Set 'error' only if not already set by rdbSaveRio() call. */ /* Set 'error' only if not already set by rdbSaveRio() call. */
if (error && *error == 0) *error = errno; if (error && *error == 0) *error = errno;
return REDIS_ERR; return C_ERR;
} }
/* Save the DB on disk. Return REDIS_ERR on error, REDIS_OK on success. */ /* Save the DB on disk. Return C_ERR on error, C_OK on success. */
int rdbSave(char *filename) { int rdbSave(char *filename) {
char tmpfile[256]; char tmpfile[256];
FILE *fp; FILE *fp;
@ -841,11 +841,11 @@ int rdbSave(char *filename) {
if (!fp) { if (!fp) {
serverLog(REDIS_WARNING, "Failed opening .rdb for saving: %s", serverLog(REDIS_WARNING, "Failed opening .rdb for saving: %s",
strerror(errno)); strerror(errno));
return REDIS_ERR; return C_ERR;
} }
rioInitWithFile(&rdb,fp); rioInitWithFile(&rdb,fp);
if (rdbSaveRio(&rdb,&error) == REDIS_ERR) { if (rdbSaveRio(&rdb,&error) == C_ERR) {
errno = error; errno = error;
goto werr; goto werr;
} }
@ -860,26 +860,26 @@ int rdbSave(char *filename) {
if (rename(tmpfile,filename) == -1) { if (rename(tmpfile,filename) == -1) {
serverLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno)); serverLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno));
unlink(tmpfile); unlink(tmpfile);
return REDIS_ERR; return C_ERR;
} }
serverLog(REDIS_NOTICE,"DB saved on disk"); serverLog(REDIS_NOTICE,"DB saved on disk");
server.dirty = 0; server.dirty = 0;
server.lastsave = time(NULL); server.lastsave = time(NULL);
server.lastbgsave_status = REDIS_OK; server.lastbgsave_status = C_OK;
return REDIS_OK; return C_OK;
werr: werr:
serverLog(REDIS_WARNING,"Write error saving DB on disk: %s", strerror(errno)); serverLog(REDIS_WARNING,"Write error saving DB on disk: %s", strerror(errno));
fclose(fp); fclose(fp);
unlink(tmpfile); unlink(tmpfile);
return REDIS_ERR; return C_ERR;
} }
int rdbSaveBackground(char *filename) { int rdbSaveBackground(char *filename) {
pid_t childpid; pid_t childpid;
long long start; long long start;
if (server.rdb_child_pid != -1) return REDIS_ERR; if (server.rdb_child_pid != -1) return C_ERR;
server.dirty_before_bgsave = server.dirty; server.dirty_before_bgsave = server.dirty;
server.lastbgsave_try = time(NULL); server.lastbgsave_try = time(NULL);
@ -892,7 +892,7 @@ int rdbSaveBackground(char *filename) {
closeListeningSockets(0); closeListeningSockets(0);
redisSetProcTitle("redis-rdb-bgsave"); redisSetProcTitle("redis-rdb-bgsave");
retval = rdbSave(filename); retval = rdbSave(filename);
if (retval == REDIS_OK) { if (retval == C_OK) {
size_t private_dirty = zmalloc_get_private_dirty(); size_t private_dirty = zmalloc_get_private_dirty();
if (private_dirty) { if (private_dirty) {
@ -901,26 +901,26 @@ int rdbSaveBackground(char *filename) {
private_dirty/(1024*1024)); private_dirty/(1024*1024));
} }
} }
exitFromChild((retval == REDIS_OK) ? 0 : 1); exitFromChild((retval == C_OK) ? 0 : 1);
} else { } else {
/* Parent */ /* Parent */
server.stat_fork_time = ustime()-start; server.stat_fork_time = ustime()-start;
server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */ server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000); latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
if (childpid == -1) { if (childpid == -1) {
server.lastbgsave_status = REDIS_ERR; server.lastbgsave_status = C_ERR;
serverLog(REDIS_WARNING,"Can't save in background: fork: %s", serverLog(REDIS_WARNING,"Can't save in background: fork: %s",
strerror(errno)); strerror(errno));
return REDIS_ERR; return C_ERR;
} }
serverLog(REDIS_NOTICE,"Background saving started by pid %d",childpid); serverLog(REDIS_NOTICE,"Background saving started by pid %d",childpid);
server.rdb_save_time_start = time(NULL); server.rdb_save_time_start = time(NULL);
server.rdb_child_pid = childpid; server.rdb_child_pid = childpid;
server.rdb_child_type = REDIS_RDB_CHILD_TYPE_DISK; server.rdb_child_type = REDIS_RDB_CHILD_TYPE_DISK;
updateDictResizePolicy(); updateDictResizePolicy();
return REDIS_OK; return C_OK;
} }
return REDIS_OK; /* unreached */ return C_OK; /* unreached */
} }
void rdbRemoveTempFile(pid_t childpid) { void rdbRemoveTempFile(pid_t childpid) {
@ -981,7 +981,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) {
if (o->encoding == OBJ_ENCODING_INTSET) { if (o->encoding == OBJ_ENCODING_INTSET) {
/* Fetch integer value from element */ /* Fetch integer value from element */
if (isObjectRepresentableAsLongLong(ele,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(ele,&llval) == C_OK) {
o->ptr = intsetAdd(o->ptr,llval,NULL); o->ptr = intsetAdd(o->ptr,llval,NULL);
} else { } else {
setTypeConvert(o,OBJ_ENCODING_HT); setTypeConvert(o,OBJ_ENCODING_HT);
@ -1241,7 +1241,7 @@ int rdbLoad(char *filename) {
FILE *fp; FILE *fp;
rio rdb; rio rdb;
if ((fp = fopen(filename,"r")) == NULL) return REDIS_ERR; if ((fp = fopen(filename,"r")) == NULL) return C_ERR;
rioInitWithFile(&rdb,fp); rioInitWithFile(&rdb,fp);
rdb.update_cksum = rdbLoadProgressCallback; rdb.update_cksum = rdbLoadProgressCallback;
@ -1252,14 +1252,14 @@ int rdbLoad(char *filename) {
fclose(fp); fclose(fp);
serverLog(REDIS_WARNING,"Wrong signature trying to load DB from file"); serverLog(REDIS_WARNING,"Wrong signature trying to load DB from file");
errno = EINVAL; errno = EINVAL;
return REDIS_ERR; return C_ERR;
} }
rdbver = atoi(buf+5); rdbver = atoi(buf+5);
if (rdbver < 1 || rdbver > REDIS_RDB_VERSION) { if (rdbver < 1 || rdbver > REDIS_RDB_VERSION) {
fclose(fp); fclose(fp);
serverLog(REDIS_WARNING,"Can't handle RDB format version %d",rdbver); serverLog(REDIS_WARNING,"Can't handle RDB format version %d",rdbver);
errno = EINVAL; errno = EINVAL;
return REDIS_ERR; return C_ERR;
} }
startLoading(fp); startLoading(fp);
@ -1381,12 +1381,12 @@ int rdbLoad(char *filename) {
fclose(fp); fclose(fp);
stopLoading(); stopLoading();
return REDIS_OK; return C_OK;
eoferr: /* unexpected end of file is handled here with a fatal exit */ eoferr: /* unexpected end of file is handled here with a fatal exit */
serverLog(REDIS_WARNING,"Short read or OOM loading DB. Unrecoverable error, aborting now."); serverLog(REDIS_WARNING,"Short read or OOM loading DB. Unrecoverable error, aborting now.");
rdbExitReportCorruptRDB("Unexpected EOF reading RDB file"); rdbExitReportCorruptRDB("Unexpected EOF reading RDB file");
return REDIS_ERR; /* Just to avoid warning */ return C_ERR; /* Just to avoid warning */
} }
/* A background saving child (BGSAVE) terminated its work. Handle this. /* A background saving child (BGSAVE) terminated its work. Handle this.
@ -1397,10 +1397,10 @@ void backgroundSaveDoneHandlerDisk(int exitcode, int bysignal) {
"Background saving terminated with success"); "Background saving terminated with success");
server.dirty = server.dirty - server.dirty_before_bgsave; server.dirty = server.dirty - server.dirty_before_bgsave;
server.lastsave = time(NULL); server.lastsave = time(NULL);
server.lastbgsave_status = REDIS_OK; server.lastbgsave_status = C_OK;
} else if (!bysignal && exitcode != 0) { } else if (!bysignal && exitcode != 0) {
serverLog(REDIS_WARNING, "Background saving error"); serverLog(REDIS_WARNING, "Background saving error");
server.lastbgsave_status = REDIS_ERR; server.lastbgsave_status = C_ERR;
} else { } else {
mstime_t latency; mstime_t latency;
@ -1413,7 +1413,7 @@ void backgroundSaveDoneHandlerDisk(int exitcode, int bysignal) {
/* SIGUSR1 is whitelisted, so we have a way to kill a child without /* SIGUSR1 is whitelisted, so we have a way to kill a child without
* tirggering an error conditon. */ * tirggering an error conditon. */
if (bysignal != SIGUSR1) if (bysignal != SIGUSR1)
server.lastbgsave_status = REDIS_ERR; server.lastbgsave_status = C_ERR;
} }
server.rdb_child_pid = -1; server.rdb_child_pid = -1;
server.rdb_child_type = REDIS_RDB_CHILD_TYPE_NONE; server.rdb_child_type = REDIS_RDB_CHILD_TYPE_NONE;
@ -1421,7 +1421,7 @@ void backgroundSaveDoneHandlerDisk(int exitcode, int bysignal) {
server.rdb_save_time_start = -1; server.rdb_save_time_start = -1;
/* Possibly there are slaves waiting for a BGSAVE in order to be served /* Possibly there are slaves waiting for a BGSAVE in order to be served
* (the first stage of SYNC is a bulk transfer of dump.rdb) */ * (the first stage of SYNC is a bulk transfer of dump.rdb) */
updateSlavesWaitingBgsave((!bysignal && exitcode == 0) ? REDIS_OK : REDIS_ERR, REDIS_RDB_CHILD_TYPE_DISK); updateSlavesWaitingBgsave((!bysignal && exitcode == 0) ? C_OK : C_ERR, REDIS_RDB_CHILD_TYPE_DISK);
} }
/* A background saving child (BGSAVE) terminated its work. Handle this. /* A background saving child (BGSAVE) terminated its work. Handle this.
@ -1516,7 +1516,7 @@ void backgroundSaveDoneHandlerSocket(int exitcode, int bysignal) {
} }
zfree(ok_slaves); zfree(ok_slaves);
updateSlavesWaitingBgsave((!bysignal && exitcode == 0) ? REDIS_OK : REDIS_ERR, REDIS_RDB_CHILD_TYPE_SOCKET); updateSlavesWaitingBgsave((!bysignal && exitcode == 0) ? C_OK : C_ERR, REDIS_RDB_CHILD_TYPE_SOCKET);
} }
/* When a background RDB saving/transfer terminates, call the right handler. */ /* When a background RDB saving/transfer terminates, call the right handler. */
@ -1546,12 +1546,12 @@ int rdbSaveToSlavesSockets(void) {
long long start; long long start;
int pipefds[2]; int pipefds[2];
if (server.rdb_child_pid != -1) return REDIS_ERR; if (server.rdb_child_pid != -1) return C_ERR;
/* Before to fork, create a pipe that will be used in order to /* Before to fork, create a pipe that will be used in order to
* send back to the parent the IDs of the slaves that successfully * send back to the parent the IDs of the slaves that successfully
* received all the writes. */ * received all the writes. */
if (pipe(pipefds) == -1) return REDIS_ERR; if (pipe(pipefds) == -1) return C_ERR;
server.rdb_pipe_read_result_from_child = pipefds[0]; server.rdb_pipe_read_result_from_child = pipefds[0];
server.rdb_pipe_write_result_to_parent = pipefds[1]; server.rdb_pipe_write_result_to_parent = pipefds[1];
@ -1594,10 +1594,10 @@ int rdbSaveToSlavesSockets(void) {
redisSetProcTitle("redis-rdb-to-slaves"); redisSetProcTitle("redis-rdb-to-slaves");
retval = rdbSaveRioWithEOFMark(&slave_sockets,NULL); retval = rdbSaveRioWithEOFMark(&slave_sockets,NULL);
if (retval == REDIS_OK && rioFlush(&slave_sockets) == 0) if (retval == C_OK && rioFlush(&slave_sockets) == 0)
retval = REDIS_ERR; retval = C_ERR;
if (retval == REDIS_OK) { if (retval == C_OK) {
size_t private_dirty = zmalloc_get_private_dirty(); size_t private_dirty = zmalloc_get_private_dirty();
if (private_dirty) { if (private_dirty) {
@ -1641,12 +1641,12 @@ int rdbSaveToSlavesSockets(void) {
write(server.rdb_pipe_write_result_to_parent,msg,msglen) write(server.rdb_pipe_write_result_to_parent,msg,msglen)
!= msglen) != msglen)
{ {
retval = REDIS_ERR; retval = C_ERR;
} }
zfree(msg); zfree(msg);
} }
zfree(clientids); zfree(clientids);
exitFromChild((retval == REDIS_OK) ? 0 : 1); exitFromChild((retval == C_OK) ? 0 : 1);
} else { } else {
/* Parent */ /* Parent */
zfree(clientids); /* Not used by parent. Free ASAP. */ zfree(clientids); /* Not used by parent. Free ASAP. */
@ -1659,7 +1659,7 @@ int rdbSaveToSlavesSockets(void) {
zfree(fds); zfree(fds);
close(pipefds[0]); close(pipefds[0]);
close(pipefds[1]); close(pipefds[1]);
return REDIS_ERR; return C_ERR;
} }
serverLog(REDIS_NOTICE,"Background RDB transfer started by pid %d",childpid); serverLog(REDIS_NOTICE,"Background RDB transfer started by pid %d",childpid);
server.rdb_save_time_start = time(NULL); server.rdb_save_time_start = time(NULL);
@ -1667,9 +1667,9 @@ int rdbSaveToSlavesSockets(void) {
server.rdb_child_type = REDIS_RDB_CHILD_TYPE_SOCKET; server.rdb_child_type = REDIS_RDB_CHILD_TYPE_SOCKET;
updateDictResizePolicy(); updateDictResizePolicy();
zfree(fds); zfree(fds);
return REDIS_OK; return C_OK;
} }
return REDIS_OK; /* unreached */ return C_OK; /* unreached */
} }
void saveCommand(client *c) { void saveCommand(client *c) {
@ -1677,7 +1677,7 @@ void saveCommand(client *c) {
addReplyError(c,"Background save already in progress"); addReplyError(c,"Background save already in progress");
return; return;
} }
if (rdbSave(server.rdb_filename) == REDIS_OK) { if (rdbSave(server.rdb_filename) == C_OK) {
addReply(c,shared.ok); addReply(c,shared.ok);
} else { } else {
addReply(c,shared.err); addReply(c,shared.err);
@ -1689,7 +1689,7 @@ void bgsaveCommand(client *c) {
addReplyError(c,"Background save already in progress"); addReplyError(c,"Background save already in progress");
} else if (server.aof_child_pid != -1) { } else if (server.aof_child_pid != -1) {
addReplyError(c,"Can't BGSAVE while AOF log rewriting is in progress"); addReplyError(c,"Can't BGSAVE while AOF log rewriting is in progress");
} else if (rdbSaveBackground(server.rdb_filename) == REDIS_OK) { } else if (rdbSaveBackground(server.rdb_filename) == C_OK) {
addReplyStatus(c,"Background saving started"); addReplyStatus(c,"Background saving started");
} else { } else {
addReply(c,shared.err); addReply(c,shared.err);

View File

@ -352,7 +352,7 @@ long long addReplyReplicationBacklog(client *c, long long offset) {
/* This function handles the PSYNC command from the point of view of a /* This function handles the PSYNC command from the point of view of a
* master receiving a request for partial resynchronization. * master receiving a request for partial resynchronization.
* *
* On success return REDIS_OK, otherwise REDIS_ERR is returned and we proceed * On success return C_OK, otherwise C_ERR is returned and we proceed
* with the usual full resync. */ * with the usual full resync. */
int masterTryPartialResynchronization(client *c) { int masterTryPartialResynchronization(client *c) {
long long psync_offset, psync_len; long long psync_offset, psync_len;
@ -378,7 +378,7 @@ int masterTryPartialResynchronization(client *c) {
/* We still have the data our slave is asking for? */ /* We still have the data our slave is asking for? */
if (getLongLongFromObjectOrReply(c,c->argv[2],&psync_offset,NULL) != if (getLongLongFromObjectOrReply(c,c->argv[2],&psync_offset,NULL) !=
REDIS_OK) goto need_full_resync; C_OK) goto need_full_resync;
if (!server.repl_backlog || if (!server.repl_backlog ||
psync_offset < server.repl_backlog_off || psync_offset < server.repl_backlog_off ||
psync_offset > (server.repl_backlog_off + server.repl_backlog_histlen)) psync_offset > (server.repl_backlog_off + server.repl_backlog_histlen))
@ -407,7 +407,7 @@ int masterTryPartialResynchronization(client *c) {
buflen = snprintf(buf,sizeof(buf),"+CONTINUE\r\n"); buflen = snprintf(buf,sizeof(buf),"+CONTINUE\r\n");
if (write(c->fd,buf,buflen) != buflen) { if (write(c->fd,buf,buflen) != buflen) {
freeClientAsync(c); freeClientAsync(c);
return REDIS_OK; return C_OK;
} }
psync_len = addReplyReplicationBacklog(c,psync_offset); psync_len = addReplyReplicationBacklog(c,psync_offset);
serverLog(REDIS_NOTICE, serverLog(REDIS_NOTICE,
@ -419,7 +419,7 @@ int masterTryPartialResynchronization(client *c) {
* has this state from the previous connection with the master. */ * has this state from the previous connection with the master. */
refreshGoodSlavesCount(); refreshGoodSlavesCount();
return REDIS_OK; /* The caller can return, no full resync needed. */ return C_OK; /* The caller can return, no full resync needed. */
need_full_resync: need_full_resync:
/* We need a full resync for some reason... notify the client. */ /* We need a full resync for some reason... notify the client. */
@ -432,16 +432,16 @@ need_full_resync:
server.runid,psync_offset); server.runid,psync_offset);
if (write(c->fd,buf,buflen) != buflen) { if (write(c->fd,buf,buflen) != buflen) {
freeClientAsync(c); freeClientAsync(c);
return REDIS_OK; return C_OK;
} }
return REDIS_ERR; return C_ERR;
} }
/* Start a BGSAVE for replication goals, which is, selecting the disk or /* Start a BGSAVE for replication goals, which is, selecting the disk or
* socket target depending on the configuration, and making sure that * socket target depending on the configuration, and making sure that
* the script cache is flushed before to start. * the script cache is flushed before to start.
* *
* Returns REDIS_OK on success or REDIS_ERR otherwise. */ * Returns C_OK on success or C_ERR otherwise. */
int startBgsaveForReplication(void) { int startBgsaveForReplication(void) {
int retval; int retval;
@ -455,7 +455,7 @@ int startBgsaveForReplication(void) {
/* Flush the script cache, since we need that slave differences are /* Flush the script cache, since we need that slave differences are
* accumulated without requiring slaves to match our cached scripts. */ * accumulated without requiring slaves to match our cached scripts. */
if (retval == REDIS_OK) replicationScriptCacheFlush(); if (retval == C_OK) replicationScriptCacheFlush();
return retval; return retval;
} }
@ -493,7 +493,7 @@ void syncCommand(client *c) {
* So the slave knows the new runid and offset to try a PSYNC later * So the slave knows the new runid and offset to try a PSYNC later
* if the connection with the master is lost. */ * if the connection with the master is lost. */
if (!strcasecmp(c->argv[0]->ptr,"psync")) { if (!strcasecmp(c->argv[0]->ptr,"psync")) {
if (masterTryPartialResynchronization(c) == REDIS_OK) { if (masterTryPartialResynchronization(c) == C_OK) {
server.stat_sync_partial_ok++; server.stat_sync_partial_ok++;
return; /* No full resync needed, return. */ return; /* No full resync needed, return. */
} else { } else {
@ -562,7 +562,7 @@ void syncCommand(client *c) {
serverLog(REDIS_NOTICE,"Delay next BGSAVE for SYNC"); serverLog(REDIS_NOTICE,"Delay next BGSAVE for SYNC");
} else { } else {
/* Ok we don't have a BGSAVE in progress, let's start one. */ /* Ok we don't have a BGSAVE in progress, let's start one. */
if (startBgsaveForReplication() != REDIS_OK) { if (startBgsaveForReplication() != C_OK) {
serverLog(REDIS_NOTICE,"Replication failed, can't BGSAVE"); serverLog(REDIS_NOTICE,"Replication failed, can't BGSAVE");
addReplyError(c,"Unable to perform background save"); addReplyError(c,"Unable to perform background save");
return; return;
@ -610,7 +610,7 @@ void replconfCommand(client *c) {
long port; long port;
if ((getLongFromObjectOrReply(c,c->argv[j+1], if ((getLongFromObjectOrReply(c,c->argv[j+1],
&port,NULL) != REDIS_OK)) &port,NULL) != C_OK))
return; return;
c->slave_listening_port = port; c->slave_listening_port = port;
} else if (!strcasecmp(c->argv[j]->ptr,"ack")) { } else if (!strcasecmp(c->argv[j]->ptr,"ack")) {
@ -620,7 +620,7 @@ void replconfCommand(client *c) {
long long offset; long long offset;
if (!(c->flags & REDIS_SLAVE)) return; if (!(c->flags & REDIS_SLAVE)) return;
if ((getLongLongFromObject(c->argv[j+1], &offset) != REDIS_OK)) if ((getLongLongFromObject(c->argv[j+1], &offset) != C_OK))
return; return;
if (offset > c->repl_ack_off) if (offset > c->repl_ack_off)
c->repl_ack_off = offset; c->repl_ack_off = offset;
@ -739,8 +739,8 @@ void sendBulkToSlave(aeEventLoop *el, int fd, void *privdata, int mask) {
* BGSAVE was in progress, but it was not a good one for replication (no * BGSAVE was in progress, but it was not a good one for replication (no
* other slave was accumulating differences). * other slave was accumulating differences).
* *
* The argument bgsaveerr is REDIS_OK if the background saving succeeded * The argument bgsaveerr is C_OK if the background saving succeeded
* otherwise REDIS_ERR is passed to the function. * otherwise C_ERR is passed to the function.
* The 'type' argument is the type of the child that terminated * The 'type' argument is the type of the child that terminated
* (if it had a disk or socket target). */ * (if it had a disk or socket target). */
void updateSlavesWaitingBgsave(int bgsaveerr, int type) { void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
@ -776,7 +776,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
slave->repl_put_online_on_ack = 1; slave->repl_put_online_on_ack = 1;
slave->repl_ack_time = server.unixtime; /* Timeout otherwise. */ slave->repl_ack_time = server.unixtime; /* Timeout otherwise. */
} else { } else {
if (bgsaveerr != REDIS_OK) { if (bgsaveerr != C_OK) {
freeClient(slave); freeClient(slave);
serverLog(REDIS_WARNING,"SYNC failed. BGSAVE child returned an error"); serverLog(REDIS_WARNING,"SYNC failed. BGSAVE child returned an error");
continue; continue;
@ -802,7 +802,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
} }
} }
if (startbgsave) { if (startbgsave) {
if (startBgsaveForReplication() != REDIS_OK) { if (startBgsaveForReplication() != C_OK) {
listIter li; listIter li;
listRewind(server.slaves,&li); listRewind(server.slaves,&li);
@ -1028,7 +1028,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
* time for non blocking loading. */ * time for non blocking loading. */
aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE); aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE);
serverLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Loading DB in memory"); serverLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Loading DB in memory");
if (rdbLoad(server.rdb_filename) != REDIS_OK) { if (rdbLoad(server.rdb_filename) != C_OK) {
serverLog(REDIS_WARNING,"Failed trying to load the MASTER synchronization DB from disk"); serverLog(REDIS_WARNING,"Failed trying to load the MASTER synchronization DB from disk");
replicationAbortSyncTransfer(); replicationAbortSyncTransfer();
return; return;
@ -1045,7 +1045,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
int retry = 10; int retry = 10;
stopAppendOnly(); stopAppendOnly();
while (retry-- && startAppendOnly() == REDIS_ERR) { while (retry-- && startAppendOnly() == C_ERR) {
serverLog(REDIS_WARNING,"Failed enabling the AOF after successful master synchronization! Trying it again in one second."); serverLog(REDIS_WARNING,"Failed enabling the AOF after successful master synchronization! Trying it again in one second.");
sleep(1); sleep(1);
} }
@ -1389,7 +1389,7 @@ int connectWithMaster(void) {
if (fd == -1) { if (fd == -1) {
serverLog(REDIS_WARNING,"Unable to connect to MASTER: %s", serverLog(REDIS_WARNING,"Unable to connect to MASTER: %s",
strerror(errno)); strerror(errno));
return REDIS_ERR; return C_ERR;
} }
if (aeCreateFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE,syncWithMaster,NULL) == if (aeCreateFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE,syncWithMaster,NULL) ==
@ -1397,13 +1397,13 @@ int connectWithMaster(void) {
{ {
close(fd); close(fd);
serverLog(REDIS_WARNING,"Can't create readable event for SYNC"); serverLog(REDIS_WARNING,"Can't create readable event for SYNC");
return REDIS_ERR; return C_ERR;
} }
server.repl_transfer_lastio = server.unixtime; server.repl_transfer_lastio = server.unixtime;
server.repl_transfer_s = fd; server.repl_transfer_s = fd;
server.repl_state = REDIS_REPL_CONNECTING; server.repl_state = REDIS_REPL_CONNECTING;
return REDIS_OK; return C_OK;
} }
/* This function can be called when a non blocking connection is currently /* This function can be called when a non blocking connection is currently
@ -1496,7 +1496,7 @@ void slaveofCommand(client *c) {
} else { } else {
long port; long port;
if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != C_OK))
return; return;
/* Check if we are already attached to the specified slave */ /* Check if we are already attached to the specified slave */
@ -1849,10 +1849,10 @@ void waitCommand(client *c) {
long long offset = c->woff; long long offset = c->woff;
/* Argument parsing. */ /* Argument parsing. */
if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != C_OK)
return; return;
if (getTimeoutFromObjectOrReply(c,c->argv[2],&timeout,UNIT_MILLISECONDS) if (getTimeoutFromObjectOrReply(c,c->argv[2],&timeout,UNIT_MILLISECONDS)
!= REDIS_OK) return; != C_OK) return;
/* First try without blocking at all. */ /* First try without blocking at all. */
ackreplicas = replicationCountAcksByOffset(c->woff); ackreplicas = replicationCountAcksByOffset(c->woff);
@ -1973,7 +1973,7 @@ void replicationCron(void) {
if (server.repl_state == REDIS_REPL_CONNECT) { if (server.repl_state == REDIS_REPL_CONNECT) {
serverLog(REDIS_NOTICE,"Connecting to MASTER %s:%d", serverLog(REDIS_NOTICE,"Connecting to MASTER %s:%d",
server.masterhost, server.masterport); server.masterhost, server.masterport);
if (connectWithMaster() == REDIS_OK) { if (connectWithMaster() == C_OK) {
serverLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started"); serverLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started");
} }
} }
@ -2090,7 +2090,7 @@ void replicationCron(void) {
if (slaves_waiting && max_idle > server.repl_diskless_sync_delay) { if (slaves_waiting && max_idle > server.repl_diskless_sync_delay) {
/* Start a BGSAVE. Usually with socket target, or with disk target /* Start a BGSAVE. Usually with socket target, or with disk target
* if there was a recent socket -> disk config change. */ * if there was a recent socket -> disk config change. */
if (startBgsaveForReplication() == REDIS_OK) { if (startBgsaveForReplication() == C_OK) {
/* It started! We need to change the state of slaves /* It started! We need to change the state of slaves
* from WAIT_BGSAVE_START to WAIT_BGSAVE_END in case * from WAIT_BGSAVE_START to WAIT_BGSAVE_END in case
* the current target is disk. Otherwise it was already done * the current target is disk. Otherwise it was already done

View File

@ -330,7 +330,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
goto cleanup; goto cleanup;
} else if (server.stop_writes_on_bgsave_err && } else if (server.stop_writes_on_bgsave_err &&
server.saveparamslen > 0 && server.saveparamslen > 0 &&
server.lastbgsave_status == REDIS_ERR) server.lastbgsave_status == C_ERR)
{ {
luaPushError(lua, shared.bgsaveerr->ptr); luaPushError(lua, shared.bgsaveerr->ptr);
goto cleanup; goto cleanup;
@ -344,7 +344,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
if (server.maxmemory && server.lua_write_dirty == 0 && if (server.maxmemory && server.lua_write_dirty == 0 &&
(cmd->flags & REDIS_CMD_DENYOOM)) (cmd->flags & REDIS_CMD_DENYOOM))
{ {
if (freeMemoryIfNeeded() == REDIS_ERR) { if (freeMemoryIfNeeded() == C_ERR) {
luaPushError(lua, shared.oomerr->ptr); luaPushError(lua, shared.oomerr->ptr);
goto cleanup; goto cleanup;
} }
@ -881,8 +881,8 @@ void luaSetGlobalArray(lua_State *lua, char *var, robj **elev, int elec) {
* *
* f_<hex sha1 sum> * f_<hex sha1 sum>
* *
* On success REDIS_OK is returned, and nothing is left on the Lua stack. * On success C_OK is returned, and nothing is left on the Lua stack.
* On error REDIS_ERR is returned and an appropriate error is set in the * On error C_ERR is returned and an appropriate error is set in the
* client context. */ * client context. */
int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) { int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) {
sds funcdef = sdsempty(); sds funcdef = sdsempty();
@ -898,14 +898,14 @@ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) {
lua_tostring(lua,-1)); lua_tostring(lua,-1));
lua_pop(lua,1); lua_pop(lua,1);
sdsfree(funcdef); sdsfree(funcdef);
return REDIS_ERR; return C_ERR;
} }
sdsfree(funcdef); sdsfree(funcdef);
if (lua_pcall(lua,0,0,0)) { if (lua_pcall(lua,0,0,0)) {
addReplyErrorFormat(c,"Error running script (new function): %s\n", addReplyErrorFormat(c,"Error running script (new function): %s\n",
lua_tostring(lua,-1)); lua_tostring(lua,-1));
lua_pop(lua,1); lua_pop(lua,1);
return REDIS_ERR; return C_ERR;
} }
/* We also save a SHA1 -> Original script map in a dictionary /* We also save a SHA1 -> Original script map in a dictionary
@ -917,7 +917,7 @@ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) {
serverAssertWithInfo(c,NULL,retval == DICT_OK); serverAssertWithInfo(c,NULL,retval == DICT_OK);
incrRefCount(body); incrRefCount(body);
} }
return REDIS_OK; return C_OK;
} }
void evalGenericCommand(client *c, int evalsha) { void evalGenericCommand(client *c, int evalsha) {
@ -942,7 +942,7 @@ void evalGenericCommand(client *c, int evalsha) {
server.lua_write_dirty = 0; server.lua_write_dirty = 0;
/* Get the number of arguments that are keys */ /* Get the number of arguments that are keys */
if (getLongLongFromObjectOrReply(c,c->argv[2],&numkeys,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[2],&numkeys,NULL) != C_OK)
return; return;
if (numkeys > (c->argc - 3)) { if (numkeys > (c->argc - 3)) {
addReplyError(c,"Number of keys can't be greater than number of args"); addReplyError(c,"Number of keys can't be greater than number of args");
@ -988,10 +988,10 @@ void evalGenericCommand(client *c, int evalsha) {
addReply(c, shared.noscripterr); addReply(c, shared.noscripterr);
return; return;
} }
if (luaCreateFunction(c,lua,funcname,c->argv[1]) == REDIS_ERR) { if (luaCreateFunction(c,lua,funcname,c->argv[1]) == C_ERR) {
lua_pop(lua,1); /* remove the error handler from the stack. */ lua_pop(lua,1); /* remove the error handler from the stack. */
/* The error is sent to the client by luaCreateFunction() /* The error is sent to the client by luaCreateFunction()
* itself when it returns REDIS_ERR. */ * itself when it returns C_ERR. */
return; return;
} }
/* Now the following is guaranteed to return non nil */ /* Now the following is guaranteed to return non nil */
@ -1175,7 +1175,7 @@ void scriptCommand(client *c) {
sha = sdsnewlen(funcname+2,40); sha = sdsnewlen(funcname+2,40);
if (dictFind(server.lua_scripts,sha) == NULL) { if (dictFind(server.lua_scripts,sha) == NULL) {
if (luaCreateFunction(c,server.lua,funcname,c->argv[2]) if (luaCreateFunction(c,server.lua,funcname,c->argv[2])
== REDIS_ERR) { == C_ERR) {
sdsfree(sha); sdsfree(sha);
return; return;
} }

View File

@ -331,7 +331,7 @@ static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
/* Nothing should be attached when something is already attached */ /* Nothing should be attached when something is already attached */
if (ac->ev.data != NULL) if (ac->ev.data != NULL)
return REDIS_ERR; return C_ERR;
/* Create container for context and r/w events */ /* Create container for context and r/w events */
e = (redisAeEvents*)zmalloc(sizeof(*e)); e = (redisAeEvents*)zmalloc(sizeof(*e));
@ -348,7 +348,7 @@ static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) {
ac->ev.cleanup = redisAeCleanup; ac->ev.cleanup = redisAeCleanup;
ac->ev.data = e; ac->ev.data = e;
return REDIS_OK; return C_OK;
} }
/* ============================= Prototypes ================================= */ /* ============================= Prototypes ================================= */
@ -1012,16 +1012,16 @@ instanceLink *releaseInstanceLink(instanceLink *link, sentinelRedisInstance *ri)
* a single connection, will send a single PING per second for failure * a single connection, will send a single PING per second for failure
* detection and so forth. * detection and so forth.
* *
* Return REDIS_OK if a matching Sentinel was found in the context of a * Return C_OK if a matching Sentinel was found in the context of a
* different master and sharing was performed. Otherwise REDIS_ERR * different master and sharing was performed. Otherwise C_ERR
* is returned. */ * is returned. */
int sentinelTryConnectionSharing(sentinelRedisInstance *ri) { int sentinelTryConnectionSharing(sentinelRedisInstance *ri) {
serverAssert(ri->flags & SRI_SENTINEL); serverAssert(ri->flags & SRI_SENTINEL);
dictIterator *di; dictIterator *di;
dictEntry *de; dictEntry *de;
if (ri->runid == NULL) return REDIS_ERR; /* No way to identify it. */ if (ri->runid == NULL) return C_ERR; /* No way to identify it. */
if (ri->link->refcount > 1) return REDIS_ERR; /* Already shared. */ if (ri->link->refcount > 1) return C_ERR; /* Already shared. */
di = dictGetIterator(sentinel.masters); di = dictGetIterator(sentinel.masters);
while((de = dictNext(di)) != NULL) { while((de = dictNext(di)) != NULL) {
@ -1039,10 +1039,10 @@ int sentinelTryConnectionSharing(sentinelRedisInstance *ri) {
releaseInstanceLink(ri->link,NULL); releaseInstanceLink(ri->link,NULL);
ri->link = match->link; ri->link = match->link;
match->link->refcount++; match->link->refcount++;
return REDIS_OK; return C_OK;
} }
dictReleaseIterator(di); dictReleaseIterator(di);
return REDIS_ERR; return C_ERR;
} }
/* When we detect a Sentinel to switch address (reporting a different IP/port /* When we detect a Sentinel to switch address (reporting a different IP/port
@ -1103,7 +1103,7 @@ void instanceLinkConnectionError(const redisAsyncContext *c) {
/* Hiredis connection established / disconnected callbacks. We need them /* Hiredis connection established / disconnected callbacks. We need them
* just to cleanup our link state. */ * just to cleanup our link state. */
void sentinelLinkEstablishedCallback(const redisAsyncContext *c, int status) { void sentinelLinkEstablishedCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) instanceLinkConnectionError(c); if (status != C_OK) instanceLinkConnectionError(c);
} }
void sentinelDisconnectCallback(const redisAsyncContext *c, int status) { void sentinelDisconnectCallback(const redisAsyncContext *c, int status) {
@ -1447,8 +1447,8 @@ int sentinelResetMastersByPattern(char *pattern, int flags) {
* *
* This is used to handle the +switch-master event. * This is used to handle the +switch-master event.
* *
* The function returns REDIS_ERR if the address can't be resolved for some * The function returns C_ERR if the address can't be resolved for some
* reason. Otherwise REDIS_OK is returned. */ * reason. Otherwise C_OK is returned. */
int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip, int port) { int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip, int port) {
sentinelAddr *oldaddr, *newaddr; sentinelAddr *oldaddr, *newaddr;
sentinelAddr **slaves = NULL; sentinelAddr **slaves = NULL;
@ -1457,7 +1457,7 @@ int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip,
dictEntry *de; dictEntry *de;
newaddr = createSentinelAddr(ip,port); newaddr = createSentinelAddr(ip,port);
if (newaddr == NULL) return REDIS_ERR; if (newaddr == NULL) return C_ERR;
/* Make a list of slaves to add back after the reset. /* Make a list of slaves to add back after the reset.
* Don't include the one having the address we are switching to. */ * Don't include the one having the address we are switching to. */
@ -1503,7 +1503,7 @@ int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip,
* gets the master->addr->ip and master->addr->port as arguments. */ * gets the master->addr->ip and master->addr->port as arguments. */
releaseSentinelAddr(oldaddr); releaseSentinelAddr(oldaddr);
sentinelFlushConfig(); sentinelFlushConfig();
return REDIS_OK; return C_OK;
} }
/* Return non-zero if there was no SDOWN or ODOWN error associated to this /* Return non-zero if there was no SDOWN or ODOWN error associated to this
@ -1869,7 +1869,7 @@ void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) {
if (auth_pass) { if (auth_pass) {
if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, "AUTH %s", if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, "AUTH %s",
auth_pass) == REDIS_OK) ri->link->pending_commands++; auth_pass) == C_OK) ri->link->pending_commands++;
} }
} }
@ -1884,7 +1884,7 @@ void sentinelSetClientName(sentinelRedisInstance *ri, redisAsyncContext *c, char
snprintf(name,sizeof(name),"sentinel-%.8s-%s",sentinel.myid,type); snprintf(name,sizeof(name),"sentinel-%.8s-%s",sentinel.myid,type);
if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri,
"CLIENT SETNAME %s", name) == REDIS_OK) "CLIENT SETNAME %s", name) == C_OK)
{ {
ri->link->pending_commands++; ri->link->pending_commands++;
} }
@ -1946,7 +1946,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
retval = redisAsyncCommand(link->pc, retval = redisAsyncCommand(link->pc,
sentinelReceiveHelloMessages, ri, "SUBSCRIBE %s", sentinelReceiveHelloMessages, ri, "SUBSCRIBE %s",
SENTINEL_HELLO_CHANNEL); SENTINEL_HELLO_CHANNEL);
if (retval != REDIS_OK) { if (retval != C_OK) {
/* If we can't subscribe, the Pub/Sub connection is useless /* If we can't subscribe, the Pub/Sub connection is useless
* and we can simply disconnect it and try again. */ * and we can simply disconnect it and try again. */
instanceLinkCloseConnection(link,link->pc); instanceLinkCloseConnection(link,link->pc);
@ -2172,7 +2172,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
int retval = sentinelSendSlaveOf(ri, int retval = sentinelSendSlaveOf(ri,
ri->master->addr->ip, ri->master->addr->ip,
ri->master->addr->port); ri->master->addr->port);
if (retval == REDIS_OK) if (retval == C_OK)
sentinelEvent(REDIS_NOTICE,"+convert-to-slave",ri,"%@"); sentinelEvent(REDIS_NOTICE,"+convert-to-slave",ri,"%@");
} }
} }
@ -2195,7 +2195,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
int retval = sentinelSendSlaveOf(ri, int retval = sentinelSendSlaveOf(ri,
ri->master->addr->ip, ri->master->addr->ip,
ri->master->addr->port); ri->master->addr->port);
if (retval == REDIS_OK) if (retval == C_OK)
sentinelEvent(REDIS_NOTICE,"+fix-slave-config",ri,"%@"); sentinelEvent(REDIS_NOTICE,"+fix-slave-config",ri,"%@");
} }
} }
@ -2279,7 +2279,7 @@ void sentinelPingReplyCallback(redisAsyncContext *c, void *reply, void *privdata
{ {
if (redisAsyncCommand(ri->link->cc, if (redisAsyncCommand(ri->link->cc,
sentinelDiscardReplyCallback, ri, sentinelDiscardReplyCallback, ri,
"SCRIPT KILL") == REDIS_OK) "SCRIPT KILL") == C_OK)
ri->link->pending_commands++; ri->link->pending_commands++;
ri->flags |= SRI_SCRIPT_KILL_SENT; ri->flags |= SRI_SCRIPT_KILL_SENT;
} }
@ -2437,8 +2437,8 @@ void sentinelReceiveHelloMessages(redisAsyncContext *c, void *reply, void *privd
* sentinel_ip,sentinel_port,sentinel_runid,current_epoch, * sentinel_ip,sentinel_port,sentinel_runid,current_epoch,
* master_name,master_ip,master_port,master_config_epoch. * master_name,master_ip,master_port,master_config_epoch.
* *
* Returns REDIS_OK if the PUBLISH was queued correctly, otherwise * Returns C_OK if the PUBLISH was queued correctly, otherwise
* REDIS_ERR is returned. */ * C_ERR is returned. */
int sentinelSendHello(sentinelRedisInstance *ri) { int sentinelSendHello(sentinelRedisInstance *ri) {
char ip[REDIS_IP_STR_LEN]; char ip[REDIS_IP_STR_LEN];
char payload[REDIS_IP_STR_LEN+1024]; char payload[REDIS_IP_STR_LEN+1024];
@ -2448,7 +2448,7 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->master; sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->master;
sentinelAddr *master_addr = sentinelGetCurrentMasterAddress(master); sentinelAddr *master_addr = sentinelGetCurrentMasterAddress(master);
if (ri->link->disconnected) return REDIS_ERR; if (ri->link->disconnected) return C_ERR;
/* Use the specified announce address if specified, otherwise try to /* Use the specified announce address if specified, otherwise try to
* obtain our own IP address. */ * obtain our own IP address. */
@ -2456,7 +2456,7 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
announce_ip = sentinel.announce_ip; announce_ip = sentinel.announce_ip;
} else { } else {
if (anetSockName(ri->link->cc->c.fd,ip,sizeof(ip),NULL) == -1) if (anetSockName(ri->link->cc->c.fd,ip,sizeof(ip),NULL) == -1)
return REDIS_ERR; return C_ERR;
announce_ip = ip; announce_ip = ip;
} }
announce_port = sentinel.announce_port ? announce_port = sentinel.announce_port ?
@ -2474,9 +2474,9 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelPublishReplyCallback, ri, "PUBLISH %s %s", sentinelPublishReplyCallback, ri, "PUBLISH %s %s",
SENTINEL_HELLO_CHANNEL,payload); SENTINEL_HELLO_CHANNEL,payload);
if (retval != REDIS_OK) return REDIS_ERR; if (retval != C_OK) return C_ERR;
ri->link->pending_commands++; ri->link->pending_commands++;
return REDIS_OK; return C_OK;
} }
/* Reset last_pub_time in all the instances in the specified dictionary /* Reset last_pub_time in all the instances in the specified dictionary
@ -2503,12 +2503,12 @@ void sentinelForceHelloUpdateDictOfRedisInstances(dict *instances) {
* Sentinel upgrades a configuration it is a good idea to deliever an update * Sentinel upgrades a configuration it is a good idea to deliever an update
* to the other Sentinels ASAP. */ * to the other Sentinels ASAP. */
int sentinelForceHelloUpdateForMaster(sentinelRedisInstance *master) { int sentinelForceHelloUpdateForMaster(sentinelRedisInstance *master) {
if (!(master->flags & SRI_MASTER)) return REDIS_ERR; if (!(master->flags & SRI_MASTER)) return C_ERR;
if (master->last_pub_time >= (SENTINEL_PUBLISH_PERIOD+1)) if (master->last_pub_time >= (SENTINEL_PUBLISH_PERIOD+1))
master->last_pub_time -= (SENTINEL_PUBLISH_PERIOD+1); master->last_pub_time -= (SENTINEL_PUBLISH_PERIOD+1);
sentinelForceHelloUpdateDictOfRedisInstances(master->sentinels); sentinelForceHelloUpdateDictOfRedisInstances(master->sentinels);
sentinelForceHelloUpdateDictOfRedisInstances(master->slaves); sentinelForceHelloUpdateDictOfRedisInstances(master->slaves);
return REDIS_OK; return C_OK;
} }
/* Send a PING to the specified instance and refresh the act_ping_time /* Send a PING to the specified instance and refresh the act_ping_time
@ -2519,7 +2519,7 @@ int sentinelForceHelloUpdateForMaster(sentinelRedisInstance *master) {
int sentinelSendPing(sentinelRedisInstance *ri) { int sentinelSendPing(sentinelRedisInstance *ri) {
int retval = redisAsyncCommand(ri->link->cc, int retval = redisAsyncCommand(ri->link->cc,
sentinelPingReplyCallback, ri, "PING"); sentinelPingReplyCallback, ri, "PING");
if (retval == REDIS_OK) { if (retval == C_OK) {
ri->link->pending_commands++; ri->link->pending_commands++;
ri->link->last_ping_time = mstime(); ri->link->last_ping_time = mstime();
/* We update the active ping time only if we received the pong for /* We update the active ping time only if we received the pong for
@ -2577,7 +2577,7 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
/* Send INFO to masters and slaves, not sentinels. */ /* Send INFO to masters and slaves, not sentinels. */
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelInfoReplyCallback, ri, "INFO"); sentinelInfoReplyCallback, ri, "INFO");
if (retval == REDIS_OK) ri->link->pending_commands++; if (retval == C_OK) ri->link->pending_commands++;
} else if ((now - ri->link->last_pong_time) > ping_period && } else if ((now - ri->link->last_pong_time) > ping_period &&
(now - ri->link->last_ping_time) > ping_period/2) { (now - ri->link->last_ping_time) > ping_period/2) {
/* Send PING to all the three kinds of instances. */ /* Send PING to all the three kinds of instances. */
@ -2905,9 +2905,9 @@ void sentinelCommand(client *c) {
int isdown = 0; int isdown = 0;
if (c->argc != 6) goto numargserr; if (c->argc != 6) goto numargserr;
if (getLongFromObjectOrReply(c,c->argv[3],&port,NULL) != REDIS_OK || if (getLongFromObjectOrReply(c,c->argv[3],&port,NULL) != C_OK ||
getLongLongFromObjectOrReply(c,c->argv[4],&req_epoch,NULL) getLongLongFromObjectOrReply(c,c->argv[4],&req_epoch,NULL)
!= REDIS_OK) != C_OK)
return; return;
ri = getSentinelRedisInstanceByAddrAndRunID(sentinel.masters, ri = getSentinelRedisInstanceByAddrAndRunID(sentinel.masters,
c->argv[2]->ptr,port,NULL); c->argv[2]->ptr,port,NULL);
@ -2985,9 +2985,9 @@ void sentinelCommand(client *c) {
if (c->argc != 6) goto numargserr; if (c->argc != 6) goto numargserr;
if (getLongFromObjectOrReply(c,c->argv[5],&quorum,"Invalid quorum") if (getLongFromObjectOrReply(c,c->argv[5],&quorum,"Invalid quorum")
!= REDIS_OK) return; != C_OK) return;
if (getLongFromObjectOrReply(c,c->argv[4],&port,"Invalid port") if (getLongFromObjectOrReply(c,c->argv[4],&port,"Invalid port")
!= REDIS_OK) return; != C_OK) return;
if (quorum <= 0) { if (quorum <= 0) {
addReplyError(c, "Quorum must be 1 or greater."); addReplyError(c, "Quorum must be 1 or greater.");
@ -3267,20 +3267,20 @@ void sentinelSetCommand(client *c) {
if (!strcasecmp(option,"down-after-milliseconds")) { if (!strcasecmp(option,"down-after-milliseconds")) {
/* down-after-millisecodns <milliseconds> */ /* down-after-millisecodns <milliseconds> */
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->down_after_period = ll; ri->down_after_period = ll;
sentinelPropagateDownAfterPeriod(ri); sentinelPropagateDownAfterPeriod(ri);
changes++; changes++;
} else if (!strcasecmp(option,"failover-timeout")) { } else if (!strcasecmp(option,"failover-timeout")) {
/* failover-timeout <milliseconds> */ /* failover-timeout <milliseconds> */
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->failover_timeout = ll; ri->failover_timeout = ll;
changes++; changes++;
} else if (!strcasecmp(option,"parallel-syncs")) { } else if (!strcasecmp(option,"parallel-syncs")) {
/* parallel-syncs <milliseconds> */ /* parallel-syncs <milliseconds> */
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->parallel_syncs = ll; ri->parallel_syncs = ll;
changes++; changes++;
@ -3314,7 +3314,7 @@ void sentinelSetCommand(client *c) {
changes++; changes++;
} else if (!strcasecmp(option,"quorum")) { } else if (!strcasecmp(option,"quorum")) {
/* quorum <count> */ /* quorum <count> */
if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->quorum = ll; ri->quorum = ll;
changes++; changes++;
@ -3543,7 +3543,7 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f
sentinel.current_epoch, sentinel.current_epoch,
(master->failover_state > SENTINEL_FAILOVER_STATE_NONE) ? (master->failover_state > SENTINEL_FAILOVER_STATE_NONE) ?
sentinel.myid : "*"); sentinel.myid : "*");
if (retval == REDIS_OK) ri->link->pending_commands++; if (retval == C_OK) ri->link->pending_commands++;
} }
dictReleaseIterator(di); dictReleaseIterator(di);
} }
@ -3690,8 +3690,8 @@ char *sentinelGetLeader(sentinelRedisInstance *master, uint64_t epoch) {
* *
* If Host is NULL the function sends "SLAVEOF NO ONE". * If Host is NULL the function sends "SLAVEOF NO ONE".
* *
* The command returns REDIS_OK if the SLAVEOF command was accepted for * The command returns C_OK if the SLAVEOF command was accepted for
* (later) delivery otherwise REDIS_ERR. The command replies are just * (later) delivery otherwise C_ERR. The command replies are just
* discarded. */ * discarded. */
int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) { int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) {
char portstr[32]; char portstr[32];
@ -3718,17 +3718,17 @@ int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) {
* will observe instead the effects in the next INFO output. */ * will observe instead the effects in the next INFO output. */
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelDiscardReplyCallback, ri, "MULTI"); sentinelDiscardReplyCallback, ri, "MULTI");
if (retval == REDIS_ERR) return retval; if (retval == C_ERR) return retval;
ri->link->pending_commands++; ri->link->pending_commands++;
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelDiscardReplyCallback, ri, "SLAVEOF %s %s", host, portstr); sentinelDiscardReplyCallback, ri, "SLAVEOF %s %s", host, portstr);
if (retval == REDIS_ERR) return retval; if (retval == C_ERR) return retval;
ri->link->pending_commands++; ri->link->pending_commands++;
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelDiscardReplyCallback, ri, "CONFIG REWRITE"); sentinelDiscardReplyCallback, ri, "CONFIG REWRITE");
if (retval == REDIS_ERR) return retval; if (retval == C_ERR) return retval;
ri->link->pending_commands++; ri->link->pending_commands++;
/* CLIENT KILL TYPE <type> is only supported starting from Redis 2.8.12, /* CLIENT KILL TYPE <type> is only supported starting from Redis 2.8.12,
@ -3738,15 +3738,15 @@ int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) {
* only the unsupported command will fail). */ * only the unsupported command will fail). */
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelDiscardReplyCallback, ri, "CLIENT KILL TYPE normal"); sentinelDiscardReplyCallback, ri, "CLIENT KILL TYPE normal");
if (retval == REDIS_ERR) return retval; if (retval == C_ERR) return retval;
ri->link->pending_commands++; ri->link->pending_commands++;
retval = redisAsyncCommand(ri->link->cc, retval = redisAsyncCommand(ri->link->cc,
sentinelDiscardReplyCallback, ri, "EXEC"); sentinelDiscardReplyCallback, ri, "EXEC");
if (retval == REDIS_ERR) return retval; if (retval == C_ERR) return retval;
ri->link->pending_commands++; ri->link->pending_commands++;
return REDIS_OK; return C_OK;
} }
/* Setup the master state to start a failover. */ /* Setup the master state to start a failover. */
@ -3980,7 +3980,7 @@ void sentinelFailoverSendSlaveOfNoOne(sentinelRedisInstance *ri) {
* really care about the reply. We check if it worked indirectly observing * really care about the reply. We check if it worked indirectly observing
* if INFO returns a different role (master instead of slave). */ * if INFO returns a different role (master instead of slave). */
retval = sentinelSendSlaveOf(ri->promoted_slave,NULL,0); retval = sentinelSendSlaveOf(ri->promoted_slave,NULL,0);
if (retval != REDIS_OK) return; if (retval != C_OK) return;
sentinelEvent(REDIS_NOTICE, "+failover-state-wait-promotion", sentinelEvent(REDIS_NOTICE, "+failover-state-wait-promotion",
ri->promoted_slave,"%@"); ri->promoted_slave,"%@");
ri->failover_state = SENTINEL_FAILOVER_STATE_WAIT_PROMOTION; ri->failover_state = SENTINEL_FAILOVER_STATE_WAIT_PROMOTION;
@ -4052,7 +4052,7 @@ void sentinelFailoverDetectEnd(sentinelRedisInstance *master) {
retval = sentinelSendSlaveOf(slave, retval = sentinelSendSlaveOf(slave,
master->promoted_slave->addr->ip, master->promoted_slave->addr->ip,
master->promoted_slave->addr->port); master->promoted_slave->addr->port);
if (retval == REDIS_OK) { if (retval == C_OK) {
sentinelEvent(REDIS_NOTICE,"+slave-reconf-sent-be",slave,"%@"); sentinelEvent(REDIS_NOTICE,"+slave-reconf-sent-be",slave,"%@");
slave->flags |= SRI_RECONF_SENT; slave->flags |= SRI_RECONF_SENT;
} }
@ -4109,7 +4109,7 @@ void sentinelFailoverReconfNextSlave(sentinelRedisInstance *master) {
retval = sentinelSendSlaveOf(slave, retval = sentinelSendSlaveOf(slave,
master->promoted_slave->addr->ip, master->promoted_slave->addr->ip,
master->promoted_slave->addr->port); master->promoted_slave->addr->port);
if (retval == REDIS_OK) { if (retval == C_OK) {
slave->flags |= SRI_RECONF_SENT; slave->flags |= SRI_RECONF_SENT;
slave->slave_reconf_sent_time = mstime(); slave->slave_reconf_sent_time = mstime();
sentinelEvent(REDIS_NOTICE,"+slave-reconf-sent",slave,"%@"); sentinelEvent(REDIS_NOTICE,"+slave-reconf-sent",slave,"%@");

View File

@ -1125,7 +1125,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* We received a SIGTERM, shutting down here in a safe way, as it is /* We received a SIGTERM, shutting down here in a safe way, as it is
* not ok doing so inside the signal handler. */ * not ok doing so inside the signal handler. */
if (server.shutdown_asap) { if (server.shutdown_asap) {
if (prepareForShutdown(0) == REDIS_OK) exit(0); if (prepareForShutdown(0) == C_OK) exit(0);
serverLog(REDIS_WARNING,"SIGTERM received but errors trying to shut down the server, check the logs for more information"); serverLog(REDIS_WARNING,"SIGTERM received but errors trying to shut down the server, check the logs for more information");
server.shutdown_asap = 0; server.shutdown_asap = 0;
} }
@ -1206,7 +1206,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
server.unixtime-server.lastsave > sp->seconds && server.unixtime-server.lastsave > sp->seconds &&
(server.unixtime-server.lastbgsave_try > (server.unixtime-server.lastbgsave_try >
REDIS_BGSAVE_RETRY_DELAY || REDIS_BGSAVE_RETRY_DELAY ||
server.lastbgsave_status == REDIS_OK)) server.lastbgsave_status == C_OK))
{ {
serverLog(REDIS_NOTICE,"%d changes in %d seconds. Saving...", serverLog(REDIS_NOTICE,"%d changes in %d seconds. Saving...",
sp->changes, (int)sp->seconds); sp->changes, (int)sp->seconds);
@ -1241,7 +1241,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
* however to try every second is enough in case of 'hz' is set to * however to try every second is enough in case of 'hz' is set to
* an higher frequency. */ * an higher frequency. */
run_with_period(1000) { run_with_period(1000) {
if (server.aof_last_write_status == REDIS_ERR) if (server.aof_last_write_status == C_ERR)
flushAppendOnlyFile(0); flushAppendOnlyFile(0);
} }
@ -1451,7 +1451,7 @@ void initServerConfig(void) {
server.aof_last_fsync = time(NULL); server.aof_last_fsync = time(NULL);
server.aof_rewrite_time_last = -1; server.aof_rewrite_time_last = -1;
server.aof_rewrite_time_start = -1; server.aof_rewrite_time_start = -1;
server.aof_lastbgrewrite_status = REDIS_OK; server.aof_lastbgrewrite_status = C_OK;
server.aof_delayed_fsync = 0; server.aof_delayed_fsync = 0;
server.aof_fd = -1; server.aof_fd = -1;
server.aof_selected_db = -1; /* Make sure the first time will not match */ server.aof_selected_db = -1; /* Make sure the first time will not match */
@ -1678,9 +1678,9 @@ void checkTcpBacklogSettings(void) {
* contains no specific addresses to bind, this function will try to * contains no specific addresses to bind, this function will try to
* bind * (all addresses) for both the IPv4 and IPv6 protocols. * bind * (all addresses) for both the IPv4 and IPv6 protocols.
* *
* On success the function returns REDIS_OK. * On success the function returns C_OK.
* *
* On error the function returns REDIS_ERR. For the function to be on * On error the function returns C_ERR. For the function to be on
* error, at least one of the server.bindaddr addresses was * error, at least one of the server.bindaddr addresses was
* impossible to bind, or no bind addresses were specified in the server * impossible to bind, or no bind addresses were specified in the server
* configuration but the function is not able to bind * for at least * configuration but the function is not able to bind * for at least
@ -1725,12 +1725,12 @@ int listenToPort(int port, int *fds, int *count) {
"Creating Server TCP listening socket %s:%d: %s", "Creating Server TCP listening socket %s:%d: %s",
server.bindaddr[j] ? server.bindaddr[j] : "*", server.bindaddr[j] ? server.bindaddr[j] : "*",
port, server.neterr); port, server.neterr);
return REDIS_ERR; return C_ERR;
} }
anetNonBlock(NULL,fds[*count]); anetNonBlock(NULL,fds[*count]);
(*count)++; (*count)++;
} }
return REDIS_OK; return C_OK;
} }
/* Resets the stats that we expose via INFO or other means that we want /* Resets the stats that we expose via INFO or other means that we want
@ -1796,7 +1796,7 @@ void initServer(void) {
/* Open the TCP listening socket for the user commands. */ /* Open the TCP listening socket for the user commands. */
if (server.port != 0 && if (server.port != 0 &&
listenToPort(server.port,server.ipfd,&server.ipfd_count) == REDIS_ERR) listenToPort(server.port,server.ipfd,&server.ipfd_count) == C_ERR)
exit(1); exit(1);
/* Open the listening Unix domain socket. */ /* Open the listening Unix domain socket. */
@ -1848,8 +1848,8 @@ void initServer(void) {
server.stat_starttime = time(NULL); server.stat_starttime = time(NULL);
server.stat_peak_memory = 0; server.stat_peak_memory = 0;
server.resident_set_size = 0; server.resident_set_size = 0;
server.lastbgsave_status = REDIS_OK; server.lastbgsave_status = C_OK;
server.aof_last_write_status = REDIS_OK; server.aof_last_write_status = C_OK;
server.aof_last_write_errno = 0; server.aof_last_write_errno = 0;
server.repl_good_slaves_count = 0; server.repl_good_slaves_count = 0;
updateCachedTime(); updateCachedTime();
@ -2187,7 +2187,7 @@ int processCommand(client *c) {
if (!strcasecmp(c->argv[0]->ptr,"quit")) { if (!strcasecmp(c->argv[0]->ptr,"quit")) {
addReply(c,shared.ok); addReply(c,shared.ok);
c->flags |= REDIS_CLOSE_AFTER_REPLY; c->flags |= REDIS_CLOSE_AFTER_REPLY;
return REDIS_ERR; return C_ERR;
} }
/* Now lookup the command and check ASAP about trivial error conditions /* Now lookup the command and check ASAP about trivial error conditions
@ -2197,13 +2197,13 @@ int processCommand(client *c) {
flagTransaction(c); flagTransaction(c);
addReplyErrorFormat(c,"unknown command '%s'", addReplyErrorFormat(c,"unknown command '%s'",
(char*)c->argv[0]->ptr); (char*)c->argv[0]->ptr);
return REDIS_OK; return C_OK;
} else if ((c->cmd->arity > 0 && c->cmd->arity != c->argc) || } else if ((c->cmd->arity > 0 && c->cmd->arity != c->argc) ||
(c->argc < -c->cmd->arity)) { (c->argc < -c->cmd->arity)) {
flagTransaction(c); flagTransaction(c);
addReplyErrorFormat(c,"wrong number of arguments for '%s' command", addReplyErrorFormat(c,"wrong number of arguments for '%s' command",
c->cmd->name); c->cmd->name);
return REDIS_OK; return C_OK;
} }
/* Check if the user is authenticated */ /* Check if the user is authenticated */
@ -2211,7 +2211,7 @@ int processCommand(client *c) {
{ {
flagTransaction(c); flagTransaction(c);
addReply(c,shared.noautherr); addReply(c,shared.noautherr);
return REDIS_OK; return C_OK;
} }
/* If cluster is enabled perform the cluster redirection here. /* If cluster is enabled perform the cluster redirection here.
@ -2229,14 +2229,14 @@ int processCommand(client *c) {
if (server.cluster->state != REDIS_CLUSTER_OK) { if (server.cluster->state != REDIS_CLUSTER_OK) {
flagTransaction(c); flagTransaction(c);
clusterRedirectClient(c,NULL,0,REDIS_CLUSTER_REDIR_DOWN_STATE); clusterRedirectClient(c,NULL,0,REDIS_CLUSTER_REDIR_DOWN_STATE);
return REDIS_OK; return C_OK;
} else { } else {
int error_code; int error_code;
clusterNode *n = getNodeByQuery(c,c->cmd,c->argv,c->argc,&hashslot,&error_code); clusterNode *n = getNodeByQuery(c,c->cmd,c->argv,c->argc,&hashslot,&error_code);
if (n == NULL || n != server.cluster->myself) { if (n == NULL || n != server.cluster->myself) {
flagTransaction(c); flagTransaction(c);
clusterRedirectClient(c,n,hashslot,error_code); clusterRedirectClient(c,n,hashslot,error_code);
return REDIS_OK; return C_OK;
} }
} }
} }
@ -2248,10 +2248,10 @@ int processCommand(client *c) {
* is returning an error. */ * is returning an error. */
if (server.maxmemory) { if (server.maxmemory) {
int retval = freeMemoryIfNeeded(); int retval = freeMemoryIfNeeded();
if ((c->cmd->flags & REDIS_CMD_DENYOOM) && retval == REDIS_ERR) { if ((c->cmd->flags & REDIS_CMD_DENYOOM) && retval == C_ERR) {
flagTransaction(c); flagTransaction(c);
addReply(c, shared.oomerr); addReply(c, shared.oomerr);
return REDIS_OK; return C_OK;
} }
} }
@ -2259,21 +2259,21 @@ int processCommand(client *c) {
* and if this is a master instance. */ * and if this is a master instance. */
if (((server.stop_writes_on_bgsave_err && if (((server.stop_writes_on_bgsave_err &&
server.saveparamslen > 0 && server.saveparamslen > 0 &&
server.lastbgsave_status == REDIS_ERR) || server.lastbgsave_status == C_ERR) ||
server.aof_last_write_status == REDIS_ERR) && server.aof_last_write_status == C_ERR) &&
server.masterhost == NULL && server.masterhost == NULL &&
(c->cmd->flags & REDIS_CMD_WRITE || (c->cmd->flags & REDIS_CMD_WRITE ||
c->cmd->proc == pingCommand)) c->cmd->proc == pingCommand))
{ {
flagTransaction(c); flagTransaction(c);
if (server.aof_last_write_status == REDIS_OK) if (server.aof_last_write_status == C_OK)
addReply(c, shared.bgsaveerr); addReply(c, shared.bgsaveerr);
else else
addReplySds(c, addReplySds(c,
sdscatprintf(sdsempty(), sdscatprintf(sdsempty(),
"-MISCONF Errors writing to the AOF file: %s\r\n", "-MISCONF Errors writing to the AOF file: %s\r\n",
strerror(server.aof_last_write_errno))); strerror(server.aof_last_write_errno)));
return REDIS_OK; return C_OK;
} }
/* Don't accept write commands if there are not enough good slaves and /* Don't accept write commands if there are not enough good slaves and
@ -2286,7 +2286,7 @@ int processCommand(client *c) {
{ {
flagTransaction(c); flagTransaction(c);
addReply(c, shared.noreplicaserr); addReply(c, shared.noreplicaserr);
return REDIS_OK; return C_OK;
} }
/* Don't accept write commands if this is a read only slave. But /* Don't accept write commands if this is a read only slave. But
@ -2296,7 +2296,7 @@ int processCommand(client *c) {
c->cmd->flags & REDIS_CMD_WRITE) c->cmd->flags & REDIS_CMD_WRITE)
{ {
addReply(c, shared.roslaveerr); addReply(c, shared.roslaveerr);
return REDIS_OK; return C_OK;
} }
/* Only allow SUBSCRIBE and UNSUBSCRIBE in the context of Pub/Sub */ /* Only allow SUBSCRIBE and UNSUBSCRIBE in the context of Pub/Sub */
@ -2307,7 +2307,7 @@ int processCommand(client *c) {
c->cmd->proc != psubscribeCommand && c->cmd->proc != psubscribeCommand &&
c->cmd->proc != punsubscribeCommand) { c->cmd->proc != punsubscribeCommand) {
addReplyError(c,"only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context"); addReplyError(c,"only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context");
return REDIS_OK; return C_OK;
} }
/* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and /* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
@ -2318,14 +2318,14 @@ int processCommand(client *c) {
{ {
flagTransaction(c); flagTransaction(c);
addReply(c, shared.masterdownerr); addReply(c, shared.masterdownerr);
return REDIS_OK; return C_OK;
} }
/* Loading DB? Return an error if the command has not the /* Loading DB? Return an error if the command has not the
* REDIS_CMD_LOADING flag. */ * REDIS_CMD_LOADING flag. */
if (server.loading && !(c->cmd->flags & REDIS_CMD_LOADING)) { if (server.loading && !(c->cmd->flags & REDIS_CMD_LOADING)) {
addReply(c, shared.loadingerr); addReply(c, shared.loadingerr);
return REDIS_OK; return C_OK;
} }
/* Lua script too slow? Only allow a limited number of commands. */ /* Lua script too slow? Only allow a limited number of commands. */
@ -2341,7 +2341,7 @@ int processCommand(client *c) {
{ {
flagTransaction(c); flagTransaction(c);
addReply(c, shared.slowscripterr); addReply(c, shared.slowscripterr);
return REDIS_OK; return C_OK;
} }
/* Exec the command */ /* Exec the command */
@ -2357,7 +2357,7 @@ int processCommand(client *c) {
if (listLength(server.ready_keys)) if (listLength(server.ready_keys))
handleClientsBlockedOnLists(); handleClientsBlockedOnLists();
} }
return REDIS_OK; return C_OK;
} }
/*================================== Shutdown =============================== */ /*================================== Shutdown =============================== */
@ -2398,7 +2398,7 @@ int prepareForShutdown(int flags) {
* shutdown or else the dataset will be lost. */ * shutdown or else the dataset will be lost. */
if (server.aof_state == REDIS_AOF_WAIT_REWRITE) { if (server.aof_state == REDIS_AOF_WAIT_REWRITE) {
serverLog(REDIS_WARNING, "Writing initial AOF, can't exit."); serverLog(REDIS_WARNING, "Writing initial AOF, can't exit.");
return REDIS_ERR; return C_ERR;
} }
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"There is a child rewriting the AOF. Killing it!"); "There is a child rewriting the AOF. Killing it!");
@ -2411,14 +2411,14 @@ int prepareForShutdown(int flags) {
if ((server.saveparamslen > 0 && !nosave) || save) { if ((server.saveparamslen > 0 && !nosave) || save) {
serverLog(REDIS_NOTICE,"Saving the final RDB snapshot before exiting."); serverLog(REDIS_NOTICE,"Saving the final RDB snapshot before exiting.");
/* Snapshotting. Perform a SYNC SAVE and exit */ /* Snapshotting. Perform a SYNC SAVE and exit */
if (rdbSave(server.rdb_filename) != REDIS_OK) { if (rdbSave(server.rdb_filename) != C_OK) {
/* Ooops.. error saving! The best we can do is to continue /* Ooops.. error saving! The best we can do is to continue
* operating. Note that if there was a background saving process, * operating. Note that if there was a background saving process,
* in the next cron() Redis will be notified that the background * in the next cron() Redis will be notified that the background
* saving aborted, handling special stuff like slaves pending for * saving aborted, handling special stuff like slaves pending for
* synchronization... */ * synchronization... */
serverLog(REDIS_WARNING,"Error trying to save the DB, can't exit."); serverLog(REDIS_WARNING,"Error trying to save the DB, can't exit.");
return REDIS_ERR; return C_ERR;
} }
} }
if (server.daemonize || server.pidfile) { if (server.daemonize || server.pidfile) {
@ -2429,7 +2429,7 @@ int prepareForShutdown(int flags) {
closeListeningSockets(1); closeListeningSockets(1);
serverLog(REDIS_WARNING,"%s is now ready to exit, bye bye...", serverLog(REDIS_WARNING,"%s is now ready to exit, bye bye...",
server.sentinel_mode ? "Sentinel" : "Redis"); server.sentinel_mode ? "Sentinel" : "Redis");
return REDIS_OK; return C_OK;
} }
/*================================== Commands =============================== */ /*================================== Commands =============================== */
@ -2828,7 +2828,7 @@ sds genRedisInfoString(char *section) {
server.dirty, server.dirty,
server.rdb_child_pid != -1, server.rdb_child_pid != -1,
(intmax_t)server.lastsave, (intmax_t)server.lastsave,
(server.lastbgsave_status == REDIS_OK) ? "ok" : "err", (server.lastbgsave_status == C_OK) ? "ok" : "err",
(intmax_t)server.rdb_save_time_last, (intmax_t)server.rdb_save_time_last,
(intmax_t)((server.rdb_child_pid == -1) ? (intmax_t)((server.rdb_child_pid == -1) ?
-1 : time(NULL)-server.rdb_save_time_start), -1 : time(NULL)-server.rdb_save_time_start),
@ -2838,8 +2838,8 @@ sds genRedisInfoString(char *section) {
(intmax_t)server.aof_rewrite_time_last, (intmax_t)server.aof_rewrite_time_last,
(intmax_t)((server.aof_child_pid == -1) ? (intmax_t)((server.aof_child_pid == -1) ?
-1 : time(NULL)-server.aof_rewrite_time_start), -1 : time(NULL)-server.aof_rewrite_time_start),
(server.aof_lastbgrewrite_status == REDIS_OK) ? "ok" : "err", (server.aof_lastbgrewrite_status == C_OK) ? "ok" : "err",
(server.aof_last_write_status == REDIS_OK) ? "ok" : "err"); (server.aof_last_write_status == C_OK) ? "ok" : "err");
if (server.aof_state != REDIS_AOF_OFF) { if (server.aof_state != REDIS_AOF_OFF) {
info = sdscatprintf(info, info = sdscatprintf(info,
@ -3146,7 +3146,7 @@ void monitorCommand(client *c) {
* evict accordingly to the configured policy. * evict accordingly to the configured policy.
* *
* If all the bytes needed to return back under the limit were freed the * If all the bytes needed to return back under the limit were freed the
* function returns REDIS_OK, otherwise REDIS_ERR is returned, and the caller * function returns C_OK, otherwise C_ERR is returned, and the caller
* should block the execution of commands that will result in more memory * should block the execution of commands that will result in more memory
* used by the server. * used by the server.
* *
@ -3288,10 +3288,10 @@ int freeMemoryIfNeeded(void) {
} }
/* Check if we are over the memory limit. */ /* Check if we are over the memory limit. */
if (mem_used <= server.maxmemory) return REDIS_OK; if (mem_used <= server.maxmemory) return C_OK;
if (server.maxmemory_policy == REDIS_MAXMEMORY_NO_EVICTION) if (server.maxmemory_policy == REDIS_MAXMEMORY_NO_EVICTION)
return REDIS_ERR; /* We need to free memory, but policy forbids. */ return C_ERR; /* We need to free memory, but policy forbids. */
/* Compute how much memory we need to free. */ /* Compute how much memory we need to free. */
mem_tofree = mem_used - server.maxmemory; mem_tofree = mem_used - server.maxmemory;
@ -3417,12 +3417,12 @@ int freeMemoryIfNeeded(void) {
if (!keys_freed) { if (!keys_freed) {
latencyEndMonitor(latency); latencyEndMonitor(latency);
latencyAddSampleIfNeeded("eviction-cycle",latency); latencyAddSampleIfNeeded("eviction-cycle",latency);
return REDIS_ERR; /* nothing to free... */ return C_ERR; /* nothing to free... */
} }
} }
latencyEndMonitor(latency); latencyEndMonitor(latency);
latencyAddSampleIfNeeded("eviction-cycle",latency); latencyAddSampleIfNeeded("eviction-cycle",latency);
return REDIS_OK; return C_OK;
} }
/* =================================== Main! ================================ */ /* =================================== Main! ================================ */
@ -3613,10 +3613,10 @@ int checkForSentinelMode(int argc, char **argv) {
void loadDataFromDisk(void) { void loadDataFromDisk(void) {
long long start = ustime(); long long start = ustime();
if (server.aof_state == REDIS_AOF_ON) { if (server.aof_state == REDIS_AOF_ON) {
if (loadAppendOnlyFile(server.aof_filename) == REDIS_OK) if (loadAppendOnlyFile(server.aof_filename) == C_OK)
serverLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000); serverLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000);
} else { } else {
if (rdbLoad(server.rdb_filename) == REDIS_OK) { if (rdbLoad(server.rdb_filename) == C_OK) {
serverLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds", serverLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",
(float)(ustime()-start)/1000000); (float)(ustime()-start)/1000000);
} else if (errno != ENOENT) { } else if (errno != ENOENT) {
@ -3879,7 +3879,7 @@ int main(int argc, char **argv) {
checkTcpBacklogSettings(); checkTcpBacklogSettings();
loadDataFromDisk(); loadDataFromDisk();
if (server.cluster_enabled) { if (server.cluster_enabled) {
if (verifyClusterConfigWithData() == REDIS_ERR) { if (verifyClusterConfigWithData() == C_ERR) {
serverLog(REDIS_WARNING, serverLog(REDIS_WARNING,
"You can't have keys in a DB different than DB 0 when in " "You can't have keys in a DB different than DB 0 when in "
"Cluster mode. Exiting."); "Cluster mode. Exiting.");

View File

@ -71,8 +71,8 @@ typedef long long mstime_t; /* millisecond time type. */
#include "crc64.h" #include "crc64.h"
/* Error codes */ /* Error codes */
#define REDIS_OK 0 #define C_OK 0
#define REDIS_ERR -1 #define C_ERR -1
/* Static server configuration */ /* Static server configuration */
#define CONFIG_DEFAULT_HZ 10 /* Time interrupt calls/sec. */ #define CONFIG_DEFAULT_HZ 10 /* Time interrupt calls/sec. */
@ -770,10 +770,10 @@ struct redisServer {
time_t aof_last_fsync; /* UNIX time of last fsync() */ time_t aof_last_fsync; /* UNIX time of last fsync() */
time_t aof_rewrite_time_last; /* Time used by last AOF rewrite run. */ time_t aof_rewrite_time_last; /* Time used by last AOF rewrite run. */
time_t aof_rewrite_time_start; /* Current AOF rewrite start time. */ time_t aof_rewrite_time_start; /* Current AOF rewrite start time. */
int aof_lastbgrewrite_status; /* REDIS_OK or REDIS_ERR */ int aof_lastbgrewrite_status; /* C_OK or C_ERR */
unsigned long aof_delayed_fsync; /* delayed AOF fsync() counter */ unsigned long aof_delayed_fsync; /* delayed AOF fsync() counter */
int aof_rewrite_incremental_fsync;/* fsync incrementally while rewriting? */ int aof_rewrite_incremental_fsync;/* fsync incrementally while rewriting? */
int aof_last_write_status; /* REDIS_OK or REDIS_ERR */ int aof_last_write_status; /* C_OK or C_ERR */
int aof_last_write_errno; /* Valid if aof_last_write_status is ERR */ int aof_last_write_errno; /* Valid if aof_last_write_status is ERR */
int aof_load_truncated; /* Don't stop on unexpected AOF EOF. */ int aof_load_truncated; /* Don't stop on unexpected AOF EOF. */
/* AOF pipes used to communicate between parent and child during rewrite. */ /* AOF pipes used to communicate between parent and child during rewrite. */
@ -800,7 +800,7 @@ struct redisServer {
time_t rdb_save_time_last; /* Time used by last RDB save run. */ time_t rdb_save_time_last; /* Time used by last RDB save run. */
time_t rdb_save_time_start; /* Current RDB save start time. */ time_t rdb_save_time_start; /* Current RDB save start time. */
int rdb_child_type; /* Type of save by active child. */ int rdb_child_type; /* Type of save by active child. */
int lastbgsave_status; /* REDIS_OK or REDIS_ERR */ int lastbgsave_status; /* C_OK or C_ERR */
int stop_writes_on_bgsave_err; /* Don't allow writes if can't BGSAVE */ int stop_writes_on_bgsave_err; /* Don't allow writes if can't BGSAVE */
int rdb_pipe_write_result_to_parent; /* RDB pipes used to return the state */ int rdb_pipe_write_result_to_parent; /* RDB pipes used to return the state */
int rdb_pipe_read_result_from_child; /* of each slave in diskless SYNC. */ int rdb_pipe_read_result_from_child; /* of each slave in diskless SYNC. */

View File

@ -143,7 +143,7 @@ void slowlogCommand(client *c) {
slowlogEntry *se; slowlogEntry *se;
if (c->argc == 3 && if (c->argc == 3 &&
getLongFromObjectOrReply(c,c->argv[2],&count,NULL) != REDIS_OK) getLongFromObjectOrReply(c,c->argv[2],&count,NULL) != C_OK)
return; return;
listRewind(server.slowlog,&li); listRewind(server.slowlog,&li);

View File

@ -233,9 +233,9 @@ void sortCommand(client *c) {
alpha = 1; alpha = 1;
} else if (!strcasecmp(c->argv[j]->ptr,"limit") && leftargs >= 2) { } else if (!strcasecmp(c->argv[j]->ptr,"limit") && leftargs >= 2) {
if ((getLongFromObjectOrReply(c, c->argv[j+1], &limit_start, NULL) if ((getLongFromObjectOrReply(c, c->argv[j+1], &limit_start, NULL)
!= REDIS_OK) || != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[j+2], &limit_count, NULL) (getLongFromObjectOrReply(c, c->argv[j+2], &limit_count, NULL)
!= REDIS_OK)) != C_OK))
{ {
syntax_error++; syntax_error++;
break; break;

View File

@ -266,7 +266,7 @@ int hashTypeDelete(robj *o, robj *field) {
decrRefCount(field); decrRefCount(field);
} else if (o->encoding == OBJ_ENCODING_HT) { } else if (o->encoding == OBJ_ENCODING_HT) {
if (dictDelete((dict*)o->ptr, field) == REDIS_OK) { if (dictDelete((dict*)o->ptr, field) == C_OK) {
deleted = 1; deleted = 1;
/* Always check if the dictionary needs a resize after a delete. */ /* Always check if the dictionary needs a resize after a delete. */
@ -320,8 +320,8 @@ void hashTypeReleaseIterator(hashTypeIterator *hi) {
zfree(hi); zfree(hi);
} }
/* Move to the next entry in the hash. Return REDIS_OK when the next entry /* Move to the next entry in the hash. Return C_OK when the next entry
* could be found and REDIS_ERR when the iterator reaches the end. */ * could be found and C_ERR when the iterator reaches the end. */
int hashTypeNext(hashTypeIterator *hi) { int hashTypeNext(hashTypeIterator *hi) {
if (hi->encoding == OBJ_ENCODING_ZIPLIST) { if (hi->encoding == OBJ_ENCODING_ZIPLIST) {
unsigned char *zl; unsigned char *zl;
@ -340,7 +340,7 @@ int hashTypeNext(hashTypeIterator *hi) {
serverAssert(vptr != NULL); serverAssert(vptr != NULL);
fptr = ziplistNext(zl, vptr); fptr = ziplistNext(zl, vptr);
} }
if (fptr == NULL) return REDIS_ERR; if (fptr == NULL) return C_ERR;
/* Grab pointer to the value (fptr points to the field) */ /* Grab pointer to the value (fptr points to the field) */
vptr = ziplistNext(zl, fptr); vptr = ziplistNext(zl, fptr);
@ -350,11 +350,11 @@ int hashTypeNext(hashTypeIterator *hi) {
hi->fptr = fptr; hi->fptr = fptr;
hi->vptr = vptr; hi->vptr = vptr;
} else if (hi->encoding == OBJ_ENCODING_HT) { } else if (hi->encoding == OBJ_ENCODING_HT) {
if ((hi->de = dictNext(hi->di)) == NULL) return REDIS_ERR; if ((hi->de = dictNext(hi->di)) == NULL) return C_ERR;
} else { } else {
redisPanic("Unknown hash encoding"); redisPanic("Unknown hash encoding");
} }
return REDIS_OK; return C_OK;
} }
/* Get the field or value at iterator cursor, for an iterator on a hash value /* Get the field or value at iterator cursor, for an iterator on a hash value
@ -443,7 +443,7 @@ void hashTypeConvertZiplist(robj *o, int enc) {
hi = hashTypeInitIterator(o); hi = hashTypeInitIterator(o);
dict = dictCreate(&hashDictType, NULL); dict = dictCreate(&hashDictType, NULL);
while (hashTypeNext(hi) != REDIS_ERR) { while (hashTypeNext(hi) != C_ERR) {
robj *field, *value; robj *field, *value;
field = hashTypeCurrentObject(hi, OBJ_HASH_KEY); field = hashTypeCurrentObject(hi, OBJ_HASH_KEY);
@ -539,11 +539,11 @@ void hincrbyCommand(client *c) {
long long value, incr, oldvalue; long long value, incr, oldvalue;
robj *o, *current, *new; robj *o, *current, *new;
if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
if ((current = hashTypeGetObject(o,c->argv[2])) != NULL) { if ((current = hashTypeGetObject(o,c->argv[2])) != NULL) {
if (getLongLongFromObjectOrReply(c,current,&value, if (getLongLongFromObjectOrReply(c,current,&value,
"hash value is not an integer") != REDIS_OK) { "hash value is not an integer") != C_OK) {
decrRefCount(current); decrRefCount(current);
return; return;
} }
@ -573,11 +573,11 @@ void hincrbyfloatCommand(client *c) {
double long value, incr; double long value, incr;
robj *o, *current, *new, *aux; robj *o, *current, *new, *aux;
if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return; if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
if ((current = hashTypeGetObject(o,c->argv[2])) != NULL) { if ((current = hashTypeGetObject(o,c->argv[2])) != NULL) {
if (getLongDoubleFromObjectOrReply(c,current,&value, if (getLongDoubleFromObjectOrReply(c,current,&value,
"hash value is not a valid float") != REDIS_OK) { "hash value is not a valid float") != C_OK) {
decrRefCount(current); decrRefCount(current);
return; return;
} }
@ -756,7 +756,7 @@ void genericHgetallCommand(client *c, int flags) {
addReplyMultiBulkLen(c, length); addReplyMultiBulkLen(c, length);
hi = hashTypeInitIterator(o); hi = hashTypeInitIterator(o);
while (hashTypeNext(hi) != REDIS_ERR) { while (hashTypeNext(hi) != C_ERR) {
if (flags & OBJ_HASH_KEY) { if (flags & OBJ_HASH_KEY) {
addHashIteratorCursorToReply(c, hi, OBJ_HASH_KEY); addHashIteratorCursorToReply(c, hi, OBJ_HASH_KEY);
count++; count++;
@ -795,7 +795,7 @@ void hscanCommand(client *c) {
robj *o; robj *o;
unsigned long cursor; unsigned long cursor;
if (parseScanCursorOrReply(c,c->argv[2],&cursor) == REDIS_ERR) return; if (parseScanCursorOrReply(c,c->argv[2],&cursor) == C_ERR) return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL || if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL ||
checkType(c,o,OBJ_HASH)) return; checkType(c,o,OBJ_HASH)) return;
scanGenericCommand(c,o,cursor); scanGenericCommand(c,o,cursor);

View File

@ -308,7 +308,7 @@ void lindexCommand(client *c) {
long index; long index;
robj *value = NULL; robj *value = NULL;
if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
return; return;
if (o->encoding == OBJ_ENCODING_QUICKLIST) { if (o->encoding == OBJ_ENCODING_QUICKLIST) {
@ -335,7 +335,7 @@ void lsetCommand(client *c) {
long index; long index;
robj *value = c->argv[3]; robj *value = c->argv[3];
if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
return; return;
if (o->encoding == OBJ_ENCODING_QUICKLIST) { if (o->encoding == OBJ_ENCODING_QUICKLIST) {
@ -390,8 +390,8 @@ void lrangeCommand(client *c) {
robj *o; robj *o;
long start, end, llen, rangelen; long start, end, llen, rangelen;
if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL
|| checkType(c,o,OBJ_LIST)) return; || checkType(c,o,OBJ_LIST)) return;
@ -436,8 +436,8 @@ void ltrimCommand(client *c) {
robj *o; robj *o;
long start, end, llen, ltrim, rtrim; long start, end, llen, ltrim, rtrim;
if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL || if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL ||
checkType(c,o,OBJ_LIST)) return; checkType(c,o,OBJ_LIST)) return;
@ -484,7 +484,7 @@ void lremCommand(client *c) {
long toremove; long toremove;
long removed = 0; long removed = 0;
if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != C_OK))
return; return;
subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero); subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero);
@ -716,8 +716,8 @@ void signalListAsReady(redisDb *db, robj *key) {
* 'value' element was popped fron the head (BLPOP) or tail (BRPOP) so that * 'value' element was popped fron the head (BLPOP) or tail (BRPOP) so that
* we can propagate the command properly. * we can propagate the command properly.
* *
* The function returns REDIS_OK if we are able to serve the client, otherwise * The function returns C_OK if we are able to serve the client, otherwise
* REDIS_ERR is returned to signal the caller that the list POP operation * C_ERR is returned to signal the caller that the list POP operation
* should be undone as the client was not served: This only happens for * should be undone as the client was not served: This only happens for
* BRPOPLPUSH that fails to push the value to the destination key as it is * BRPOPLPUSH that fails to push the value to the destination key as it is
* of the wrong type. */ * of the wrong type. */
@ -765,10 +765,10 @@ int serveClientBlockedOnList(client *receiver, robj *key, robj *dstkey, redisDb
} else { } else {
/* BRPOPLPUSH failed because of wrong /* BRPOPLPUSH failed because of wrong
* destination type. */ * destination type. */
return REDIS_ERR; return C_ERR;
} }
} }
return REDIS_OK; return C_OK;
} }
/* This function should be called by Redis every time a single command, /* This function should be called by Redis every time a single command,
@ -831,7 +831,7 @@ void handleClientsBlockedOnLists(void) {
if (serveClientBlockedOnList(receiver, if (serveClientBlockedOnList(receiver,
rl->key,dstkey,rl->db,value, rl->key,dstkey,rl->db,value,
where) == REDIS_ERR) where) == C_ERR)
{ {
/* If we failed serving the client we need /* If we failed serving the client we need
* to also undo the POP operation. */ * to also undo the POP operation. */
@ -869,7 +869,7 @@ void blockingPopGenericCommand(client *c, int where) {
int j; int j;
if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS) if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS)
!= REDIS_OK) return; != C_OK) return;
for (j = 1; j < c->argc-1; j++) { for (j = 1; j < c->argc-1; j++) {
o = lookupKeyWrite(c->db,c->argv[j]); o = lookupKeyWrite(c->db,c->argv[j]);
@ -931,7 +931,7 @@ void brpoplpushCommand(client *c) {
mstime_t timeout; mstime_t timeout;
if (getTimeoutFromObjectOrReply(c,c->argv[3],&timeout,UNIT_SECONDS) if (getTimeoutFromObjectOrReply(c,c->argv[3],&timeout,UNIT_SECONDS)
!= REDIS_OK) return; != C_OK) return;
robj *key = lookupKeyWrite(c->db, c->argv[1]); robj *key = lookupKeyWrite(c->db, c->argv[1]);

View File

@ -40,7 +40,7 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum,
* an integer-encodable value, an intset will be returned. Otherwise a regular * an integer-encodable value, an intset will be returned. Otherwise a regular
* hash table. */ * hash table. */
robj *setTypeCreate(robj *value) { robj *setTypeCreate(robj *value) {
if (isObjectRepresentableAsLongLong(value,NULL) == REDIS_OK) if (isObjectRepresentableAsLongLong(value,NULL) == C_OK)
return createIntsetObject(); return createIntsetObject();
return createSetObject(); return createSetObject();
} }
@ -58,7 +58,7 @@ int setTypeAdd(robj *subject, robj *value) {
return 1; return 1;
} }
} else if (subject->encoding == OBJ_ENCODING_INTSET) { } else if (subject->encoding == OBJ_ENCODING_INTSET) {
if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) {
uint8_t success = 0; uint8_t success = 0;
subject->ptr = intsetAdd(subject->ptr,llval,&success); subject->ptr = intsetAdd(subject->ptr,llval,&success);
if (success) { if (success) {
@ -93,7 +93,7 @@ int setTypeRemove(robj *setobj, robj *value) {
return 1; return 1;
} }
} else if (setobj->encoding == OBJ_ENCODING_INTSET) { } else if (setobj->encoding == OBJ_ENCODING_INTSET) {
if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) {
int success; int success;
setobj->ptr = intsetRemove(setobj->ptr,llval,&success); setobj->ptr = intsetRemove(setobj->ptr,llval,&success);
if (success) return 1; if (success) return 1;
@ -109,7 +109,7 @@ int setTypeIsMember(robj *subject, robj *value) {
if (subject->encoding == OBJ_ENCODING_HT) { if (subject->encoding == OBJ_ENCODING_HT) {
return dictFind((dict*)subject->ptr,value) != NULL; return dictFind((dict*)subject->ptr,value) != NULL;
} else if (subject->encoding == OBJ_ENCODING_INTSET) { } else if (subject->encoding == OBJ_ENCODING_INTSET) {
if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) {
return intsetFind((intset*)subject->ptr,llval); return intsetFind((intset*)subject->ptr,llval);
} }
} else { } else {
@ -413,7 +413,7 @@ void spopWithCountCommand(client *c) {
robj *set; robj *set;
/* Get the count argument */ /* Get the count argument */
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != REDIS_OK) return; if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (l >= 0) { if (l >= 0) {
count = (unsigned) l; count = (unsigned) l;
} else { } else {
@ -626,7 +626,7 @@ void srandmemberWithCountCommand(client *c) {
dict *d; dict *d;
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != REDIS_OK) return; if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (l >= 0) { if (l >= 0) {
count = (unsigned) l; count = (unsigned) l;
} else { } else {
@ -1112,7 +1112,7 @@ void sscanCommand(client *c) {
robj *set; robj *set;
unsigned long cursor; unsigned long cursor;
if (parseScanCursorOrReply(c,c->argv[2],&cursor) == REDIS_ERR) return; if (parseScanCursorOrReply(c,c->argv[2],&cursor) == C_ERR) return;
if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL || if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL ||
checkType(c,set,OBJ_SET)) return; checkType(c,set,OBJ_SET)) return;
scanGenericCommand(c,set,cursor); scanGenericCommand(c,set,cursor);

View File

@ -37,9 +37,9 @@
static int checkStringLength(client *c, long long size) { static int checkStringLength(client *c, long long size) {
if (size > 512*1024*1024) { if (size > 512*1024*1024) {
addReplyError(c,"string exceeds maximum allowed size (512MB)"); addReplyError(c,"string exceeds maximum allowed size (512MB)");
return REDIS_ERR; return C_ERR;
} }
return REDIS_OK; return C_OK;
} }
/* The setGenericCommand() function implements the SET operation with different /* The setGenericCommand() function implements the SET operation with different
@ -68,7 +68,7 @@ void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire,
long long milliseconds = 0; /* initialized to avoid any harmness warning */ long long milliseconds = 0; /* initialized to avoid any harmness warning */
if (expire) { if (expire) {
if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != C_OK)
return; return;
if (milliseconds <= 0) { if (milliseconds <= 0) {
addReplyErrorFormat(c,"invalid expire time in %s",c->cmd->name); addReplyErrorFormat(c,"invalid expire time in %s",c->cmd->name);
@ -158,14 +158,14 @@ int getGenericCommand(client *c) {
robj *o; robj *o;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL) if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL)
return REDIS_OK; return C_OK;
if (o->type != OBJ_STRING) { if (o->type != OBJ_STRING) {
addReply(c,shared.wrongtypeerr); addReply(c,shared.wrongtypeerr);
return REDIS_ERR; return C_ERR;
} else { } else {
addReplyBulk(c,o); addReplyBulk(c,o);
return REDIS_OK; return C_OK;
} }
} }
@ -174,7 +174,7 @@ void getCommand(client *c) {
} }
void getsetCommand(client *c) { void getsetCommand(client *c) {
if (getGenericCommand(c) == REDIS_ERR) return; if (getGenericCommand(c) == C_ERR) return;
c->argv[2] = tryObjectEncoding(c->argv[2]); c->argv[2] = tryObjectEncoding(c->argv[2]);
setKey(c->db,c->argv[1],c->argv[2]); setKey(c->db,c->argv[1],c->argv[2]);
notifyKeyspaceEvent(REDIS_NOTIFY_STRING,"set",c->argv[1],c->db->id); notifyKeyspaceEvent(REDIS_NOTIFY_STRING,"set",c->argv[1],c->db->id);
@ -186,7 +186,7 @@ void setrangeCommand(client *c) {
long offset; long offset;
sds value = c->argv[3]->ptr; sds value = c->argv[3]->ptr;
if (getLongFromObjectOrReply(c,c->argv[2],&offset,NULL) != REDIS_OK) if (getLongFromObjectOrReply(c,c->argv[2],&offset,NULL) != C_OK)
return; return;
if (offset < 0) { if (offset < 0) {
@ -203,7 +203,7 @@ void setrangeCommand(client *c) {
} }
/* Return when the resulting string exceeds allowed size */ /* Return when the resulting string exceeds allowed size */
if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK) if (checkStringLength(c,offset+sdslen(value)) != C_OK)
return; return;
o = createObject(OBJ_STRING,sdsnewlen(NULL, offset+sdslen(value))); o = createObject(OBJ_STRING,sdsnewlen(NULL, offset+sdslen(value)));
@ -223,7 +223,7 @@ void setrangeCommand(client *c) {
} }
/* Return when the resulting string exceeds allowed size */ /* Return when the resulting string exceeds allowed size */
if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK) if (checkStringLength(c,offset+sdslen(value)) != C_OK)
return; return;
/* Create a copy when the object is shared or encoded. */ /* Create a copy when the object is shared or encoded. */
@ -247,9 +247,9 @@ void getrangeCommand(client *c) {
char *str, llbuf[32]; char *str, llbuf[32];
size_t strlen; size_t strlen;
if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK)
return; return;
if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK) if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK)
return; return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL || if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL ||
checkType(c,o,OBJ_STRING)) return; checkType(c,o,OBJ_STRING)) return;
@ -340,7 +340,7 @@ void incrDecrCommand(client *c, long long incr) {
o = lookupKeyWrite(c->db,c->argv[1]); o = lookupKeyWrite(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,OBJ_STRING)) return; if (o != NULL && checkType(c,o,OBJ_STRING)) return;
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c,o,&value,NULL) != C_OK) return;
oldvalue = value; oldvalue = value;
if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) || if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
@ -383,14 +383,14 @@ void decrCommand(client *c) {
void incrbyCommand(client *c) { void incrbyCommand(client *c) {
long long incr; long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return;
incrDecrCommand(c,incr); incrDecrCommand(c,incr);
} }
void decrbyCommand(client *c) { void decrbyCommand(client *c) {
long long incr; long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != REDIS_OK) return; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return;
incrDecrCommand(c,-incr); incrDecrCommand(c,-incr);
} }
@ -400,8 +400,8 @@ void incrbyfloatCommand(client *c) {
o = lookupKeyWrite(c->db,c->argv[1]); o = lookupKeyWrite(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,OBJ_STRING)) return; if (o != NULL && checkType(c,o,OBJ_STRING)) return;
if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != REDIS_OK || if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != C_OK ||
getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != REDIS_OK) getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != C_OK)
return; return;
value += incr; value += incr;
@ -447,7 +447,7 @@ void appendCommand(client *c) {
/* "append" is an argument, so always an sds */ /* "append" is an argument, so always an sds */
append = c->argv[2]; append = c->argv[2];
totlen = stringObjectLen(o)+sdslen(append->ptr); totlen = stringObjectLen(o)+sdslen(append->ptr);
if (checkStringLength(c,totlen) != REDIS_OK) if (checkStringLength(c,totlen) != C_OK)
return; return;
/* Append the value */ /* Append the value */

View File

@ -440,11 +440,11 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) {
} else { } else {
if (((char*)min->ptr)[0] == '(') { if (((char*)min->ptr)[0] == '(') {
spec->min = strtod((char*)min->ptr+1,&eptr); spec->min = strtod((char*)min->ptr+1,&eptr);
if (eptr[0] != '\0' || isnan(spec->min)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->min)) return C_ERR;
spec->minex = 1; spec->minex = 1;
} else { } else {
spec->min = strtod((char*)min->ptr,&eptr); spec->min = strtod((char*)min->ptr,&eptr);
if (eptr[0] != '\0' || isnan(spec->min)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->min)) return C_ERR;
} }
} }
if (max->encoding == OBJ_ENCODING_INT) { if (max->encoding == OBJ_ENCODING_INT) {
@ -452,15 +452,15 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) {
} else { } else {
if (((char*)max->ptr)[0] == '(') { if (((char*)max->ptr)[0] == '(') {
spec->max = strtod((char*)max->ptr+1,&eptr); spec->max = strtod((char*)max->ptr+1,&eptr);
if (eptr[0] != '\0' || isnan(spec->max)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->max)) return C_ERR;
spec->maxex = 1; spec->maxex = 1;
} else { } else {
spec->max = strtod((char*)max->ptr,&eptr); spec->max = strtod((char*)max->ptr,&eptr);
if (eptr[0] != '\0' || isnan(spec->max)) return REDIS_ERR; if (eptr[0] != '\0' || isnan(spec->max)) return C_ERR;
} }
} }
return REDIS_OK; return C_OK;
} }
/* ------------------------ Lexicographic ranges ---------------------------- */ /* ------------------------ Lexicographic ranges ---------------------------- */
@ -473,64 +473,64 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) {
* *
* If the string is valid the *dest pointer is set to the redis object * If the string is valid the *dest pointer is set to the redis object
* that will be used for the comparision, and ex will be set to 0 or 1 * that will be used for the comparision, and ex will be set to 0 or 1
* respectively if the item is exclusive or inclusive. REDIS_OK will be * respectively if the item is exclusive or inclusive. C_OK will be
* returned. * returned.
* *
* If the string is not a valid range REDIS_ERR is returned, and the value * If the string is not a valid range C_ERR is returned, and the value
* of *dest and *ex is undefined. */ * of *dest and *ex is undefined. */
int zslParseLexRangeItem(robj *item, robj **dest, int *ex) { int zslParseLexRangeItem(robj *item, robj **dest, int *ex) {
char *c = item->ptr; char *c = item->ptr;
switch(c[0]) { switch(c[0]) {
case '+': case '+':
if (c[1] != '\0') return REDIS_ERR; if (c[1] != '\0') return C_ERR;
*ex = 0; *ex = 0;
*dest = shared.maxstring; *dest = shared.maxstring;
incrRefCount(shared.maxstring); incrRefCount(shared.maxstring);
return REDIS_OK; return C_OK;
case '-': case '-':
if (c[1] != '\0') return REDIS_ERR; if (c[1] != '\0') return C_ERR;
*ex = 0; *ex = 0;
*dest = shared.minstring; *dest = shared.minstring;
incrRefCount(shared.minstring); incrRefCount(shared.minstring);
return REDIS_OK; return C_OK;
case '(': case '(':
*ex = 1; *ex = 1;
*dest = createStringObject(c+1,sdslen(c)-1); *dest = createStringObject(c+1,sdslen(c)-1);
return REDIS_OK; return C_OK;
case '[': case '[':
*ex = 0; *ex = 0;
*dest = createStringObject(c+1,sdslen(c)-1); *dest = createStringObject(c+1,sdslen(c)-1);
return REDIS_OK; return C_OK;
default: default:
return REDIS_ERR; return C_ERR;
} }
} }
/* Populate the rangespec according to the objects min and max. /* Populate the rangespec according to the objects min and max.
* *
* Return REDIS_OK on success. On error REDIS_ERR is returned. * Return C_OK on success. On error C_ERR is returned.
* When OK is returned the structure must be freed with zslFreeLexRange(), * When OK is returned the structure must be freed with zslFreeLexRange(),
* otherwise no release is needed. */ * otherwise no release is needed. */
static int zslParseLexRange(robj *min, robj *max, zlexrangespec *spec) { static int zslParseLexRange(robj *min, robj *max, zlexrangespec *spec) {
/* The range can't be valid if objects are integer encoded. /* The range can't be valid if objects are integer encoded.
* Every item must start with ( or [. */ * Every item must start with ( or [. */
if (min->encoding == OBJ_ENCODING_INT || if (min->encoding == OBJ_ENCODING_INT ||
max->encoding == OBJ_ENCODING_INT) return REDIS_ERR; max->encoding == OBJ_ENCODING_INT) return C_ERR;
spec->min = spec->max = NULL; spec->min = spec->max = NULL;
if (zslParseLexRangeItem(min, &spec->min, &spec->minex) == REDIS_ERR || if (zslParseLexRangeItem(min, &spec->min, &spec->minex) == C_ERR ||
zslParseLexRangeItem(max, &spec->max, &spec->maxex) == REDIS_ERR) { zslParseLexRangeItem(max, &spec->max, &spec->maxex) == C_ERR) {
if (spec->min) decrRefCount(spec->min); if (spec->min) decrRefCount(spec->min);
if (spec->max) decrRefCount(spec->max); if (spec->max) decrRefCount(spec->max);
return REDIS_ERR; return C_ERR;
} else { } else {
return REDIS_OK; return C_OK;
} }
} }
/* Free a lex range structure, must be called only after zelParseLexRange() /* Free a lex range structure, must be called only after zelParseLexRange()
* populated the structure with success (REDIS_OK returned). */ * populated the structure with success (C_OK returned). */
void zslFreeLexRange(zlexrangespec *spec) { void zslFreeLexRange(zlexrangespec *spec) {
decrRefCount(spec->min); decrRefCount(spec->min);
decrRefCount(spec->max); decrRefCount(spec->max);
@ -1167,23 +1167,23 @@ void zsetConvert(robj *zobj, int encoding) {
} }
/* Return (by reference) the score of the specified member of the sorted set /* Return (by reference) the score of the specified member of the sorted set
* storing it into *score. If the element does not exist REDIS_ERR is returned * storing it into *score. If the element does not exist C_ERR is returned
* otherwise REDIS_OK is returned and *score is correctly populated. * otherwise C_OK is returned and *score is correctly populated.
* If 'zobj' or 'member' is NULL, REDIS_ERR is returned. */ * If 'zobj' or 'member' is NULL, C_ERR is returned. */
int zsetScore(robj *zobj, robj *member, double *score) { int zsetScore(robj *zobj, robj *member, double *score) {
if (!zobj || !member) return REDIS_ERR; if (!zobj || !member) return C_ERR;
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) { if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
if (zzlFind(zobj->ptr, member, score) == NULL) return REDIS_ERR; if (zzlFind(zobj->ptr, member, score) == NULL) return C_ERR;
} else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) { } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
zset *zs = zobj->ptr; zset *zs = zobj->ptr;
dictEntry *de = dictFind(zs->dict, member); dictEntry *de = dictFind(zs->dict, member);
if (de == NULL) return REDIS_ERR; if (de == NULL) return C_ERR;
*score = *(double*)dictGetVal(de); *score = *(double*)dictGetVal(de);
} else { } else {
redisPanic("Unknown sorted set encoding"); redisPanic("Unknown sorted set encoding");
} }
return REDIS_OK; return C_OK;
} }
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
@ -1260,7 +1260,7 @@ void zaddGenericCommand(client *c, int flags) {
scores = zmalloc(sizeof(double)*elements); scores = zmalloc(sizeof(double)*elements);
for (j = 0; j < elements; j++) { for (j = 0; j < elements; j++) {
if (getDoubleFromObjectOrReply(c,c->argv[scoreidx+j*2],&scores[j],NULL) if (getDoubleFromObjectOrReply(c,c->argv[scoreidx+j*2],&scores[j],NULL)
!= REDIS_OK) goto cleanup; != C_OK) goto cleanup;
} }
/* Lookup the key and create the sorted set if does not exist. */ /* Lookup the key and create the sorted set if does not exist. */
@ -1471,16 +1471,16 @@ void zremrangeGenericCommand(client *c, int rangetype) {
/* Step 1: Parse the range. */ /* Step 1: Parse the range. */
if (rangetype == ZRANGE_RANK) { if (rangetype == ZRANGE_RANK) {
if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) ||
(getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK)) (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK))
return; return;
} else if (rangetype == ZRANGE_SCORE) { } else if (rangetype == ZRANGE_SCORE) {
if (zslParseRange(c->argv[2],c->argv[3],&range) != REDIS_OK) { if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
addReplyError(c,"min or max is not a float"); addReplyError(c,"min or max is not a float");
return; return;
} }
} else if (rangetype == ZRANGE_LEX) { } else if (rangetype == ZRANGE_LEX) {
if (zslParseLexRange(c->argv[2],c->argv[3],&lexrange) != REDIS_OK) { if (zslParseLexRange(c->argv[2],c->argv[3],&lexrange) != C_OK) {
addReplyError(c,"min or max not valid string range item"); addReplyError(c,"min or max not valid string range item");
return; return;
} }
@ -1936,7 +1936,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
int touched = 0; int touched = 0;
/* expect setnum input keys to be given */ /* expect setnum input keys to be given */
if ((getLongFromObjectOrReply(c, c->argv[2], &setnum, NULL) != REDIS_OK)) if ((getLongFromObjectOrReply(c, c->argv[2], &setnum, NULL) != C_OK))
return; return;
if (setnum < 1) { if (setnum < 1) {
@ -1982,7 +1982,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
j++; remaining--; j++; remaining--;
for (i = 0; i < setnum; i++, j++, remaining--) { for (i = 0; i < setnum; i++, j++, remaining--) {
if (getDoubleFromObjectOrReply(c,c->argv[j],&src[i].weight, if (getDoubleFromObjectOrReply(c,c->argv[j],&src[i].weight,
"weight value is not a float") != REDIS_OK) "weight value is not a float") != C_OK)
{ {
zfree(src); zfree(src);
return; return;
@ -2180,8 +2180,8 @@ void zrangeGenericCommand(client *c, int reverse) {
int llen; int llen;
int rangelen; int rangelen;
if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return;
if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) { if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) {
withscores = 1; withscores = 1;
@ -2301,7 +2301,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
minidx = 2; maxidx = 3; minidx = 2; maxidx = 3;
} }
if (zslParseRange(c->argv[minidx],c->argv[maxidx],&range) != REDIS_OK) { if (zslParseRange(c->argv[minidx],c->argv[maxidx],&range) != C_OK) {
addReplyError(c,"min or max is not a float"); addReplyError(c,"min or max is not a float");
return; return;
} }
@ -2317,8 +2317,8 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
pos++; remaining--; pos++; remaining--;
withscores = 1; withscores = 1;
} else if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) { } else if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return;
pos += 3; remaining -= 3; pos += 3; remaining -= 3;
} else { } else {
addReply(c,shared.syntaxerr); addReply(c,shared.syntaxerr);
@ -2483,7 +2483,7 @@ void zcountCommand(client *c) {
int count = 0; int count = 0;
/* Parse the range arguments */ /* Parse the range arguments */
if (zslParseRange(c->argv[2],c->argv[3],&range) != REDIS_OK) { if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
addReplyError(c,"min or max is not a float"); addReplyError(c,"min or max is not a float");
return; return;
} }
@ -2560,7 +2560,7 @@ void zlexcountCommand(client *c) {
int count = 0; int count = 0;
/* Parse the range arguments */ /* Parse the range arguments */
if (zslParseLexRange(c->argv[2],c->argv[3],&range) != REDIS_OK) { if (zslParseLexRange(c->argv[2],c->argv[3],&range) != C_OK) {
addReplyError(c,"min or max not valid string range item"); addReplyError(c,"min or max not valid string range item");
return; return;
} }
@ -2651,7 +2651,7 @@ void genericZrangebylexCommand(client *c, int reverse) {
minidx = 2; maxidx = 3; minidx = 2; maxidx = 3;
} }
if (zslParseLexRange(c->argv[minidx],c->argv[maxidx],&range) != REDIS_OK) { if (zslParseLexRange(c->argv[minidx],c->argv[maxidx],&range) != C_OK) {
addReplyError(c,"min or max not valid string range item"); addReplyError(c,"min or max not valid string range item");
return; return;
} }
@ -2664,8 +2664,8 @@ void genericZrangebylexCommand(client *c, int reverse) {
while (remaining) { while (remaining) {
if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) { if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) {
if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) || if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) ||
(getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return; (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return;
pos += 3; remaining -= 3; pos += 3; remaining -= 3;
} else { } else {
zslFreeLexRange(&range); zslFreeLexRange(&range);
@ -2835,7 +2835,7 @@ void zscoreCommand(client *c) {
if ((zobj = lookupKeyReadOrReply(c,key,shared.nullbulk)) == NULL || if ((zobj = lookupKeyReadOrReply(c,key,shared.nullbulk)) == NULL ||
checkType(c,zobj,OBJ_ZSET)) return; checkType(c,zobj,OBJ_ZSET)) return;
if (zsetScore(zobj,c->argv[2],&score) == REDIS_ERR) { if (zsetScore(zobj,c->argv[2],&score) == C_ERR) {
addReply(c,shared.nullbulk); addReply(c,shared.nullbulk);
} else { } else {
addReplyDouble(c,score); addReplyDouble(c,score);
@ -2916,7 +2916,7 @@ void zscanCommand(client *c) {
robj *o; robj *o;
unsigned long cursor; unsigned long cursor;
if (parseScanCursorOrReply(c,c->argv[2],&cursor) == REDIS_ERR) return; if (parseScanCursorOrReply(c,c->argv[2],&cursor) == C_ERR) return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL || if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptyscan)) == NULL ||
checkType(c,o,OBJ_ZSET)) return; checkType(c,o,OBJ_ZSET)) return;
scanGenericCommand(c,o,cursor); scanGenericCommand(c,o,cursor);