Skip to content

Commit

Permalink
Fix checking confirmation in redisxSetValue() / redisxSetValueAsync()
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Jan 8, 2025
1 parent 85587db commit 3a17ed5
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/redisx-tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ RedisEntry *redisxGetTable(Redis *redis, const char *table, int *n) {
* \param value A proper 0-terminated string value to store.
* \param confirm Whether we should get a confirmation from the server (requires a round-trip).
*
* \return X_SUCCESS if the variable was succesfully set, or:
* X_NO_INIT
* X_NAME_INVALID
* X_NULL
* X_NO_SERVICE
* X_FAILURE
* \return X_SUCCESS (0) if the variable was succesfully set, or:
* X_NO_INIT
* X_NAME_INVALID
* X_NULL
* X_NO_SERVICE
* X_FAILURE
*
*/
int redisxSetValue(Redis *redis, const char *table, const char *key, const char *value, boolean confirm) {
Expand All @@ -131,6 +131,13 @@ int redisxSetValue(Redis *redis, const char *table, const char *key, const char
prop_error(fn, redisxLockConnected(redis->interactive));

status = redisxSetValueAsync(redis->interactive, table, key, value, confirm);

if(confirm) {
RESP *reply = redisxReadReplyAsync(redis->interactive, &status);
if(!status) status = redisxCheckRESP(reply, RESP_INT, 0);
redisxDestroyRESP(reply);
}

redisxUnlockClient(redis->interactive);

prop_error(fn, status);
Expand All @@ -144,7 +151,7 @@ int redisxSetValue(Redis *redis, const char *table, const char *key, const char
* \param table Hashtable from which to retrieve a value or NULL if to use the global table.
* \param key Field name (i.e. variable name).
* \param value The string value to set (assumes normal string termination).'
* \param confirm Whether confirmation is required from Redis to acknowledge.
* \param confirm Whether confirmation is requested from Redis to acknowledge.
*
* \return X_SUCCESS (0) if successful, or
* X_NULL if the client or value is NULL
Expand Down Expand Up @@ -172,15 +179,6 @@ int redisxSetValueAsync(RedisClient *cl, const char *table, const char *key, con

xvprintf("Redis-X> set %s = %s on %s\n", key, value, table);

if(confirm) {
RESP *reply = redisxReadReplyAsync(cl, &status);
prop_error(fn, status);

status = redisxCheckRESP(reply, RESP_INT, 0);
redisxDestroyRESP(reply);
prop_error(fn, status);
}

return X_SUCCESS;
}

Expand Down

0 comments on commit 3a17ed5

Please sign in to comment.