RedisX v0.9
A simple, light-weight Redis database client
Loading...
Searching...
No Matches
redisx-io.c File Reference

Macros

#define REDIS_SIMPLE_STRING_SIZE   256
 (bytes) Only store up to this many characters from Redis confirms and errors.
 
#define REDIS_TIMEOUT_SECONDS   3
 (seconds) Abort with an error if cannot send before this timeout (<=0 for not timeout)
 

Functions

int redisxAbortBlockAsync (RedisClient *cl)
 
RESPredisxArrayRequest (Redis *redis, char *args[], int lengths[], int n, int *status)
 
RESPredisxExecBlockAsync (RedisClient *cl)
 
RESPredisxReadReplyAsync (RedisClient *cl)
 
RESPredisxRequest (Redis *redis, const char *command, const char *arg1, const char *arg2, const char *arg3, int *status)
 
int redisxSendArrayRequestAsync (RedisClient *cl, char *args[], int lengths[], int n)
 
int redisxSendRequestAsync (RedisClient *cl, const char *command, const char *arg1, const char *arg2, const char *arg3)
 
int redisxSkipReplyAsync (RedisClient *cl)
 
int redisxStartBlockAsync (RedisClient *cl)
 

Detailed Description

Date
Created on Aug 26, 2024
Author
Attila Kovacs

Basic I/O (send/receive) functions for the RedisX library.

Function Documentation

◆ redisxAbortBlockAsync()

int redisxAbortBlockAsync ( RedisClient cl)

Abort an atomic transaction block. It sends DISCARD.

Parameters
clPointer to a Redis client
Returns
X_SUCCESS (0) if successful or else an error code from send() (see errno.h).
See also
redisxStartBlockAsync()

References redisxError(), redisxIgnoreReplyAsync(), TRUE, X_NULL, and X_SUCCESS.

◆ redisxArrayRequest()

RESP * redisxArrayRequest ( Redis redis,
char *  args[],
int  lengths[],
int  n,
int *  status 
)

Returns the result of the most generic type of Redis request with any number of arguments. This is not the highest throughput mode (that would be sending asynchronous pipeline request, and then asynchronously collecting the results such as with redisxSendArrayRequestAsync() / redisxReadReplyAsync(), because it requires separate network roundtrips for each and every request. But, it is simple and perfectly good method when one needs to retrieve only a few (<1000) variables per second...

Parameters
redisPointer to a Redis instance.
argsAn array of strings to send to Redis, corresponding to a single query.
lengthsArray indicating the number of bytes to send from each string argument. Zero values can be used to determine the string length automatically using strlen(), and the length argument itself may be NULL to determine the lengths of all string arguments automatically.
nNumber of string arguments.
statusPointer to the return error status, which is either
                 X_SUCCESS       on success.
                 X_NO_INIT       if the Redis client librarywas not initialized via initRedis.
                 X_NULL          if the argument is NULL or n<1.
                 X_NO_SERVICE    if not connected to Redis.
                 X_FAILURE       If there was a socket level error.
Returns
A freshly allocated RESP array containing the Redis response, or NULL if no valid response could be obtained.
See also
redisxRequest()
redisxSendArrayRequestAsync()
redisxReadReplyAsync()

References Redis::interactive, redisxError(), redisxLockEnabled(), redisxReadReplyAsync(), redisxSendArrayRequestAsync(), redisxUnlockClient(), X_NULL, X_SUCCESS, and xvprintf.

◆ redisxExecBlockAsync()

RESP * redisxExecBlockAsync ( RedisClient cl)

Finish and execute an atomic transaction block. It sends EXEC, skips through all OK and QUEUED acknowledgements, and returns the reply to the transaction block itself.

Parameters
clPointer to a Redis client
Returns
The array RESP returned by EXEC, or NULL if there was an error.
See also
redisxStartBlockAsync()
redisxAbortBlockAsync()

References REDIS_NULL, redisxDestroyRESP(), redisxError(), redisxReadReplyAsync(), redisxSkipReplyAsync(), RESP_ARRAY, RESP_ERROR, TRUE, RESP::type, and X_NULL.

◆ redisxReadReplyAsync()

RESP * redisxReadReplyAsync ( RedisClient cl)

Reads a response from Redis and returns it.

Parameters
clPointer to a Redis channel
Returns
The RESP structure for the reponse received from Redis, or NULL if an error was encountered (errno will be set to describe the error, which may either be an errno produced by recv() or EBADMSG if the message was corrupted and/or unparseable.

References FALSE, RESP::n, REDIS_INCOMPLETE_TRANSFER, REDIS_SIMPLE_STRING_SIZE, REDIS_UNEXPECTED_RESP, redisxDestroyRESP(), redisxError(), redisxReadReplyAsync(), RESP_ARRAY, RESP_BULK_STRING, RESP_ERROR, RESP_INT, RESP_PONG, RESP_SIMPLE_STRING, RESP::type, RESP::value, X_FAILURE, X_PARSE_ERROR, X_SUCCESS, and xdprintf.

◆ redisxRequest()

RESP * redisxRequest ( Redis redis,
const char *  command,
const char *  arg1,
const char *  arg2,
const char *  arg3,
int *  status 
)

Returns the result of a Redis command with up to 3 regularly terminated string arguments. This is not the highest throughput mode (that would be sending asynchronous pipeline request, and then asynchronously collecting the results such as with redisxSendRequestAsync() / redisxReadReplyAsync(), because it requires separate network roundtrips for each and every request. But, it is simple and perfectly good method when one needs to retrieve only a few (<1000) variables per second...

To make Redis calls with binary (non-string) data, you can use redisxArrayRequest() instead, where you can set the number of bytes for each argument explicitly.

Parameters
redisPointer to a Redis instance.
commandRedis command, e.g. "HGET"
arg1First terminated string argument or NULL.
arg2Second terminated string argument or NULL.
arg3Third terminated string argument or NULL.
statusPointer to the return error status, which is either X_SUCCESS on success or else the error code set by redisxArrayRequest().
Returns
A freshly allocated RESP array containing the Redis response, or NULL if no valid response could be obtained.
See also
redisxArrayRequest()
redisxSendRequestAsync()
redisxReadReplyAsync()

References redisxArrayRequest().

◆ redisxSendArrayRequestAsync()

int redisxSendArrayRequestAsync ( RedisClient cl,
char *  args[],
int  lengths[],
int  n 
)

Send a Redis request with an arbitrary number of arguments.

Parameters
clPointer to the Redis client.
argsThe array of string arguments to send.
lengthsArray indicating the number of bytes to send from each string argument. Zero or negative values can be used to determine the string length automatically using strlen(), and the length argument itself may be NULL to determine the lengths of all string arguments automatically.
nThe number of arguments to send.
Returns
0 on success or an error code on failure, is either X_NO_SERVICE (if not connected to the REDIS server on the requested channel) or the errno set by send().

References FALSE, REDIS_CMDBUF_SIZE, redisxError(), TRUE, X_NULL, and X_SUCCESS.

◆ redisxSendRequestAsync()

int redisxSendRequestAsync ( RedisClient cl,
const char *  command,
const char *  arg1,
const char *  arg2,
const char *  arg3 
)

Send a command (with up to 3 arguments) to the REDIS server. The caller must have an exclusive lock on the client for this version. The arguments supplied will be used up to the first non-NULL value.

Parameters
clPointer to the Redis client instance.
commandREDIS command string.
arg1Optional first string argument or NULL.
arg2Optional second string argument or NULL.
arg3Optional third string argument or NULL.
Returns
0 on success or an error code on failure, is either X_NO_SERVICE (if not connected to the REDIS server on the requested channel) or the errno set by send().

References redisxSendArrayRequestAsync(), X_NAME_INVALID, X_NO_INIT, and X_NULL.

◆ redisxSkipReplyAsync()

int redisxSkipReplyAsync ( RedisClient cl)

Instructs Redis to skip sending a reply for the next command.

Sends CLIENT REPLY SKIP

Parameters
clPointer to the Redis client to use.
Returns
X_SUCCESS (0) on success or an error code on failure, is either X_NO_SERVICE (if not connected to the REDIS server on the requested channel) or the errno set by send().
X_NULL      if the client is NULL.

References redisxError(), TRUE, X_NULL, and X_SUCCESS.

◆ redisxStartBlockAsync()

int redisxStartBlockAsync ( RedisClient cl)

Starts an atomic Redis transaction block, by sending MULTI on the specified client connection. Redis transaction blocks behave just like scripts (in fact they are effectively improptu scripts themselves). As such the rules of Redis scripting apply, such as you cannot call LUA from within a transaction block (which is a real pity...)

Once you start a transaction block you may ignore all acknowledgedments such as OK and QUEUED responses that Redis sends back. These will be 'processed' in bulk by redisEndBlockAsync(), at the end of the transaction block.

Parameters
clPointer to a Redis client.
Returns
X_SUCCESS (0) if successful, or X_NULL if the Redis client is NULL

or else the error set by send().

See also
redisxExecBlockAsync()
redisxAbortBlockAsync()

References redisxError(), TRUE, X_NULL, and X_SUCCESS.