From 561d65be9740e471e167de14e2acf10665d14f98 Mon Sep 17 00:00:00 2001 From: Attila Kovacs Date: Wed, 11 Dec 2024 14:09:43 +0100 Subject: [PATCH] Afew more fixes --- src/redisx-net.c | 26 +++++++++++++++++++------- src/redisx-tab.c | 4 ++-- src/redisx.c | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/redisx-net.c b/src/redisx-net.c index ab3e1e9..d9fbec9 100644 --- a/src/redisx-net.c +++ b/src/redisx-net.c @@ -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"); @@ -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"); @@ -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; @@ -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; @@ -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(); */ @@ -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; diff --git a/src/redisx-tab.c b/src/redisx-tab.c index 02f52a9..a7bd5bc 100644 --- a/src/redisx-tab.c +++ b/src/redisx-tab.c @@ -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; } @@ -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); diff --git a/src/redisx.c b/src/redisx.c index b629632..9de5dd4 100644 --- a/src/redisx.c +++ b/src/redisx.c @@ -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);