diff --git a/src/aof.c b/src/aof.c index 0c23818d1..2c143dd67 100644 --- a/src/aof.c +++ b/src/aof.c @@ -238,17 +238,17 @@ int startAppendOnly(void) { serverAssert(server.aof_state == REDIS_AOF_OFF); 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)); - return REDIS_ERR; + return C_ERR; } - if (rewriteAppendOnlyFileBackground() == REDIS_ERR) { + if (rewriteAppendOnlyFileBackground() == C_ERR) { 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."); - return REDIS_ERR; + return C_ERR; } /* We correctly switched on AOF, now wait for the rewrite to be complete * in order to append data on disk. */ server.aof_state = REDIS_AOF_WAIT_REWRITE; - return REDIS_OK; + return C_OK; } /* 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 * set an error to stop accepting writes as long as the error * 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 * was no way to undo it with ftruncate(2). */ @@ -393,10 +393,10 @@ void flushAppendOnlyFile(int force) { } else { /* Successful write(2). If AOF was in error state, restore the * 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, "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; @@ -593,8 +593,8 @@ void freeFakeClient(struct client *c) { zfree(c); } -/* Replay the append log file. On success REDIS_OK is returned. On non fatal - * error (the append only file is zero-length) REDIS_ERR is returned. On +/* Replay the append log file. On success C_OK is returned. On non fatal + * error (the append only file is zero-length) C_ERR is returned. On * fatal error an error message is logged and the program exists. */ int loadAppendOnlyFile(char *filename) { struct client *fakeClient; @@ -607,7 +607,7 @@ int loadAppendOnlyFile(char *filename) { if (fp && redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) { server.aof_current_size = 0; fclose(fp); - return REDIS_ERR; + return C_ERR; } 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 (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); freeFakeClient(fakeClient); server.aof_state = old_aof_state; stopLoading(); aofUpdateCurrentSize(); 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. */ if (!feof(fp)) { @@ -952,7 +952,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) { long long count = 0, items = hashTypeLength(o); hi = hashTypeInitIterator(o); - while (hashTypeNext(hi) != REDIS_ERR) { + while (hashTypeNext(hi) != C_ERR) { if (count == 0) { int cmd_items = (items > REDIS_AOF_REWRITE_ITEMS_PER_CMD) ? REDIS_AOF_REWRITE_ITEMS_PER_CMD : items; @@ -1012,7 +1012,7 @@ int rewriteAppendOnlyFile(char *filename) { fp = fopen(tmpfile,"w"); if (!fp) { 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(); @@ -1027,7 +1027,7 @@ int rewriteAppendOnlyFile(char *filename) { di = dictGetSafeIterator(d); if (!di) { fclose(fp); - return REDIS_ERR; + return C_ERR; } /* SELECT the new DB */ @@ -1140,17 +1140,17 @@ int rewriteAppendOnlyFile(char *filename) { if (rename(tmpfile,filename) == -1) { serverLog(REDIS_WARNING,"Error moving temp append only file on the final destination: %s", strerror(errno)); unlink(tmpfile); - return REDIS_ERR; + return C_ERR; } serverLog(REDIS_NOTICE,"SYNC append only file rewrite performed"); - return REDIS_OK; + return C_OK; werr: serverLog(REDIS_WARNING,"Write error writing append only file on disk: %s", strerror(errno)); fclose(fp); unlink(tmpfile); 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_read_ack_from_parent = fds[4]; server.aof_stop_sending_diff = 0; - return REDIS_OK; + return C_OK; error: serverLog(REDIS_WARNING,"Error opening /setting AOF rewrite IPC pipes: %s", strerror(errno)); for (j = 0; j < 6; j++) if(fds[j] != -1) close(fds[j]); - return REDIS_ERR; + return C_ERR; } void aofClosePipes(void) { @@ -1247,8 +1247,8 @@ int rewriteAppendOnlyFileBackground(void) { pid_t childpid; long long start; - if (server.aof_child_pid != -1) return REDIS_ERR; - if (aofCreatePipes() != REDIS_OK) return REDIS_ERR; + if (server.aof_child_pid != -1) return C_ERR; + if (aofCreatePipes() != C_OK) return C_ERR; start = ustime(); if ((childpid = fork()) == 0) { char tmpfile[256]; @@ -1257,7 +1257,7 @@ int rewriteAppendOnlyFileBackground(void) { closeListeningSockets(0); redisSetProcTitle("redis-aof-rewrite"); 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(); if (private_dirty) { @@ -1278,7 +1278,7 @@ int rewriteAppendOnlyFileBackground(void) { serverLog(REDIS_WARNING, "Can't rewrite append only file in background: fork: %s", strerror(errno)); - return REDIS_ERR; + return C_ERR; } serverLog(REDIS_NOTICE, "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. */ server.aof_selected_db = -1; replicationScriptCacheFlush(); - return REDIS_OK; + return C_OK; } - return REDIS_OK; /* unreached */ + return C_OK; /* unreached */ } void bgrewriteaofCommand(client *c) { @@ -1303,7 +1303,7 @@ void bgrewriteaofCommand(client *c) { } else if (server.rdb_child_pid != -1) { server.aof_rewrite_scheduled = 1; 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"); } else { addReply(c,shared.err); @@ -1446,7 +1446,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) { server.aof_buf = sdsempty(); } - server.aof_lastbgrewrite_status = REDIS_OK; + server.aof_lastbgrewrite_status = C_OK; serverLog(REDIS_NOTICE, "Background AOF rewrite finished successfully"); /* Change state from WAIT_REWRITE to ON if needed */ @@ -1459,12 +1459,12 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) { serverLog(REDIS_VERBOSE, "Background AOF rewrite signal handler took %lldus", ustime()-now); } else if (!bysignal && exitcode != 0) { - server.aof_lastbgrewrite_status = REDIS_ERR; + server.aof_lastbgrewrite_status = C_ERR; serverLog(REDIS_WARNING, "Background AOF rewrite terminated with error"); } else { - server.aof_lastbgrewrite_status = REDIS_ERR; + server.aof_lastbgrewrite_status = C_ERR; serverLog(REDIS_WARNING, "Background AOF rewrite terminated by signal %d", bysignal); diff --git a/src/bitops.c b/src/bitops.c index 0b3e55ef2..8603899e4 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -41,18 +41,18 @@ static int getBitOffsetFromArgument(client *c, robj *o, size_t *offset) { long long loffset; char *err = "bit offset is not an integer or out of range"; - if (getLongLongFromObjectOrReply(c,o,&loffset,err) != REDIS_OK) - return REDIS_ERR; + if (getLongLongFromObjectOrReply(c,o,&loffset,err) != C_OK) + return C_ERR; /* Limit offset to 512MB in bytes */ if ((loffset < 0) || ((unsigned long long)loffset >> 3) >= (512*1024*1024)) { addReplyError(c,err); - return REDIS_ERR; + return C_ERR; } *offset = (size_t)loffset; - return REDIS_OK; + return C_OK; } /* 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; long on; - if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != REDIS_OK) + if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != C_OK) return; - if (getLongFromObjectOrReply(c,c->argv[3],&on,err) != REDIS_OK) + if (getLongFromObjectOrReply(c,c->argv[3],&on,err) != C_OK) return; /* Bits can only be set or cleared... */ @@ -263,7 +263,7 @@ void getbitCommand(client *c) { size_t byte, bit; size_t bitval = 0; - if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != REDIS_OK) + if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset) != C_OK) return; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL || @@ -479,9 +479,9 @@ void bitcountCommand(client *c) { /* Parse start/end range if any. */ 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; - if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK) return; /* Convert negative indexes */ 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 * or clear bits. */ - if (getLongFromObjectOrReply(c,c->argv[2],&bit,NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c,c->argv[2],&bit,NULL) != C_OK) return; if (bit != 0 && bit != 1) { addReplyError(c, "The bit argument must be 1 or 0."); @@ -548,10 +548,10 @@ void bitposCommand(client *c) { /* Parse start/end range if any. */ 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; 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; end_given = 1; } else { diff --git a/src/blocked.c b/src/blocked.c index 2480bf2a7..c6194a0e7 100644 --- a/src/blocked.c +++ b/src/blocked.c @@ -77,12 +77,12 @@ int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int long long tval; if (getLongLongFromObjectOrReply(c,object,&tval, - "timeout is not an integer or out of range") != REDIS_OK) - return REDIS_ERR; + "timeout is not an integer or out of range") != C_OK) + return C_ERR; if (tval < 0) { addReplyError(c,"timeout is negative"); - return REDIS_ERR; + return C_ERR; } if (tval > 0) { @@ -91,7 +91,7 @@ int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int } *timeout = tval; - return REDIS_OK; + return C_OK; } /* Block a client for the specific operation type. Once the REDIS_BLOCKED diff --git a/src/cluster.c b/src/cluster.c index bce082ac0..04ad6231f 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -85,8 +85,8 @@ int clusterBumpConfigEpochWithoutConsensus(void); * * 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 - * sake of locking if it does not already exist), REDIS_ERR is returned. - * If the configuration was loaded from the file, REDIS_OK is returned. */ + * sake of locking if it does not already exist), C_ERR is returned. + * If the configuration was loaded from the file, C_OK is returned. */ int clusterLoadConfig(char *filename) { FILE *fp = fopen(filename,"r"); struct stat sb; @@ -95,7 +95,7 @@ int clusterLoadConfig(char *filename) { if (fp == NULL) { if (errno == ENOENT) { - return REDIS_ERR; + return C_ERR; } else { serverLog(REDIS_WARNING, "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. */ if (fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) { fclose(fp); - return REDIS_ERR; + return C_ERR; } /* 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) { server.cluster->currentEpoch = clusterGetMaxEpoch(); } - return REDIS_OK; + return C_OK; fmterr: 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 * the length with ftruncate()). * - * On success REDIS_OK is returned, otherwise an error is logged and - * the function returns REDIS_ERR to signal a lock was not acquired. */ + * On success C_OK is returned, otherwise an error is logged and + * the function returns C_ERR to signal a lock was not acquired. */ int clusterLockConfig(char *filename) { /* flock() does not exist on Solaris * 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, "Can't open %s in order to acquire a lock: %s", filename, strerror(errno)); - return REDIS_ERR; + return C_ERR; } if (flock(fd,LOCK_EX|LOCK_NB) == -1) { @@ -386,13 +386,13 @@ int clusterLockConfig(char *filename) { "Impossible to lock %s: %s", filename, strerror(errno)); } close(fd); - return REDIS_ERR; + return C_ERR; } /* 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. */ #endif /* __sun */ - return REDIS_OK; + return C_OK; } void clusterInit(void) { @@ -420,11 +420,11 @@ void clusterInit(void) { /* Lock the cluster config file to make sure every node uses * its own nodes.conf. */ - if (clusterLockConfig(server.cluster_configfile) == REDIS_ERR) + if (clusterLockConfig(server.cluster_configfile) == C_ERR) exit(1); /* 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 * by the createClusterNode() function. */ myself = server.cluster->myself = @@ -452,7 +452,7 @@ void clusterInit(void) { } if (listenToPort(server.port+REDIS_CLUSTER_PORT_INCR, - server.cfd,&server.cfd_count) == REDIS_ERR) + server.cfd,&server.cfd_count) == C_ERR) { exit(1); } else { @@ -783,10 +783,10 @@ int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) { (sizeof(*master->slaves) * remaining_slaves)); } master->numslaves--; - return REDIS_OK; + return C_OK; } } - return REDIS_ERR; + return C_ERR; } 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. */ 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, sizeof(clusterNode*)*(master->numslaves+1)); master->slaves[master->numslaves] = slave; master->numslaves++; - return REDIS_OK; + return C_OK; } void clusterNodeResetSlaves(clusterNode *n) { @@ -849,7 +849,7 @@ int clusterAddNode(clusterNode *node) { retval = dictAdd(server.cluster->nodes, 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 @@ -949,8 +949,8 @@ uint64_t clusterGetMaxEpoch(void) { * 3) Persist the configuration on disk before sending packets with the * new configuration. * - * If the new config epoch is generated and assigend, REDIS_OK is returned, - * otherwise REDIS_ERR is returned (since the node has already the greatest + * If the new config epoch is generated and assigend, C_OK is returned, + * otherwise C_ERR is returned (since the node has already the greatest * configuration around) and no operation is performed. * * Important note: this function violates the principle that config epochs @@ -983,9 +983,9 @@ int clusterBumpConfigEpochWithoutConsensus(void) { serverLog(REDIS_WARNING, "New configEpoch set to %llu", (unsigned long long) myself->configEpoch); - return REDIS_OK; + return C_OK; } 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 - * 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 - * an error and REDIS_ERR is returned. */ + * an error and C_ERR is returned. */ 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); server.cluster->slots[slot] = n; - return REDIS_OK; + return C_OK; } /* Delete the specified slot marking it as unassigned. - * Returns REDIS_OK if the slot was assigned, otherwise if the slot was - * already unassigned REDIS_ERR is returned. */ + * Returns C_OK if the slot was assigned, otherwise if the slot was + * already unassigned C_ERR is returned. */ int clusterDelSlot(int slot) { clusterNode *n = server.cluster->slots[slot]; - if (!n) return REDIS_ERR; + if (!n) return C_ERR; serverAssert(clusterNodeClearSlotBit(n,slot) == 1); server.cluster->slots[slot] = NULL; - return REDIS_OK; + return C_OK; } /* 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 * 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. - * 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 * 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 - * 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 * 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 * 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. */ 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 @@ -3557,7 +3557,7 @@ int verifyClusterConfigWithData(void) { } } 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) { long long slot; - if (getLongLongFromObject(o,&slot) != REDIS_OK || + if (getLongLongFromObject(o,&slot) != C_OK || slot < 0 || slot >= REDIS_CLUSTER_SLOTS) { 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) { 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", (char*)c->argv[3]->ptr); return; @@ -3894,7 +3894,7 @@ void clusterCommand(client *c) { retval = del ? clusterDelSlot(j) : clusterAddSlot(myself,j); - serverAssertWithInfo(c,NULL,retval == REDIS_OK); + serverAssertWithInfo(c,NULL,retval == C_OK); } } zfree(slots); @@ -3977,7 +3977,7 @@ void clusterCommand(client *c) { * failover happens at the same time we close the slot, the * configEpoch collision resolution will fix it assigning * a different epoch to each node. */ - if (clusterBumpConfigEpochWithoutConsensus() == REDIS_OK) { + if (clusterBumpConfigEpochWithoutConsensus() == C_OK) { serverLog(REDIS_WARNING, "configEpoch updated after importing slot %d", slot); } @@ -4061,7 +4061,7 @@ void clusterCommand(client *c) { /* CLUSTER COUNTKEYSINSLOT */ long long slot; - if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != REDIS_OK) + if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != C_OK) return; if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS) { addReplyError(c,"Invalid slot"); @@ -4074,10 +4074,10 @@ void clusterCommand(client *c) { unsigned int numkeys, j; robj **keys; - if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != REDIS_OK) + if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != C_OK) return; if (getLongLongFromObjectOrReply(c,c->argv[3],&maxkeys,NULL) - != REDIS_OK) + != C_OK) return; if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS || maxkeys < 0) { 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. */ long long epoch; - if (getLongLongFromObjectOrReply(c,c->argv[2],&epoch,NULL) != REDIS_OK) + if (getLongLongFromObjectOrReply(c,c->argv[2],&epoch,NULL) != C_OK) return; 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 * 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. */ int verifyDumpPayload(unsigned char *p, size_t len) { unsigned char *footer; @@ -4347,17 +4347,17 @@ int verifyDumpPayload(unsigned char *p, size_t len) { uint64_t crc; /* 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); /* Verify RDB version */ rdbver = (footer[1] << 8) | footer[0]; - if (rdbver != REDIS_RDB_VERSION) return REDIS_ERR; + if (rdbver != REDIS_RDB_VERSION) return C_ERR; /* Verify CRC64 */ crc = crc64(0,p,len-8); 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 @@ -4407,7 +4407,7 @@ void restoreCommand(client *c) { } /* 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; } else if (ttl < 0) { addReplyError(c,"Invalid TTL value, must be >= 0"); @@ -4415,7 +4415,7 @@ void restoreCommand(client *c) { } /* 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"); return; @@ -4587,9 +4587,9 @@ try_again: } /* Sanity check */ - if (getLongFromObjectOrReply(c,c->argv[5],&timeout,NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c,c->argv[5],&timeout,NULL) != C_OK) return; - if (getLongFromObjectOrReply(c,c->argv[4],&dbid,NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c,c->argv[4],&dbid,NULL) != C_OK) return; if (timeout <= 0) timeout = 1000; diff --git a/src/config.c b/src/config.c index b33db70bf..7f31c4782 100644 --- a/src/config.c +++ b/src/config.c @@ -677,7 +677,7 @@ void loadServerConfig(char *filename, char *options) { #define config_set_numerical_field(_name,_var,min,max) \ } 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 (max != LLONG_MAX && ll > max) goto badfmt; \ _var = ll; @@ -727,7 +727,7 @@ void configSetCommand(client *c) { } config_set_special_field("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. */ server.maxclients = ll; @@ -757,7 +757,7 @@ void configSetCommand(client *c) { if (enable == 0 && server.aof_state != REDIS_AOF_OFF) { stopAppendOnly(); } else if (enable && server.aof_state == REDIS_AOF_OFF) { - if (startAppendOnly() == REDIS_ERR) { + if (startAppendOnly() == C_ERR) { addReplyError(c, "Unable to turn on AOF. Check server logs."); return; diff --git a/src/db.c b/src/db.c index 72c4c3b4e..d1eb1db1c 100644 --- a/src/db.c +++ b/src/db.c @@ -119,7 +119,7 @@ void dbAdd(redisDb *db, robj *key, robj *val) { sds copy = sdsdup(key->ptr); 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 (server.cluster_enabled) slotToKeyAdd(key); } @@ -249,9 +249,9 @@ long long emptyDb(void(callback)(void*)) { int selectDb(client *c, int id) { if (id < 0 || id >= server.dbnum) - return REDIS_ERR; + return C_ERR; c->db = &server.db[id]; - return REDIS_OK; + return C_OK; } /*----------------------------------------------------------------------------- @@ -335,14 +335,14 @@ void selectCommand(client *c) { long id; if (getLongFromObjectOrReply(c, c->argv[1], &id, - "invalid DB index") != REDIS_OK) + "invalid DB index") != C_OK) return; if (server.cluster_enabled && id != 0) { addReplyError(c,"SELECT is not allowed in cluster mode"); return; } - if (selectDb(c,id) == REDIS_ERR) { + if (selectDb(c,id) == C_ERR) { addReplyError(c,"invalid DB index"); } else { 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': * 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. */ int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor) { 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) { addReplyError(c, "invalid cursor"); - return REDIS_ERR; + return C_ERR; } - return REDIS_OK; + return C_OK; } /* 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; if (!strcasecmp(c->argv[i]->ptr, "count") && j >= 2) { if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL) - != REDIS_OK) + != C_OK) { goto cleanup; } @@ -629,7 +629,7 @@ cleanup: /* The SCAN command completely relies on scanGenericCommand. */ void scanCommand(client *c) { 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); } @@ -685,7 +685,7 @@ void shutdownCommand(client *c) { * Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */ if (server.loading || server.sentinel_mode) 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."); } @@ -754,9 +754,9 @@ void moveCommand(client *c) { src = c->db; 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 || - selectDb(c,dbid) == REDIS_ERR) + selectDb(c,dbid) == C_ERR) { addReply(c,shared.outofrangeerr); return; @@ -903,7 +903,7 @@ void expireGenericCommand(client *c, long long basetime, int unit) { robj *key = c->argv[1], *param = c->argv[2]; 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; if (unit == UNIT_SECONDS) when *= 1000; diff --git a/src/debug.c b/src/debug.c index 7a45816ad..08431dcee 100644 --- a/src/debug.c +++ b/src/debug.c @@ -226,7 +226,7 @@ void computeDatasetDigest(unsigned char *final) { robj *obj; hi = hashTypeInitIterator(o); - while (hashTypeNext(hi) != REDIS_ERR) { + while (hashTypeNext(hi) != C_ERR) { unsigned char eledigest[20]; memset(eledigest,0,20); @@ -269,12 +269,12 @@ void debugCommand(client *c) { if (c->argc >= 3) c->argv[2] = tryObjectEncoding(c->argv[2]); serverAssertWithInfo(c,c->argv[0],1 == 2); } 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); return; } 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"); return; } @@ -282,7 +282,7 @@ void debugCommand(client *c) { addReply(c,shared.ok); } else if (!strcasecmp(c->argv[1]->ptr,"loadaof")) { emptyDb(NULL); - if (loadAppendOnlyFile(server.aof_filename) != REDIS_OK) { + if (loadAppendOnlyFile(server.aof_filename) != C_OK) { addReply(c,shared.err); return; } @@ -370,7 +370,7 @@ void debugCommand(client *c) { robj *key, *val; char buf[128]; - if (getLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != C_OK) return; dictExpand(c->db->dict,keys); for (j = 0; j < keys; j++) { @@ -434,7 +434,7 @@ void debugCommand(client *c) { sds stats = sdsempty(); char buf[4096]; - if (getLongFromObjectOrReply(c, c->argv[2], &dbid, NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c, c->argv[2], &dbid, NULL) != C_OK) return; if (dbid < 0 || dbid >= server.dbnum) { addReplyError(c,"Out of range database"); diff --git a/src/geo.c b/src/geo.c index 6671806bd..637302662 100644 --- a/src/geo.c +++ b/src/geo.c @@ -88,33 +88,33 @@ int decodeGeohash(double bits, double *xy) { /* Input Argument Helper */ /* 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, double *xy) { for (int i = 0; i < 2; i++) { if (getDoubleFromObjectOrReply(c, argv[i], xy + i, NULL) != - REDIS_OK) { - return REDIS_ERR; + C_OK) { + return C_ERR; } if (xy[0] < GEO_LONG_MIN || xy[0] > GEO_LONG_MAX || xy[1] < GEO_LAT_MIN || xy[1] > GEO_LAT_MAX) { addReplySds(c, sdscatprintf(sdsempty(), "-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 */ /* 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) { double score = 0; - if (zsetScore(zobj, member, &score) == REDIS_ERR) return REDIS_ERR; - if (!decodeGeohash(score, xy)) return REDIS_ERR; - return REDIS_OK; + if (zsetScore(zobj, member, &score) == C_ERR) return C_ERR; + if (!decodeGeohash(score, xy)) return C_ERR; + return C_OK; } /* 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 distance; if (getDoubleFromObjectOrReply(c, argv[0], &distance, - "need numeric radius") != REDIS_OK) { + "need numeric radius") != C_OK) { return -1; } @@ -179,17 +179,17 @@ void addReplyDoubleDistance(client *c, double d) { * a radius, appends this entry as a geoPoint into the specified geoArray * 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) { 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 * reverse order: longitude first, latitude later. */ if (!geohashGetDistanceIfInRadiusWGS84(lon,lat, xy[0], xy[1], radius, &distance)) { - return REDIS_ERR; + return C_ERR; } /* Append the new element. */ @@ -199,7 +199,7 @@ int geoAppendIfWithinRadius(geoArray *ga, double lon, double lat, double radius, gp->dist = distance; gp->member = member; gp->score = score; - return REDIS_OK; + return C_OK; } /* 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) : sdsnewlen(vstr,vlen); if (geoAppendIfWithinRadius(ga,lon,lat,radius,score,member) - == REDIS_ERR) sdsfree(member); + == C_ERR) sdsfree(member); zzlNext(zl, &eptr, &sptr); } } 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) : sdsdup(o->ptr); if (geoAppendIfWithinRadius(ga,lon,lat,radius,ln->score,member) - == REDIS_ERR) sdsfree(member); + == C_ERR) sdsfree(member); ln = ln->level[0].forward; } } @@ -386,7 +386,7 @@ void geoaddCommand(client *c) { for (i = 0; i < elements; i++) { 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++) if (argv[i]) decrRefCount(argv[i]); zfree(argv); @@ -434,12 +434,12 @@ void georadiusGeneric(client *c, int type) { double xy[2] = { 0 }; if (type == RADIUS_COORDS) { base_args = 6; - if (extractLongLatOrReply(c, c->argv + 2, xy) == REDIS_ERR) + if (extractLongLatOrReply(c, c->argv + 2, xy) == C_ERR) return; } else if (type == RADIUS_MEMBER) { base_args = 5; 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"); return; } @@ -475,7 +475,7 @@ void georadiusGeneric(client *c, int type) { sort = SORT_DESC; } else if (!strcasecmp(arg, "count") && remaining > 0) { if (getLongLongFromObjectOrReply(c, c->argv[base_args+i+1], - &count, NULL) != REDIS_OK) return; + &count, NULL) != C_OK) return; if (count <= 0) { addReplyError(c,"COUNT must be > 0"); return; @@ -596,7 +596,7 @@ void geohashCommand(client *c) { addReplyMultiBulkLen(c,c->argc-2); for (j = 2; j < c->argc; j++) { double score; - if (zsetScore(zobj, c->argv[j], &score) == REDIS_ERR) { + if (zsetScore(zobj, c->argv[j], &score) == C_ERR) { addReply(c,shared.nullbulk); } else { /* The internal format we use for geocoding is a bit different @@ -650,7 +650,7 @@ void geoposCommand(client *c) { addReplyMultiBulkLen(c,c->argc-2); for (j = 2; j < c->argc; j++) { double score; - if (zsetScore(zobj, c->argv[j], &score) == REDIS_ERR) { + if (zsetScore(zobj, c->argv[j], &score) == C_ERR) { addReply(c,shared.nullmultibulk); } else { /* Decode... */ @@ -690,8 +690,8 @@ void geodistCommand(client *c) { /* Get the scores. We need both otherwise NULL is returned. */ double score1, score2, xyxy[4]; - if (zsetScore(zobj, c->argv[2], &score1) == REDIS_ERR || - zsetScore(zobj, c->argv[3], &score2) == REDIS_ERR) + if (zsetScore(zobj, c->argv[2], &score1) == C_ERR || + zsetScore(zobj, c->argv[3], &score2) == C_ERR) { addReply(c,shared.nullbulk); return; diff --git a/src/hyperloglog.c b/src/hyperloglog.c index 8e18f5261..ffd2a9ec3 100644 --- a/src/hyperloglog.c +++ b/src/hyperloglog.c @@ -563,8 +563,8 @@ double hllDenseSum(uint8_t *registers, double *PE, int *ezp) { * representation. Both representations are represented by SDS strings, and * the input representation is freed as a side effect. * - * The function returns REDIS_OK if the sparse representation was valid, - * otherwise REDIS_ERR is returned if the representation was corrupted. */ + * The function returns C_OK if the sparse representation was valid, + * otherwise C_ERR is returned if the representation was corrupted. */ int hllSparseToDense(robj *o) { sds sparse = o->ptr, dense; 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. */ 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. * 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. */ if (idx != HLL_REGISTERS) { sdsfree(dense); - return REDIS_ERR; + return C_ERR; } /* Free the old representation and set the new one. */ sdsfree(o->ptr); o->ptr = dense; - return REDIS_OK; + return C_OK; } /* "Add" the element in the sparse hyperloglog data structure. @@ -866,7 +866,7 @@ updated: return 1; 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; /* 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() * 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. */ int hllMerge(uint8_t *max, robj *hll) { struct hllhdr *hdr = hll->ptr; @@ -1077,9 +1077,9 @@ int hllMerge(uint8_t *max, robj *hll) { p++; } } - if (i != HLL_REGISTERS) return REDIS_ERR; + if (i != HLL_REGISTERS) return C_ERR; } - return REDIS_OK; + return C_OK; } /* ========================== HyperLogLog commands ========================== */ @@ -1119,14 +1119,14 @@ robj *createHLLObject(void) { } /* Check if the object is a String with a valid HLL representation. - * Return REDIS_OK if this is true, otherwise reply to the client - * with an error and return REDIS_ERR. */ + * Return C_OK if this is true, otherwise reply to the client + * with an error and return C_ERR. */ int isHLLObjectOrReply(client *c, robj *o) { struct hllhdr *hdr; /* Key exists, check type */ 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; hdr = o->ptr; @@ -1142,13 +1142,13 @@ int isHLLObjectOrReply(client *c, robj *o) { stringObjectLen(o) != HLL_DENSE_SIZE) goto invalid; /* All tests passed. */ - return REDIS_OK; + return C_OK; invalid: addReplySds(c, sdsnew("-WRONGTYPE Key is not a valid " "HyperLogLog string value.\r\n")); - return REDIS_ERR; + return C_ERR; } /* PFADD var ele ele ele ... ele => :0 or :1 */ @@ -1165,7 +1165,7 @@ void pfaddCommand(client *c) { dbAdd(c->db,c->argv[1],o); updated++; } else { - if (isHLLObjectOrReply(c,o) != REDIS_OK) return; + if (isHLLObjectOrReply(c,o) != C_OK) return; o = dbUnshareStringValue(c->db,c->argv[1],o); } /* Perform the low level ADD operation for every element. */ @@ -1214,11 +1214,11 @@ void pfcountCommand(client *c) { /* Check type and size. */ robj *o = lookupKeyRead(c->db,c->argv[j]); 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] * to MAX(max[i],hll[i]). */ - if (hllMerge(registers,o) == REDIS_ERR) { + if (hllMerge(registers,o) == C_ERR) { addReplySds(c,sdsnew(invalid_hll_err)); return; } @@ -1239,7 +1239,7 @@ void pfcountCommand(client *c) { * we would have a key as HLLADD creates it as a side effect. */ addReply(c,shared.czero); } else { - if (isHLLObjectOrReply(c,o) != REDIS_OK) return; + if (isHLLObjectOrReply(c,o) != C_OK) return; o = dbUnshareStringValue(c->db,c->argv[1],o); /* Check if the cached cardinality is valid. */ @@ -1295,11 +1295,11 @@ void pfmergeCommand(client *c) { /* Check type and size. */ robj *o = lookupKeyRead(c->db,c->argv[j]); 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] * to MAX(max[i],hll[i]). */ - if (hllMerge(max,o) == REDIS_ERR) { + if (hllMerge(max,o) == C_ERR) { addReplySds(c,sdsnew(invalid_hll_err)); return; } @@ -1321,7 +1321,7 @@ void pfmergeCommand(client *c) { } /* Only support dense objects as destination. */ - if (hllSparseToDense(o) == REDIS_ERR) { + if (hllSparseToDense(o) == C_ERR) { addReplySds(c,sdsnew(invalid_hll_err)); return; } @@ -1463,7 +1463,7 @@ void pfdebugCommand(client *c) { addReplyError(c,"The specified key does not exist"); return; } - if (isHLLObjectOrReply(c,o) != REDIS_OK) return; + if (isHLLObjectOrReply(c,o) != C_OK) return; o = dbUnshareStringValue(c->db,c->argv[2],o); hdr = o->ptr; @@ -1472,7 +1472,7 @@ void pfdebugCommand(client *c) { if (c->argc != 3) goto arityerr; if (hdr->encoding == HLL_SPARSE) { - if (hllSparseToDense(o) == REDIS_ERR) { + if (hllSparseToDense(o) == C_ERR) { addReplySds(c,sdsnew(invalid_hll_err)); return; } @@ -1536,7 +1536,7 @@ void pfdebugCommand(client *c) { if (c->argc != 3) goto arityerr; if (hdr->encoding == HLL_SPARSE) { - if (hllSparseToDense(o) == REDIS_ERR) { + if (hllSparseToDense(o) == C_ERR) { addReplySds(c,sdsnew(invalid_hll_err)); return; } diff --git a/src/networking.c b/src/networking.c index 9c17763d3..32fdfc494 100644 --- a/src/networking.c +++ b/src/networking.c @@ -132,14 +132,14 @@ client *createClient(int fd) { * to the client. The behavior is the following: * * 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. * * 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 - * 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: * * 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. * * 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. */ int prepareClientToWrite(client *c) { /* If it's the Lua client we always return ok without installing any * 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 * is set. */ 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 * slaves, if the client can actually receive writes. */ @@ -173,12 +173,12 @@ int prepareClientToWrite(client *c) { sendReplyToClient, c) == AE_ERR) { freeClientAsync(c); - return REDIS_ERR; + return C_ERR; } } /* 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 @@ -204,18 +204,18 @@ robj *dupLastObjectIfNeeded(list *reply) { int _addReplyToBuffer(client *c, const char *s, size_t len) { 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 * 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. */ - if (len > available) return REDIS_ERR; + if (len > available) return C_ERR; memcpy(c->buf+c->bufpos,s,len); c->bufpos+=len; - return REDIS_OK; + return C_OK; } 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) { - if (prepareClientToWrite(c) != REDIS_OK) return; + if (prepareClientToWrite(c) != C_OK) return; /* This is an important place where we can avoid copy-on-write * 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 * messing with its page. */ 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); } else if (obj->encoding == OBJ_ENCODING_INT) { /* Optimization: if there is room in the static buffer for 32 bytes @@ -339,13 +339,13 @@ void addReply(client *c, robj *obj) { int len; len = ll2string(buf,sizeof(buf),(long)obj->ptr); - if (_addReplyToBuffer(c,buf,len) == REDIS_OK) + if (_addReplyToBuffer(c,buf,len) == C_OK) return; /* else... continue with the normal code path, but should never * happen actually since we verified there is room. */ } 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); decrRefCount(obj); } else { @@ -354,12 +354,12 @@ void addReply(client *c, robj *obj) { } 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. */ sdsfree(s); return; } - if (_addReplyToBuffer(c,s,sdslen(s)) == REDIS_OK) { + if (_addReplyToBuffer(c,s,sdslen(s)) == C_OK) { sdsfree(s); } else { /* 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) { - if (prepareClientToWrite(c) != REDIS_OK) return; - if (_addReplyToBuffer(c,s,len) != REDIS_OK) + if (prepareClientToWrite(c) != C_OK) return; + if (_addReplyToBuffer(c,s,len) != C_OK) _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 * ready to be sent, since we are sure that before returning to the * 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)); return listLast(c->reply); } @@ -934,7 +934,7 @@ int processInlineBuffer(client *c) { addReplyError(c,"Protocol error: too big inline request"); setProtocolError(c,0); } - return REDIS_ERR; + return C_ERR; } /* Handle the \r\n case. */ @@ -949,7 +949,7 @@ int processInlineBuffer(client *c) { if (argv == NULL) { addReplyError(c,"Protocol error: unbalanced quotes in request"); setProtocolError(c,0); - return REDIS_ERR; + return C_ERR; } /* Newline from slaves can be used to refresh the last ACK time. @@ -977,7 +977,7 @@ int processInlineBuffer(client *c) { } } zfree(argv); - return REDIS_OK; + return C_OK; } /* 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"); setProtocolError(c,0); } - return REDIS_ERR; + return C_ERR; } /* Buffer should also contain \n */ 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, * so go ahead and find out the multi bulk length. */ @@ -1023,13 +1023,13 @@ int processMultibulkBuffer(client *c) { if (!ok || ll > 1024*1024) { addReplyError(c,"Protocol error: invalid multibulk length"); setProtocolError(c,pos); - return REDIS_ERR; + return C_ERR; } pos = (newline-c->querybuf)+2; if (ll <= 0) { sdsrange(c->querybuf,pos,-1); - return REDIS_OK; + return C_OK; } c->multibulklen = ll; @@ -1049,7 +1049,7 @@ int processMultibulkBuffer(client *c) { addReplyError(c, "Protocol error: too big bulk count string"); setProtocolError(c,0); - return REDIS_ERR; + return C_ERR; } break; } @@ -1063,14 +1063,14 @@ int processMultibulkBuffer(client *c) { "Protocol error: expected '$', got '%c'", c->querybuf[pos]); setProtocolError(c,pos); - return REDIS_ERR; + return C_ERR; } ok = string2ll(c->querybuf+pos+1,newline-(c->querybuf+pos+1),&ll); if (!ok || ll < 0 || ll > 512*1024*1024) { addReplyError(c,"Protocol error: invalid bulk length"); setProtocolError(c,pos); - return REDIS_ERR; + return C_ERR; } pos += newline-(c->querybuf+pos)+2; @@ -1125,10 +1125,10 @@ int processMultibulkBuffer(client *c) { if (pos) sdsrange(c->querybuf,pos,-1); /* 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 */ - return REDIS_ERR; + return C_ERR; } void processInputBuffer(client *c) { @@ -1156,9 +1156,9 @@ void processInputBuffer(client *c) { } 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) { - if (processMultibulkBuffer(c) != REDIS_OK) break; + if (processMultibulkBuffer(c) != C_OK) break; } else { redisPanic("Unknown request type"); } @@ -1168,7 +1168,7 @@ void processInputBuffer(client *c) { resetClient(c); } else { /* Only reset the client when the command was executed. */ - if (processCommand(c) == REDIS_OK) + if (processCommand(c) == C_OK) resetClient(c); } } @@ -1388,7 +1388,7 @@ void clientCommand(client *c) { long long tmp; if (getLongLongFromObjectOrReply(c,c->argv[i+1],&tmp,NULL) - != REDIS_OK) return; + != C_OK) return; id = tmp; } else if (!strcasecmp(c->argv[i]->ptr,"type") && moreargs) { type = getClientTypeByName(c->argv[i+1]->ptr); @@ -1489,7 +1489,7 @@ void clientCommand(client *c) { long long duration; if (getTimeoutFromObjectOrReply(c,c->argv[2],&duration,UNIT_MILLISECONDS) - != REDIS_OK) return; + != C_OK) return; pauseClients(duration); addReply(c,shared.ok); } else { diff --git a/src/object.c b/src/object.c index a9d959b4c..c82badd79 100644 --- a/src/object.c +++ b/src/object.c @@ -351,9 +351,9 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) { serverAssertWithInfo(NULL,o,o->type == OBJ_STRING); if (o->encoding == OBJ_ENCODING_INT) { if (llval) *llval = (long) o->ptr; - return REDIS_OK; + return C_OK; } 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)) || errno == EINVAL || isnan(value)) - return REDIS_ERR; + return C_ERR; } else if (o->encoding == OBJ_ENCODING_INT) { value = (long)o->ptr; } else { @@ -559,21 +559,21 @@ int getDoubleFromObject(robj *o, double *target) { } } *target = value; - return REDIS_OK; + return C_OK; } int getDoubleFromObjectOrReply(client *c, robj *o, double *target, const char *msg) { double value; - if (getDoubleFromObject(o, &value) != REDIS_OK) { + if (getDoubleFromObject(o, &value) != C_OK) { if (msg != NULL) { addReplyError(c,(char*)msg); } else { addReplyError(c,"value is not a valid float"); } - return REDIS_ERR; + return C_ERR; } *target = value; - return REDIS_OK; + return C_OK; } int getLongDoubleFromObject(robj *o, long double *target) { @@ -589,7 +589,7 @@ int getLongDoubleFromObject(robj *o, long double *target) { value = strtold(o->ptr, &eptr); if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || errno == ERANGE || isnan(value)) - return REDIS_ERR; + return C_ERR; } else if (o->encoding == OBJ_ENCODING_INT) { value = (long)o->ptr; } else { @@ -597,21 +597,21 @@ int getLongDoubleFromObject(robj *o, long double *target) { } } *target = value; - return REDIS_OK; + return C_OK; } int getLongDoubleFromObjectOrReply(client *c, robj *o, long double *target, const char *msg) { long double value; - if (getLongDoubleFromObject(o, &value) != REDIS_OK) { + if (getLongDoubleFromObject(o, &value) != C_OK) { if (msg != NULL) { addReplyError(c,(char*)msg); } else { addReplyError(c,"value is not a valid float"); } - return REDIS_ERR; + return C_ERR; } *target = value; - return REDIS_OK; + return C_OK; } int getLongLongFromObject(robj *o, long long *target) { @@ -627,7 +627,7 @@ int getLongLongFromObject(robj *o, long long *target) { value = strtoll(o->ptr, &eptr, 10); if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || errno == ERANGE) - return REDIS_ERR; + return C_ERR; } else if (o->encoding == OBJ_ENCODING_INT) { value = (long)o->ptr; } else { @@ -635,37 +635,37 @@ int getLongLongFromObject(robj *o, long long *target) { } } if (target) *target = value; - return REDIS_OK; + return C_OK; } int getLongLongFromObjectOrReply(client *c, robj *o, long long *target, const char *msg) { long long value; - if (getLongLongFromObject(o, &value) != REDIS_OK) { + if (getLongLongFromObject(o, &value) != C_OK) { if (msg != NULL) { addReplyError(c,(char*)msg); } else { addReplyError(c,"value is not an integer or out of range"); } - return REDIS_ERR; + return C_ERR; } *target = value; - return REDIS_OK; + return C_OK; } int getLongFromObjectOrReply(client *c, robj *o, long *target, const char *msg) { 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 (msg != NULL) { addReplyError(c,(char*)msg); } else { addReplyError(c,"value is out of range"); } - return REDIS_ERR; + return C_ERR; } *target = value; - return REDIS_OK; + return C_OK; } char *strEncoding(int encoding) { diff --git a/src/rdb.c b/src/rdb.c index 69c69d744..4562c7fb0 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -726,11 +726,11 @@ int rdbSaveInfoAuxFields(rio *rdb) { } /* 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 * 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 * error. */ int rdbSaveRio(rio *rdb, int *error) { @@ -752,7 +752,7 @@ int rdbSaveRio(rio *rdb, int *error) { dict *d = db->dict; if (dictSize(d) == 0) continue; di = dictGetSafeIterator(d); - if (!di) return REDIS_ERR; + if (!di) return C_ERR; /* Write the SELECT DB opcode */ if (rdbSaveType(rdb,REDIS_RDB_OPCODE_SELECTDB) == -1) goto werr; @@ -795,12 +795,12 @@ int rdbSaveRio(rio *rdb, int *error) { cksum = rdb->cksum; memrev64ifbe(&cksum); if (rioWrite(rdb,&cksum,8) == 0) goto werr; - return REDIS_OK; + return C_OK; werr: if (error) *error = errno; if (di) dictReleaseIterator(di); - return REDIS_ERR; + return C_ERR; } /* 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,eofmark,REDIS_EOF_MARK_SIZE) == 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; - return REDIS_OK; + return C_OK; werr: /* Write error. */ /* Set 'error' only if not already set by rdbSaveRio() call. */ 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) { char tmpfile[256]; FILE *fp; @@ -841,11 +841,11 @@ int rdbSave(char *filename) { if (!fp) { serverLog(REDIS_WARNING, "Failed opening .rdb for saving: %s", strerror(errno)); - return REDIS_ERR; + return C_ERR; } rioInitWithFile(&rdb,fp); - if (rdbSaveRio(&rdb,&error) == REDIS_ERR) { + if (rdbSaveRio(&rdb,&error) == C_ERR) { errno = error; goto werr; } @@ -860,26 +860,26 @@ int rdbSave(char *filename) { if (rename(tmpfile,filename) == -1) { serverLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno)); unlink(tmpfile); - return REDIS_ERR; + return C_ERR; } serverLog(REDIS_NOTICE,"DB saved on disk"); server.dirty = 0; server.lastsave = time(NULL); - server.lastbgsave_status = REDIS_OK; - return REDIS_OK; + server.lastbgsave_status = C_OK; + return C_OK; werr: serverLog(REDIS_WARNING,"Write error saving DB on disk: %s", strerror(errno)); fclose(fp); unlink(tmpfile); - return REDIS_ERR; + return C_ERR; } int rdbSaveBackground(char *filename) { pid_t childpid; 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.lastbgsave_try = time(NULL); @@ -892,7 +892,7 @@ int rdbSaveBackground(char *filename) { closeListeningSockets(0); redisSetProcTitle("redis-rdb-bgsave"); retval = rdbSave(filename); - if (retval == REDIS_OK) { + if (retval == C_OK) { size_t private_dirty = zmalloc_get_private_dirty(); if (private_dirty) { @@ -901,26 +901,26 @@ int rdbSaveBackground(char *filename) { private_dirty/(1024*1024)); } } - exitFromChild((retval == REDIS_OK) ? 0 : 1); + exitFromChild((retval == C_OK) ? 0 : 1); } else { /* Parent */ 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. */ latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000); if (childpid == -1) { - server.lastbgsave_status = REDIS_ERR; + server.lastbgsave_status = C_ERR; serverLog(REDIS_WARNING,"Can't save in background: fork: %s", strerror(errno)); - return REDIS_ERR; + return C_ERR; } serverLog(REDIS_NOTICE,"Background saving started by pid %d",childpid); server.rdb_save_time_start = time(NULL); server.rdb_child_pid = childpid; server.rdb_child_type = REDIS_RDB_CHILD_TYPE_DISK; updateDictResizePolicy(); - return REDIS_OK; + return C_OK; } - return REDIS_OK; /* unreached */ + return C_OK; /* unreached */ } void rdbRemoveTempFile(pid_t childpid) { @@ -981,7 +981,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb) { if (o->encoding == OBJ_ENCODING_INTSET) { /* Fetch integer value from element */ - if (isObjectRepresentableAsLongLong(ele,&llval) == REDIS_OK) { + if (isObjectRepresentableAsLongLong(ele,&llval) == C_OK) { o->ptr = intsetAdd(o->ptr,llval,NULL); } else { setTypeConvert(o,OBJ_ENCODING_HT); @@ -1241,7 +1241,7 @@ int rdbLoad(char *filename) { FILE *fp; rio rdb; - if ((fp = fopen(filename,"r")) == NULL) return REDIS_ERR; + if ((fp = fopen(filename,"r")) == NULL) return C_ERR; rioInitWithFile(&rdb,fp); rdb.update_cksum = rdbLoadProgressCallback; @@ -1252,14 +1252,14 @@ int rdbLoad(char *filename) { fclose(fp); serverLog(REDIS_WARNING,"Wrong signature trying to load DB from file"); errno = EINVAL; - return REDIS_ERR; + return C_ERR; } rdbver = atoi(buf+5); if (rdbver < 1 || rdbver > REDIS_RDB_VERSION) { fclose(fp); serverLog(REDIS_WARNING,"Can't handle RDB format version %d",rdbver); errno = EINVAL; - return REDIS_ERR; + return C_ERR; } startLoading(fp); @@ -1381,12 +1381,12 @@ int rdbLoad(char *filename) { fclose(fp); stopLoading(); - return REDIS_OK; + return C_OK; 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."); 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. @@ -1397,10 +1397,10 @@ void backgroundSaveDoneHandlerDisk(int exitcode, int bysignal) { "Background saving terminated with success"); server.dirty = server.dirty - server.dirty_before_bgsave; server.lastsave = time(NULL); - server.lastbgsave_status = REDIS_OK; + server.lastbgsave_status = C_OK; } else if (!bysignal && exitcode != 0) { serverLog(REDIS_WARNING, "Background saving error"); - server.lastbgsave_status = REDIS_ERR; + server.lastbgsave_status = C_ERR; } else { 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 * tirggering an error conditon. */ if (bysignal != SIGUSR1) - server.lastbgsave_status = REDIS_ERR; + server.lastbgsave_status = C_ERR; } server.rdb_child_pid = -1; 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; /* 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) */ - 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. @@ -1516,7 +1516,7 @@ void backgroundSaveDoneHandlerSocket(int exitcode, int bysignal) { } 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. */ @@ -1546,12 +1546,12 @@ int rdbSaveToSlavesSockets(void) { long long start; 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 * send back to the parent the IDs of the slaves that successfully * 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_write_result_to_parent = pipefds[1]; @@ -1594,10 +1594,10 @@ int rdbSaveToSlavesSockets(void) { redisSetProcTitle("redis-rdb-to-slaves"); retval = rdbSaveRioWithEOFMark(&slave_sockets,NULL); - if (retval == REDIS_OK && rioFlush(&slave_sockets) == 0) - retval = REDIS_ERR; + if (retval == C_OK && rioFlush(&slave_sockets) == 0) + retval = C_ERR; - if (retval == REDIS_OK) { + if (retval == C_OK) { size_t private_dirty = zmalloc_get_private_dirty(); if (private_dirty) { @@ -1641,12 +1641,12 @@ int rdbSaveToSlavesSockets(void) { write(server.rdb_pipe_write_result_to_parent,msg,msglen) != msglen) { - retval = REDIS_ERR; + retval = C_ERR; } zfree(msg); } zfree(clientids); - exitFromChild((retval == REDIS_OK) ? 0 : 1); + exitFromChild((retval == C_OK) ? 0 : 1); } else { /* Parent */ zfree(clientids); /* Not used by parent. Free ASAP. */ @@ -1659,7 +1659,7 @@ int rdbSaveToSlavesSockets(void) { zfree(fds); close(pipefds[0]); close(pipefds[1]); - return REDIS_ERR; + return C_ERR; } serverLog(REDIS_NOTICE,"Background RDB transfer started by pid %d",childpid); server.rdb_save_time_start = time(NULL); @@ -1667,9 +1667,9 @@ int rdbSaveToSlavesSockets(void) { server.rdb_child_type = REDIS_RDB_CHILD_TYPE_SOCKET; updateDictResizePolicy(); zfree(fds); - return REDIS_OK; + return C_OK; } - return REDIS_OK; /* unreached */ + return C_OK; /* unreached */ } void saveCommand(client *c) { @@ -1677,7 +1677,7 @@ void saveCommand(client *c) { addReplyError(c,"Background save already in progress"); return; } - if (rdbSave(server.rdb_filename) == REDIS_OK) { + if (rdbSave(server.rdb_filename) == C_OK) { addReply(c,shared.ok); } else { addReply(c,shared.err); @@ -1689,7 +1689,7 @@ void bgsaveCommand(client *c) { addReplyError(c,"Background save already in progress"); } else if (server.aof_child_pid != -1) { 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"); } else { addReply(c,shared.err); diff --git a/src/replication.c b/src/replication.c index fdd4ddfa0..4cae1d9ad 100644 --- a/src/replication.c +++ b/src/replication.c @@ -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 * 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. */ int masterTryPartialResynchronization(client *c) { long long psync_offset, psync_len; @@ -378,7 +378,7 @@ int masterTryPartialResynchronization(client *c) { /* We still have the data our slave is asking for? */ 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 || psync_offset < server.repl_backlog_off || 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"); if (write(c->fd,buf,buflen) != buflen) { freeClientAsync(c); - return REDIS_OK; + return C_OK; } psync_len = addReplyReplicationBacklog(c,psync_offset); serverLog(REDIS_NOTICE, @@ -419,7 +419,7 @@ int masterTryPartialResynchronization(client *c) { * has this state from the previous connection with the master. */ 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: /* We need a full resync for some reason... notify the client. */ @@ -432,16 +432,16 @@ need_full_resync: server.runid,psync_offset); if (write(c->fd,buf,buflen) != buflen) { 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 * socket target depending on the configuration, and making sure that * 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 retval; @@ -455,7 +455,7 @@ int startBgsaveForReplication(void) { /* Flush the script cache, since we need that slave differences are * accumulated without requiring slaves to match our cached scripts. */ - if (retval == REDIS_OK) replicationScriptCacheFlush(); + if (retval == C_OK) replicationScriptCacheFlush(); return retval; } @@ -493,7 +493,7 @@ void syncCommand(client *c) { * So the slave knows the new runid and offset to try a PSYNC later * if the connection with the master is lost. */ if (!strcasecmp(c->argv[0]->ptr,"psync")) { - if (masterTryPartialResynchronization(c) == REDIS_OK) { + if (masterTryPartialResynchronization(c) == C_OK) { server.stat_sync_partial_ok++; return; /* No full resync needed, return. */ } else { @@ -562,7 +562,7 @@ void syncCommand(client *c) { serverLog(REDIS_NOTICE,"Delay next BGSAVE for SYNC"); } else { /* 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"); addReplyError(c,"Unable to perform background save"); return; @@ -610,7 +610,7 @@ void replconfCommand(client *c) { long port; if ((getLongFromObjectOrReply(c,c->argv[j+1], - &port,NULL) != REDIS_OK)) + &port,NULL) != C_OK)) return; c->slave_listening_port = port; } else if (!strcasecmp(c->argv[j]->ptr,"ack")) { @@ -620,7 +620,7 @@ void replconfCommand(client *c) { long long offset; 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; if (offset > c->repl_ack_off) 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 * other slave was accumulating differences). * - * The argument bgsaveerr is REDIS_OK if the background saving succeeded - * otherwise REDIS_ERR is passed to the function. + * The argument bgsaveerr is C_OK if the background saving succeeded + * otherwise C_ERR is passed to the function. * The 'type' argument is the type of the child that terminated * (if it had a disk or socket target). */ 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_ack_time = server.unixtime; /* Timeout otherwise. */ } else { - if (bgsaveerr != REDIS_OK) { + if (bgsaveerr != C_OK) { freeClient(slave); serverLog(REDIS_WARNING,"SYNC failed. BGSAVE child returned an error"); continue; @@ -802,7 +802,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) { } } if (startbgsave) { - if (startBgsaveForReplication() != REDIS_OK) { + if (startBgsaveForReplication() != C_OK) { listIter li; listRewind(server.slaves,&li); @@ -1028,7 +1028,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { * time for non blocking loading. */ aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE); 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"); replicationAbortSyncTransfer(); return; @@ -1045,7 +1045,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { int retry = 10; 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."); sleep(1); } @@ -1389,7 +1389,7 @@ int connectWithMaster(void) { if (fd == -1) { serverLog(REDIS_WARNING,"Unable to connect to MASTER: %s", strerror(errno)); - return REDIS_ERR; + return C_ERR; } if (aeCreateFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE,syncWithMaster,NULL) == @@ -1397,13 +1397,13 @@ int connectWithMaster(void) { { close(fd); 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_s = fd; server.repl_state = REDIS_REPL_CONNECTING; - return REDIS_OK; + return C_OK; } /* This function can be called when a non blocking connection is currently @@ -1496,7 +1496,7 @@ void slaveofCommand(client *c) { } else { long port; - if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != REDIS_OK)) + if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != C_OK)) return; /* Check if we are already attached to the specified slave */ @@ -1849,10 +1849,10 @@ void waitCommand(client *c) { long long offset = c->woff; /* Argument parsing. */ - if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != REDIS_OK) + if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != C_OK) return; if (getTimeoutFromObjectOrReply(c,c->argv[2],&timeout,UNIT_MILLISECONDS) - != REDIS_OK) return; + != C_OK) return; /* First try without blocking at all. */ ackreplicas = replicationCountAcksByOffset(c->woff); @@ -1973,7 +1973,7 @@ void replicationCron(void) { if (server.repl_state == REDIS_REPL_CONNECT) { serverLog(REDIS_NOTICE,"Connecting to MASTER %s:%d", server.masterhost, server.masterport); - if (connectWithMaster() == REDIS_OK) { + if (connectWithMaster() == C_OK) { serverLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started"); } } @@ -2090,7 +2090,7 @@ void replicationCron(void) { if (slaves_waiting && max_idle > server.repl_diskless_sync_delay) { /* Start a BGSAVE. Usually with socket target, or with disk target * 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 * from WAIT_BGSAVE_START to WAIT_BGSAVE_END in case * the current target is disk. Otherwise it was already done diff --git a/src/scripting.c b/src/scripting.c index 9364d8b19..0f6e1f5c3 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -330,7 +330,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { goto cleanup; } else if (server.stop_writes_on_bgsave_err && server.saveparamslen > 0 && - server.lastbgsave_status == REDIS_ERR) + server.lastbgsave_status == C_ERR) { luaPushError(lua, shared.bgsaveerr->ptr); goto cleanup; @@ -344,7 +344,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { if (server.maxmemory && server.lua_write_dirty == 0 && (cmd->flags & REDIS_CMD_DENYOOM)) { - if (freeMemoryIfNeeded() == REDIS_ERR) { + if (freeMemoryIfNeeded() == C_ERR) { luaPushError(lua, shared.oomerr->ptr); goto cleanup; } @@ -881,8 +881,8 @@ void luaSetGlobalArray(lua_State *lua, char *var, robj **elev, int elec) { * * f_ * - * On success REDIS_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 success C_OK is returned, and nothing is left on the Lua stack. + * On error C_ERR is returned and an appropriate error is set in the * client context. */ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) { sds funcdef = sdsempty(); @@ -898,14 +898,14 @@ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) { lua_tostring(lua,-1)); lua_pop(lua,1); sdsfree(funcdef); - return REDIS_ERR; + return C_ERR; } sdsfree(funcdef); if (lua_pcall(lua,0,0,0)) { addReplyErrorFormat(c,"Error running script (new function): %s\n", lua_tostring(lua,-1)); lua_pop(lua,1); - return REDIS_ERR; + return C_ERR; } /* 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); incrRefCount(body); } - return REDIS_OK; + return C_OK; } void evalGenericCommand(client *c, int evalsha) { @@ -942,7 +942,7 @@ void evalGenericCommand(client *c, int evalsha) { server.lua_write_dirty = 0; /* 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; if (numkeys > (c->argc - 3)) { 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); 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. */ /* The error is sent to the client by luaCreateFunction() - * itself when it returns REDIS_ERR. */ + * itself when it returns C_ERR. */ return; } /* Now the following is guaranteed to return non nil */ @@ -1175,7 +1175,7 @@ void scriptCommand(client *c) { sha = sdsnewlen(funcname+2,40); if (dictFind(server.lua_scripts,sha) == NULL) { if (luaCreateFunction(c,server.lua,funcname,c->argv[2]) - == REDIS_ERR) { + == C_ERR) { sdsfree(sha); return; } diff --git a/src/sentinel.c b/src/sentinel.c index 6de90f997..60cedfda6 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -331,7 +331,7 @@ static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) { /* Nothing should be attached when something is already attached */ if (ac->ev.data != NULL) - return REDIS_ERR; + return C_ERR; /* Create container for context and r/w events */ e = (redisAeEvents*)zmalloc(sizeof(*e)); @@ -348,7 +348,7 @@ static int redisAeAttach(aeEventLoop *loop, redisAsyncContext *ac) { ac->ev.cleanup = redisAeCleanup; ac->ev.data = e; - return REDIS_OK; + return C_OK; } /* ============================= Prototypes ================================= */ @@ -1012,16 +1012,16 @@ instanceLink *releaseInstanceLink(instanceLink *link, sentinelRedisInstance *ri) * a single connection, will send a single PING per second for failure * detection and so forth. * - * Return REDIS_OK if a matching Sentinel was found in the context of a - * different master and sharing was performed. Otherwise REDIS_ERR + * Return C_OK if a matching Sentinel was found in the context of a + * different master and sharing was performed. Otherwise C_ERR * is returned. */ int sentinelTryConnectionSharing(sentinelRedisInstance *ri) { serverAssert(ri->flags & SRI_SENTINEL); dictIterator *di; dictEntry *de; - if (ri->runid == NULL) return REDIS_ERR; /* No way to identify it. */ - if (ri->link->refcount > 1) return REDIS_ERR; /* Already shared. */ + if (ri->runid == NULL) return C_ERR; /* No way to identify it. */ + if (ri->link->refcount > 1) return C_ERR; /* Already shared. */ di = dictGetIterator(sentinel.masters); while((de = dictNext(di)) != NULL) { @@ -1039,10 +1039,10 @@ int sentinelTryConnectionSharing(sentinelRedisInstance *ri) { releaseInstanceLink(ri->link,NULL); ri->link = match->link; match->link->refcount++; - return REDIS_OK; + return C_OK; } dictReleaseIterator(di); - return REDIS_ERR; + return C_ERR; } /* 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 * just to cleanup our link state. */ 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) { @@ -1447,8 +1447,8 @@ int sentinelResetMastersByPattern(char *pattern, int flags) { * * This is used to handle the +switch-master event. * - * The function returns REDIS_ERR if the address can't be resolved for some - * reason. Otherwise REDIS_OK is returned. */ + * The function returns C_ERR if the address can't be resolved for some + * reason. Otherwise C_OK is returned. */ int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip, int port) { sentinelAddr *oldaddr, *newaddr; sentinelAddr **slaves = NULL; @@ -1457,7 +1457,7 @@ int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *ip, dictEntry *de; 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. * 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. */ releaseSentinelAddr(oldaddr); sentinelFlushConfig(); - return REDIS_OK; + return C_OK; } /* 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 (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); if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, - "CLIENT SETNAME %s", name) == REDIS_OK) + "CLIENT SETNAME %s", name) == C_OK) { ri->link->pending_commands++; } @@ -1946,7 +1946,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) { retval = redisAsyncCommand(link->pc, sentinelReceiveHelloMessages, ri, "SUBSCRIBE %s", SENTINEL_HELLO_CHANNEL); - if (retval != REDIS_OK) { + if (retval != C_OK) { /* If we can't subscribe, the Pub/Sub connection is useless * and we can simply disconnect it and try again. */ instanceLinkCloseConnection(link,link->pc); @@ -2172,7 +2172,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { int retval = sentinelSendSlaveOf(ri, ri->master->addr->ip, ri->master->addr->port); - if (retval == REDIS_OK) + if (retval == C_OK) sentinelEvent(REDIS_NOTICE,"+convert-to-slave",ri,"%@"); } } @@ -2195,7 +2195,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { int retval = sentinelSendSlaveOf(ri, ri->master->addr->ip, ri->master->addr->port); - if (retval == REDIS_OK) + if (retval == C_OK) sentinelEvent(REDIS_NOTICE,"+fix-slave-config",ri,"%@"); } } @@ -2279,7 +2279,7 @@ void sentinelPingReplyCallback(redisAsyncContext *c, void *reply, void *privdata { if (redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, - "SCRIPT KILL") == REDIS_OK) + "SCRIPT KILL") == C_OK) ri->link->pending_commands++; 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, * master_name,master_ip,master_port,master_config_epoch. * - * Returns REDIS_OK if the PUBLISH was queued correctly, otherwise - * REDIS_ERR is returned. */ + * Returns C_OK if the PUBLISH was queued correctly, otherwise + * C_ERR is returned. */ int sentinelSendHello(sentinelRedisInstance *ri) { char ip[REDIS_IP_STR_LEN]; char payload[REDIS_IP_STR_LEN+1024]; @@ -2448,7 +2448,7 @@ int sentinelSendHello(sentinelRedisInstance *ri) { sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->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 * obtain our own IP address. */ @@ -2456,7 +2456,7 @@ int sentinelSendHello(sentinelRedisInstance *ri) { announce_ip = sentinel.announce_ip; } else { if (anetSockName(ri->link->cc->c.fd,ip,sizeof(ip),NULL) == -1) - return REDIS_ERR; + return C_ERR; announce_ip = ip; } announce_port = sentinel.announce_port ? @@ -2474,9 +2474,9 @@ int sentinelSendHello(sentinelRedisInstance *ri) { retval = redisAsyncCommand(ri->link->cc, sentinelPublishReplyCallback, ri, "PUBLISH %s %s", SENTINEL_HELLO_CHANNEL,payload); - if (retval != REDIS_OK) return REDIS_ERR; + if (retval != C_OK) return C_ERR; ri->link->pending_commands++; - return REDIS_OK; + return C_OK; } /* 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 * to the other Sentinels ASAP. */ 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)) master->last_pub_time -= (SENTINEL_PUBLISH_PERIOD+1); sentinelForceHelloUpdateDictOfRedisInstances(master->sentinels); sentinelForceHelloUpdateDictOfRedisInstances(master->slaves); - return REDIS_OK; + return C_OK; } /* 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 retval = redisAsyncCommand(ri->link->cc, sentinelPingReplyCallback, ri, "PING"); - if (retval == REDIS_OK) { + if (retval == C_OK) { ri->link->pending_commands++; ri->link->last_ping_time = mstime(); /* 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. */ retval = redisAsyncCommand(ri->link->cc, 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 && (now - ri->link->last_ping_time) > ping_period/2) { /* Send PING to all the three kinds of instances. */ @@ -2905,9 +2905,9 @@ void sentinelCommand(client *c) { int isdown = 0; 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) - != REDIS_OK) + != C_OK) return; ri = getSentinelRedisInstanceByAddrAndRunID(sentinel.masters, c->argv[2]->ptr,port,NULL); @@ -2985,9 +2985,9 @@ void sentinelCommand(client *c) { if (c->argc != 6) goto numargserr; if (getLongFromObjectOrReply(c,c->argv[5],&quorum,"Invalid quorum") - != REDIS_OK) return; + != C_OK) return; if (getLongFromObjectOrReply(c,c->argv[4],&port,"Invalid port") - != REDIS_OK) return; + != C_OK) return; if (quorum <= 0) { addReplyError(c, "Quorum must be 1 or greater."); @@ -3267,20 +3267,20 @@ void sentinelSetCommand(client *c) { if (!strcasecmp(option,"down-after-milliseconds")) { /* down-after-millisecodns */ - if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) goto badfmt; ri->down_after_period = ll; sentinelPropagateDownAfterPeriod(ri); changes++; } else if (!strcasecmp(option,"failover-timeout")) { /* failover-timeout */ - if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) goto badfmt; ri->failover_timeout = ll; changes++; } else if (!strcasecmp(option,"parallel-syncs")) { /* parallel-syncs */ - if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) goto badfmt; ri->parallel_syncs = ll; changes++; @@ -3314,7 +3314,7 @@ void sentinelSetCommand(client *c) { changes++; } else if (!strcasecmp(option,"quorum")) { /* quorum */ - if (getLongLongFromObject(o,&ll) == REDIS_ERR || ll <= 0) + if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) goto badfmt; ri->quorum = ll; changes++; @@ -3543,7 +3543,7 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f sentinel.current_epoch, (master->failover_state > SENTINEL_FAILOVER_STATE_NONE) ? sentinel.myid : "*"); - if (retval == REDIS_OK) ri->link->pending_commands++; + if (retval == C_OK) ri->link->pending_commands++; } dictReleaseIterator(di); } @@ -3690,8 +3690,8 @@ char *sentinelGetLeader(sentinelRedisInstance *master, uint64_t epoch) { * * If Host is NULL the function sends "SLAVEOF NO ONE". * - * The command returns REDIS_OK if the SLAVEOF command was accepted for - * (later) delivery otherwise REDIS_ERR. The command replies are just + * The command returns C_OK if the SLAVEOF command was accepted for + * (later) delivery otherwise C_ERR. The command replies are just * discarded. */ int sentinelSendSlaveOf(sentinelRedisInstance *ri, char *host, int port) { 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. */ retval = redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, "MULTI"); - if (retval == REDIS_ERR) return retval; + if (retval == C_ERR) return retval; ri->link->pending_commands++; retval = redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, "SLAVEOF %s %s", host, portstr); - if (retval == REDIS_ERR) return retval; + if (retval == C_ERR) return retval; ri->link->pending_commands++; retval = redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, "CONFIG REWRITE"); - if (retval == REDIS_ERR) return retval; + if (retval == C_ERR) return retval; ri->link->pending_commands++; /* CLIENT KILL 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). */ retval = redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, "CLIENT KILL TYPE normal"); - if (retval == REDIS_ERR) return retval; + if (retval == C_ERR) return retval; ri->link->pending_commands++; retval = redisAsyncCommand(ri->link->cc, sentinelDiscardReplyCallback, ri, "EXEC"); - if (retval == REDIS_ERR) return retval; + if (retval == C_ERR) return retval; ri->link->pending_commands++; - return REDIS_OK; + return C_OK; } /* 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 * if INFO returns a different role (master instead of slave). */ retval = sentinelSendSlaveOf(ri->promoted_slave,NULL,0); - if (retval != REDIS_OK) return; + if (retval != C_OK) return; sentinelEvent(REDIS_NOTICE, "+failover-state-wait-promotion", ri->promoted_slave,"%@"); ri->failover_state = SENTINEL_FAILOVER_STATE_WAIT_PROMOTION; @@ -4052,7 +4052,7 @@ void sentinelFailoverDetectEnd(sentinelRedisInstance *master) { retval = sentinelSendSlaveOf(slave, master->promoted_slave->addr->ip, master->promoted_slave->addr->port); - if (retval == REDIS_OK) { + if (retval == C_OK) { sentinelEvent(REDIS_NOTICE,"+slave-reconf-sent-be",slave,"%@"); slave->flags |= SRI_RECONF_SENT; } @@ -4109,7 +4109,7 @@ void sentinelFailoverReconfNextSlave(sentinelRedisInstance *master) { retval = sentinelSendSlaveOf(slave, master->promoted_slave->addr->ip, master->promoted_slave->addr->port); - if (retval == REDIS_OK) { + if (retval == C_OK) { slave->flags |= SRI_RECONF_SENT; slave->slave_reconf_sent_time = mstime(); sentinelEvent(REDIS_NOTICE,"+slave-reconf-sent",slave,"%@"); diff --git a/src/server.c b/src/server.c index 4a2483f66..33019efa6 100644 --- a/src/server.c +++ b/src/server.c @@ -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 * not ok doing so inside the signal handler. */ 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"); 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.lastbgsave_try > REDIS_BGSAVE_RETRY_DELAY || - server.lastbgsave_status == REDIS_OK)) + server.lastbgsave_status == C_OK)) { serverLog(REDIS_NOTICE,"%d changes in %d seconds. Saving...", 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 * an higher frequency. */ run_with_period(1000) { - if (server.aof_last_write_status == REDIS_ERR) + if (server.aof_last_write_status == C_ERR) flushAppendOnlyFile(0); } @@ -1451,7 +1451,7 @@ void initServerConfig(void) { server.aof_last_fsync = time(NULL); server.aof_rewrite_time_last = -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_fd = -1; 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 * 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 * impossible to bind, or no bind addresses were specified in the server * 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", server.bindaddr[j] ? server.bindaddr[j] : "*", port, server.neterr); - return REDIS_ERR; + return C_ERR; } anetNonBlock(NULL,fds[*count]); (*count)++; } - return REDIS_OK; + return C_OK; } /* 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. */ 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); /* Open the listening Unix domain socket. */ @@ -1848,8 +1848,8 @@ void initServer(void) { server.stat_starttime = time(NULL); server.stat_peak_memory = 0; server.resident_set_size = 0; - server.lastbgsave_status = REDIS_OK; - server.aof_last_write_status = REDIS_OK; + server.lastbgsave_status = C_OK; + server.aof_last_write_status = C_OK; server.aof_last_write_errno = 0; server.repl_good_slaves_count = 0; updateCachedTime(); @@ -2187,7 +2187,7 @@ int processCommand(client *c) { if (!strcasecmp(c->argv[0]->ptr,"quit")) { addReply(c,shared.ok); c->flags |= REDIS_CLOSE_AFTER_REPLY; - return REDIS_ERR; + return C_ERR; } /* Now lookup the command and check ASAP about trivial error conditions @@ -2197,13 +2197,13 @@ int processCommand(client *c) { flagTransaction(c); addReplyErrorFormat(c,"unknown command '%s'", (char*)c->argv[0]->ptr); - return REDIS_OK; + return C_OK; } else if ((c->cmd->arity > 0 && c->cmd->arity != c->argc) || (c->argc < -c->cmd->arity)) { flagTransaction(c); addReplyErrorFormat(c,"wrong number of arguments for '%s' command", c->cmd->name); - return REDIS_OK; + return C_OK; } /* Check if the user is authenticated */ @@ -2211,7 +2211,7 @@ int processCommand(client *c) { { flagTransaction(c); addReply(c,shared.noautherr); - return REDIS_OK; + return C_OK; } /* If cluster is enabled perform the cluster redirection here. @@ -2229,14 +2229,14 @@ int processCommand(client *c) { if (server.cluster->state != REDIS_CLUSTER_OK) { flagTransaction(c); clusterRedirectClient(c,NULL,0,REDIS_CLUSTER_REDIR_DOWN_STATE); - return REDIS_OK; + return C_OK; } else { int error_code; clusterNode *n = getNodeByQuery(c,c->cmd,c->argv,c->argc,&hashslot,&error_code); if (n == NULL || n != server.cluster->myself) { flagTransaction(c); clusterRedirectClient(c,n,hashslot,error_code); - return REDIS_OK; + return C_OK; } } } @@ -2248,10 +2248,10 @@ int processCommand(client *c) { * is returning an error. */ if (server.maxmemory) { 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); 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. */ if (((server.stop_writes_on_bgsave_err && server.saveparamslen > 0 && - server.lastbgsave_status == REDIS_ERR) || - server.aof_last_write_status == REDIS_ERR) && + server.lastbgsave_status == C_ERR) || + server.aof_last_write_status == C_ERR) && server.masterhost == NULL && (c->cmd->flags & REDIS_CMD_WRITE || c->cmd->proc == pingCommand)) { flagTransaction(c); - if (server.aof_last_write_status == REDIS_OK) + if (server.aof_last_write_status == C_OK) addReply(c, shared.bgsaveerr); else addReplySds(c, sdscatprintf(sdsempty(), "-MISCONF Errors writing to the AOF file: %s\r\n", 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 @@ -2286,7 +2286,7 @@ int processCommand(client *c) { { flagTransaction(c); addReply(c, shared.noreplicaserr); - return REDIS_OK; + return C_OK; } /* 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) { addReply(c, shared.roslaveerr); - return REDIS_OK; + return C_OK; } /* 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 != punsubscribeCommand) { 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 @@ -2318,14 +2318,14 @@ int processCommand(client *c) { { flagTransaction(c); addReply(c, shared.masterdownerr); - return REDIS_OK; + return C_OK; } /* Loading DB? Return an error if the command has not the * REDIS_CMD_LOADING flag. */ if (server.loading && !(c->cmd->flags & REDIS_CMD_LOADING)) { addReply(c, shared.loadingerr); - return REDIS_OK; + return C_OK; } /* Lua script too slow? Only allow a limited number of commands. */ @@ -2341,7 +2341,7 @@ int processCommand(client *c) { { flagTransaction(c); addReply(c, shared.slowscripterr); - return REDIS_OK; + return C_OK; } /* Exec the command */ @@ -2357,7 +2357,7 @@ int processCommand(client *c) { if (listLength(server.ready_keys)) handleClientsBlockedOnLists(); } - return REDIS_OK; + return C_OK; } /*================================== Shutdown =============================== */ @@ -2398,7 +2398,7 @@ int prepareForShutdown(int flags) { * shutdown or else the dataset will be lost. */ if (server.aof_state == REDIS_AOF_WAIT_REWRITE) { serverLog(REDIS_WARNING, "Writing initial AOF, can't exit."); - return REDIS_ERR; + return C_ERR; } serverLog(REDIS_WARNING, "There is a child rewriting the AOF. Killing it!"); @@ -2411,14 +2411,14 @@ int prepareForShutdown(int flags) { if ((server.saveparamslen > 0 && !nosave) || save) { serverLog(REDIS_NOTICE,"Saving the final RDB snapshot before exiting."); /* 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 * operating. Note that if there was a background saving process, * in the next cron() Redis will be notified that the background * saving aborted, handling special stuff like slaves pending for * synchronization... */ serverLog(REDIS_WARNING,"Error trying to save the DB, can't exit."); - return REDIS_ERR; + return C_ERR; } } if (server.daemonize || server.pidfile) { @@ -2429,7 +2429,7 @@ int prepareForShutdown(int flags) { closeListeningSockets(1); serverLog(REDIS_WARNING,"%s is now ready to exit, bye bye...", server.sentinel_mode ? "Sentinel" : "Redis"); - return REDIS_OK; + return C_OK; } /*================================== Commands =============================== */ @@ -2828,7 +2828,7 @@ sds genRedisInfoString(char *section) { server.dirty, server.rdb_child_pid != -1, (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_child_pid == -1) ? -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_child_pid == -1) ? -1 : time(NULL)-server.aof_rewrite_time_start), - (server.aof_lastbgrewrite_status == REDIS_OK) ? "ok" : "err", - (server.aof_last_write_status == REDIS_OK) ? "ok" : "err"); + (server.aof_lastbgrewrite_status == C_OK) ? "ok" : "err", + (server.aof_last_write_status == C_OK) ? "ok" : "err"); if (server.aof_state != REDIS_AOF_OFF) { info = sdscatprintf(info, @@ -3146,7 +3146,7 @@ void monitorCommand(client *c) { * evict accordingly to the configured policy. * * 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 * used by the server. * @@ -3288,10 +3288,10 @@ int freeMemoryIfNeeded(void) { } /* 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) - 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. */ mem_tofree = mem_used - server.maxmemory; @@ -3417,12 +3417,12 @@ int freeMemoryIfNeeded(void) { if (!keys_freed) { latencyEndMonitor(latency); latencyAddSampleIfNeeded("eviction-cycle",latency); - return REDIS_ERR; /* nothing to free... */ + return C_ERR; /* nothing to free... */ } } latencyEndMonitor(latency); latencyAddSampleIfNeeded("eviction-cycle",latency); - return REDIS_OK; + return C_OK; } /* =================================== Main! ================================ */ @@ -3613,10 +3613,10 @@ int checkForSentinelMode(int argc, char **argv) { void loadDataFromDisk(void) { long long start = ustime(); 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); } else { - if (rdbLoad(server.rdb_filename) == REDIS_OK) { + if (rdbLoad(server.rdb_filename) == C_OK) { serverLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds", (float)(ustime()-start)/1000000); } else if (errno != ENOENT) { @@ -3879,7 +3879,7 @@ int main(int argc, char **argv) { checkTcpBacklogSettings(); loadDataFromDisk(); if (server.cluster_enabled) { - if (verifyClusterConfigWithData() == REDIS_ERR) { + if (verifyClusterConfigWithData() == C_ERR) { serverLog(REDIS_WARNING, "You can't have keys in a DB different than DB 0 when in " "Cluster mode. Exiting."); diff --git a/src/server.h b/src/server.h index 6677d8419..f5350c363 100644 --- a/src/server.h +++ b/src/server.h @@ -71,8 +71,8 @@ typedef long long mstime_t; /* millisecond time type. */ #include "crc64.h" /* Error codes */ -#define REDIS_OK 0 -#define REDIS_ERR -1 +#define C_OK 0 +#define C_ERR -1 /* Static server configuration */ #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_rewrite_time_last; /* Time used by last AOF rewrite run. */ 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 */ 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_load_truncated; /* Don't stop on unexpected AOF EOF. */ /* 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_start; /* Current RDB save start time. */ 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 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. */ diff --git a/src/slowlog.c b/src/slowlog.c index 21f1842bf..484cf06bf 100644 --- a/src/slowlog.c +++ b/src/slowlog.c @@ -143,7 +143,7 @@ void slowlogCommand(client *c) { slowlogEntry *se; if (c->argc == 3 && - getLongFromObjectOrReply(c,c->argv[2],&count,NULL) != REDIS_OK) + getLongFromObjectOrReply(c,c->argv[2],&count,NULL) != C_OK) return; listRewind(server.slowlog,&li); diff --git a/src/sort.c b/src/sort.c index a3b0b750c..cea4cb9cc 100644 --- a/src/sort.c +++ b/src/sort.c @@ -233,9 +233,9 @@ void sortCommand(client *c) { alpha = 1; } else if (!strcasecmp(c->argv[j]->ptr,"limit") && leftargs >= 2) { if ((getLongFromObjectOrReply(c, c->argv[j+1], &limit_start, NULL) - != REDIS_OK) || + != C_OK) || (getLongFromObjectOrReply(c, c->argv[j+2], &limit_count, NULL) - != REDIS_OK)) + != C_OK)) { syntax_error++; break; diff --git a/src/t_hash.c b/src/t_hash.c index e94238f5e..8700f406d 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -266,7 +266,7 @@ int hashTypeDelete(robj *o, robj *field) { decrRefCount(field); } 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; /* Always check if the dictionary needs a resize after a delete. */ @@ -320,8 +320,8 @@ void hashTypeReleaseIterator(hashTypeIterator *hi) { zfree(hi); } -/* Move to the next entry in the hash. Return REDIS_OK when the next entry - * could be found and REDIS_ERR when the iterator reaches the end. */ +/* Move to the next entry in the hash. Return C_OK when the next entry + * could be found and C_ERR when the iterator reaches the end. */ int hashTypeNext(hashTypeIterator *hi) { if (hi->encoding == OBJ_ENCODING_ZIPLIST) { unsigned char *zl; @@ -340,7 +340,7 @@ int hashTypeNext(hashTypeIterator *hi) { serverAssert(vptr != NULL); 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) */ vptr = ziplistNext(zl, fptr); @@ -350,11 +350,11 @@ int hashTypeNext(hashTypeIterator *hi) { hi->fptr = fptr; hi->vptr = vptr; } 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 { 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 @@ -443,7 +443,7 @@ void hashTypeConvertZiplist(robj *o, int enc) { hi = hashTypeInitIterator(o); dict = dictCreate(&hashDictType, NULL); - while (hashTypeNext(hi) != REDIS_ERR) { + while (hashTypeNext(hi) != C_ERR) { robj *field, *value; field = hashTypeCurrentObject(hi, OBJ_HASH_KEY); @@ -539,11 +539,11 @@ void hincrbyCommand(client *c) { long long value, incr, oldvalue; 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 ((current = hashTypeGetObject(o,c->argv[2])) != NULL) { if (getLongLongFromObjectOrReply(c,current,&value, - "hash value is not an integer") != REDIS_OK) { + "hash value is not an integer") != C_OK) { decrRefCount(current); return; } @@ -573,11 +573,11 @@ void hincrbyfloatCommand(client *c) { double long value, incr; 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 ((current = hashTypeGetObject(o,c->argv[2])) != NULL) { 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); return; } @@ -756,7 +756,7 @@ void genericHgetallCommand(client *c, int flags) { addReplyMultiBulkLen(c, length); hi = hashTypeInitIterator(o); - while (hashTypeNext(hi) != REDIS_ERR) { + while (hashTypeNext(hi) != C_ERR) { if (flags & OBJ_HASH_KEY) { addHashIteratorCursorToReply(c, hi, OBJ_HASH_KEY); count++; @@ -795,7 +795,7 @@ void hscanCommand(client *c) { robj *o; 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 || checkType(c,o,OBJ_HASH)) return; scanGenericCommand(c,o,cursor); diff --git a/src/t_list.c b/src/t_list.c index 0d5ca8fe9..7fa634a66 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -308,7 +308,7 @@ void lindexCommand(client *c) { long index; robj *value = NULL; - if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK)) + if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK)) return; if (o->encoding == OBJ_ENCODING_QUICKLIST) { @@ -335,7 +335,7 @@ void lsetCommand(client *c) { long index; 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; if (o->encoding == OBJ_ENCODING_QUICKLIST) { @@ -390,8 +390,8 @@ void lrangeCommand(client *c) { robj *o; long start, end, llen, rangelen; - if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || - (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; + if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) || + (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL || checkType(c,o,OBJ_LIST)) return; @@ -436,8 +436,8 @@ void ltrimCommand(client *c) { robj *o; long start, end, llen, ltrim, rtrim; - if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || - (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; + if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) || + (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return; if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL || checkType(c,o,OBJ_LIST)) return; @@ -484,7 +484,7 @@ void lremCommand(client *c) { long toremove; long removed = 0; - if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != REDIS_OK)) + if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != C_OK)) return; 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 * we can propagate the command properly. * - * The function returns REDIS_OK if we are able to serve the client, otherwise - * REDIS_ERR is returned to signal the caller that the list POP operation + * The function returns C_OK if we are able to serve the client, otherwise + * 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 * BRPOPLPUSH that fails to push the value to the destination key as it is * of the wrong type. */ @@ -765,10 +765,10 @@ int serveClientBlockedOnList(client *receiver, robj *key, robj *dstkey, redisDb } else { /* BRPOPLPUSH failed because of wrong * 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, @@ -831,7 +831,7 @@ void handleClientsBlockedOnLists(void) { if (serveClientBlockedOnList(receiver, rl->key,dstkey,rl->db,value, - where) == REDIS_ERR) + where) == C_ERR) { /* If we failed serving the client we need * to also undo the POP operation. */ @@ -869,7 +869,7 @@ void blockingPopGenericCommand(client *c, int where) { int j; 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++) { o = lookupKeyWrite(c->db,c->argv[j]); @@ -931,7 +931,7 @@ void brpoplpushCommand(client *c) { mstime_t timeout; if (getTimeoutFromObjectOrReply(c,c->argv[3],&timeout,UNIT_SECONDS) - != REDIS_OK) return; + != C_OK) return; robj *key = lookupKeyWrite(c->db, c->argv[1]); diff --git a/src/t_set.c b/src/t_set.c index 4d8dd165b..97032fbc1 100644 --- a/src/t_set.c +++ b/src/t_set.c @@ -40,7 +40,7 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum, * an integer-encodable value, an intset will be returned. Otherwise a regular * hash table. */ robj *setTypeCreate(robj *value) { - if (isObjectRepresentableAsLongLong(value,NULL) == REDIS_OK) + if (isObjectRepresentableAsLongLong(value,NULL) == C_OK) return createIntsetObject(); return createSetObject(); } @@ -58,7 +58,7 @@ int setTypeAdd(robj *subject, robj *value) { return 1; } } else if (subject->encoding == OBJ_ENCODING_INTSET) { - if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { + if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) { uint8_t success = 0; subject->ptr = intsetAdd(subject->ptr,llval,&success); if (success) { @@ -93,7 +93,7 @@ int setTypeRemove(robj *setobj, robj *value) { return 1; } } else if (setobj->encoding == OBJ_ENCODING_INTSET) { - if (isObjectRepresentableAsLongLong(value,&llval) == REDIS_OK) { + if (isObjectRepresentableAsLongLong(value,&llval) == C_OK) { int success; setobj->ptr = intsetRemove(setobj->ptr,llval,&success); if (success) return 1; @@ -109,7 +109,7 @@ int setTypeIsMember(robj *subject, robj *value) { if (subject->encoding == OBJ_ENCODING_HT) { return dictFind((dict*)subject->ptr,value) != NULL; } 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); } } else { @@ -413,7 +413,7 @@ void spopWithCountCommand(client *c) { robj *set; /* 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) { count = (unsigned) l; } else { @@ -626,7 +626,7 @@ void srandmemberWithCountCommand(client *c) { 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) { count = (unsigned) l; } else { @@ -1112,7 +1112,7 @@ void sscanCommand(client *c) { robj *set; 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 || checkType(c,set,OBJ_SET)) return; scanGenericCommand(c,set,cursor); diff --git a/src/t_string.c b/src/t_string.c index 5bc1534e5..2fbdca696 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -37,9 +37,9 @@ static int checkStringLength(client *c, long long size) { if (size > 512*1024*1024) { 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 @@ -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 */ if (expire) { - if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != REDIS_OK) + if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != C_OK) return; if (milliseconds <= 0) { addReplyErrorFormat(c,"invalid expire time in %s",c->cmd->name); @@ -158,14 +158,14 @@ int getGenericCommand(client *c) { robj *o; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL) - return REDIS_OK; + return C_OK; if (o->type != OBJ_STRING) { addReply(c,shared.wrongtypeerr); - return REDIS_ERR; + return C_ERR; } else { addReplyBulk(c,o); - return REDIS_OK; + return C_OK; } } @@ -174,7 +174,7 @@ void getCommand(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]); setKey(c->db,c->argv[1],c->argv[2]); notifyKeyspaceEvent(REDIS_NOTIFY_STRING,"set",c->argv[1],c->db->id); @@ -186,7 +186,7 @@ void setrangeCommand(client *c) { long offset; 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; if (offset < 0) { @@ -203,7 +203,7 @@ void setrangeCommand(client *c) { } /* 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; 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 */ - if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK) + if (checkStringLength(c,offset+sdslen(value)) != C_OK) return; /* Create a copy when the object is shared or encoded. */ @@ -247,9 +247,9 @@ void getrangeCommand(client *c) { char *str, llbuf[32]; size_t strlen; - if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) + if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) return; - if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK) + if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK) return; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL || checkType(c,o,OBJ_STRING)) return; @@ -340,7 +340,7 @@ void incrDecrCommand(client *c, long long incr) { o = lookupKeyWrite(c->db,c->argv[1]); 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; if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) || @@ -383,14 +383,14 @@ void decrCommand(client *c) { void incrbyCommand(client *c) { 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); } void decrbyCommand(client *c) { 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); } @@ -400,8 +400,8 @@ void incrbyfloatCommand(client *c) { o = lookupKeyWrite(c->db,c->argv[1]); if (o != NULL && checkType(c,o,OBJ_STRING)) return; - if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != REDIS_OK || - getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != REDIS_OK) + if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != C_OK || + getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != C_OK) return; value += incr; @@ -447,7 +447,7 @@ void appendCommand(client *c) { /* "append" is an argument, so always an sds */ append = c->argv[2]; totlen = stringObjectLen(o)+sdslen(append->ptr); - if (checkStringLength(c,totlen) != REDIS_OK) + if (checkStringLength(c,totlen) != C_OK) return; /* Append the value */ diff --git a/src/t_zset.c b/src/t_zset.c index 63d19036a..0fc2a28f6 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -440,11 +440,11 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) { } else { if (((char*)min->ptr)[0] == '(') { 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; } else { 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) { @@ -452,15 +452,15 @@ static int zslParseRange(robj *min, robj *max, zrangespec *spec) { } else { if (((char*)max->ptr)[0] == '(') { 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; } else { 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 ---------------------------- */ @@ -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 * 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. * - * 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. */ int zslParseLexRangeItem(robj *item, robj **dest, int *ex) { char *c = item->ptr; switch(c[0]) { case '+': - if (c[1] != '\0') return REDIS_ERR; + if (c[1] != '\0') return C_ERR; *ex = 0; *dest = shared.maxstring; incrRefCount(shared.maxstring); - return REDIS_OK; + return C_OK; case '-': - if (c[1] != '\0') return REDIS_ERR; + if (c[1] != '\0') return C_ERR; *ex = 0; *dest = shared.minstring; incrRefCount(shared.minstring); - return REDIS_OK; + return C_OK; case '(': *ex = 1; *dest = createStringObject(c+1,sdslen(c)-1); - return REDIS_OK; + return C_OK; case '[': *ex = 0; *dest = createStringObject(c+1,sdslen(c)-1); - return REDIS_OK; + return C_OK; default: - return REDIS_ERR; + return C_ERR; } } /* 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(), * otherwise no release is needed. */ static int zslParseLexRange(robj *min, robj *max, zlexrangespec *spec) { /* The range can't be valid if objects are integer encoded. * Every item must start with ( or [. */ 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; - if (zslParseLexRangeItem(min, &spec->min, &spec->minex) == REDIS_ERR || - zslParseLexRangeItem(max, &spec->max, &spec->maxex) == REDIS_ERR) { + if (zslParseLexRangeItem(min, &spec->min, &spec->minex) == C_ERR || + zslParseLexRangeItem(max, &spec->max, &spec->maxex) == C_ERR) { if (spec->min) decrRefCount(spec->min); if (spec->max) decrRefCount(spec->max); - return REDIS_ERR; + return C_ERR; } else { - return REDIS_OK; + return C_OK; } } /* 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) { decrRefCount(spec->min); 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 - * storing it into *score. If the element does not exist REDIS_ERR is returned - * otherwise REDIS_OK is returned and *score is correctly populated. - * If 'zobj' or 'member' is NULL, REDIS_ERR is returned. */ + * storing it into *score. If the element does not exist C_ERR is returned + * otherwise C_OK is returned and *score is correctly populated. + * If 'zobj' or 'member' is NULL, C_ERR is returned. */ 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 (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) { zset *zs = zobj->ptr; dictEntry *de = dictFind(zs->dict, member); - if (de == NULL) return REDIS_ERR; + if (de == NULL) return C_ERR; *score = *(double*)dictGetVal(de); } else { 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); for (j = 0; j < elements; j++) { 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. */ @@ -1471,16 +1471,16 @@ void zremrangeGenericCommand(client *c, int rangetype) { /* Step 1: Parse the range. */ if (rangetype == ZRANGE_RANK) { - if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != REDIS_OK) || - (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK)) + if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) || + (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK)) return; } 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"); return; } } 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"); return; } @@ -1936,7 +1936,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) { int touched = 0; /* 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; if (setnum < 1) { @@ -1982,7 +1982,7 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) { j++; remaining--; for (i = 0; i < setnum; i++, j++, remaining--) { 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); return; @@ -2180,8 +2180,8 @@ void zrangeGenericCommand(client *c, int reverse) { int llen; int rangelen; - if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) || - (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return; + if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != C_OK) || + (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK)) return; if (c->argc == 5 && !strcasecmp(c->argv[4]->ptr,"withscores")) { withscores = 1; @@ -2301,7 +2301,7 @@ void genericZrangebyscoreCommand(client *c, int reverse) { 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"); return; } @@ -2317,8 +2317,8 @@ void genericZrangebyscoreCommand(client *c, int reverse) { pos++; remaining--; withscores = 1; } else if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) { - if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) || - (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return; + if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) || + (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return; pos += 3; remaining -= 3; } else { addReply(c,shared.syntaxerr); @@ -2483,7 +2483,7 @@ void zcountCommand(client *c) { int count = 0; /* 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"); return; } @@ -2560,7 +2560,7 @@ void zlexcountCommand(client *c) { int count = 0; /* 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"); return; } @@ -2651,7 +2651,7 @@ void genericZrangebylexCommand(client *c, int reverse) { 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"); return; } @@ -2664,8 +2664,8 @@ void genericZrangebylexCommand(client *c, int reverse) { while (remaining) { if (remaining >= 3 && !strcasecmp(c->argv[pos]->ptr,"limit")) { - if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != REDIS_OK) || - (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != REDIS_OK)) return; + if ((getLongFromObjectOrReply(c, c->argv[pos+1], &offset, NULL) != C_OK) || + (getLongFromObjectOrReply(c, c->argv[pos+2], &limit, NULL) != C_OK)) return; pos += 3; remaining -= 3; } else { zslFreeLexRange(&range); @@ -2835,7 +2835,7 @@ void zscoreCommand(client *c) { if ((zobj = lookupKeyReadOrReply(c,key,shared.nullbulk)) == NULL || 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); } else { addReplyDouble(c,score); @@ -2916,7 +2916,7 @@ void zscanCommand(client *c) { robj *o; 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 || checkType(c,o,OBJ_ZSET)) return; scanGenericCommand(c,o,cursor);