Skip to content

Commit

Permalink
Afew more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Dec 11, 2024
1 parent 68f81ee commit 561d65b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
26 changes: 19 additions & 7 deletions src/redisx-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,16 @@ static int rConfirmMasterRole(Redis *redis) {
prop_error(fn, status);
prop_error(fn, redisxCheckDestroyRESP(reply, RESP_BULK_STRING, 0));

// Go line by line...
str = strtok((char *) reply->value, "\n");

while(str) {
const char *tok = strtok(str, ":");

if(strcmp("role", tok) == 0) {
const char *role = strtok(NULL, "\n");
tok = strtok(NULL, "\n");

status = strcmp("master", role) == 0;
status = strcmp("master", tok);
redisxDestroyRESP(reply);

if(status) return x_error(X_FAILURE, EAGAIN, fn, "Replica is not master");
Expand All @@ -314,14 +315,14 @@ static int rConfirmMasterRole(Redis *redis) {
return x_error(X_FAILURE, EBADE, fn, "Got empty array response");
}

component = (RESP **) reply->value;

if(reply->n < 1) {
redisxDestroyRESP(reply);
return x_error(X_FAILURE, EBADE, fn, "Got empty array response");
}

status = strcmp("master", (char *) component[0]->value) == 0;
component = (RESP **) reply->value;
status = strcmp("master", (char *) component[0]->value);

redisxDestroyRESP(reply);

if(status) return x_error(X_FAILURE, EAGAIN, fn, "Replica is not master");
Expand Down Expand Up @@ -897,6 +898,16 @@ Redis *redisxInitSentinel(const char *serviceName, const RedisServer *serverList
RedisPrivate *p;
RedisSentinel *s;

if(!serviceName) {
x_error(0, EINVAL, fn, "input serviceName is NULL");
return NULL;
}

if(!serviceName[0]) {
x_error(0, EINVAL, fn, "input serviceName is empty");
return NULL;
}

if(!serverList) {
x_error(0, EINVAL, fn, "input serverList is NULL");
return NULL;
Expand Down Expand Up @@ -933,6 +944,7 @@ Redis *redisxInitSentinel(const char *serviceName, const RedisServer *serverList
s->nServers = nServers;
s->serviceName = xStringCopyOf(serviceName);
s->timeoutMillis = REDISX_DEFAULT_SENTINEL_TIMEOUT_MILLIS;

p->sentinel = s;

return redis;
Expand Down Expand Up @@ -1042,7 +1054,7 @@ void redisxSetTcpBuf(int size) {
* @param port The TCP port number to use.
*
* @return X_SUCCESS (0) if successful, or else X_NULL if the redis instance is NULL,
* or X_N_INIT if the redis instance is not initialized.
* or X_NO_INIT if the redis instance is not initialized.
*
* @sa redisxConnect();
*/
Expand Down Expand Up @@ -1073,7 +1085,7 @@ int redisxSetSocketTimeout(Redis *redis, int millis) {

prop_error("redisxSetPort", rConfigLock(redis));
p = (RedisPrivate *) redis->priv;
p->timeoutMillis = millis;
p->timeoutMillis = millis > 0 ? millis : REDISX_DEFAULT_TIMEOUT_MILLIS;
rConfigUnlock(redis);

return X_SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions src/redisx-tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ int redisxDeleteEntries(Redis *redis, const char *pattern) {
// If the table itself matches, delete it wholesale...
if(fnmatch(root, table, 0) == 0) {
RESP *reply = redisxRequest(redis, "DEL", table, NULL, NULL, &status);
if(!status) if(redisxCheckRESP(reply, RESP_INT, 1) == X_SUCCESS) found++;
if(status == X_SUCCESS) if(redisxCheckRESP(reply, RESP_INT, 1) == X_SUCCESS) found++;
redisxDestroyRESP(reply);
continue;
}
Expand All @@ -954,7 +954,7 @@ int redisxDeleteEntries(Redis *redis, const char *pattern) {
if(id) {
if(fnmatch(key, id, 0) == 0) {
RESP *reply = redisxRequest(redis, "HDEL", table, e->key, NULL, &status);
if(!status) if(redisxCheckRESP(reply, RESP_INT, 1) == X_SUCCESS) found++;
if(status == X_SUCCESS) if(redisxCheckRESP(reply, RESP_INT, 1) == X_SUCCESS) found++;
redisxDestroyRESP(reply);
}
free(id);
Expand Down
2 changes: 1 addition & 1 deletion src/redisx.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int redisxGetTime(Redis *redis, struct timespec *t) {
memset(t, 0, sizeof(*t));

reply = redisxRequest(redis, "TIME", NULL, NULL, NULL, &status);
if(status) return x_trace(fn, NULL, status);
prop_error(fn, status);

status = redisxCheckDestroyRESP(reply, RESP_ARRAY, 2);
prop_error(fn, status);
Expand Down

0 comments on commit 561d65b

Please sign in to comment.