RedisX v0.9
A simple, light-weight Redis database client
Loading...
Searching...
No Matches
redisx-client.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)
 
RESPredisxExecBlockAsync (RedisClient *cl)
 
RedisClientredisxGetClient (Redis *redis, enum redisx_channel channel)
 
RedisClientredisxGetLockedConnectedClient (Redis *redis, enum redisx_channel channel)
 
int redisxIgnoreReplyAsync (RedisClient *cl)
 
int redisxLockClient (RedisClient *cl)
 
int redisxLockConnected (RedisClient *cl)
 
RESPredisxReadReplyAsync (RedisClient *cl)
 
int redisxResetClient (RedisClient *cl)
 
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)
 
int redisxUnlockClient (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 X_NULL if the client is NULL, or else X_NO_SERVICE if not connected ot the client or if send() failed.
See also
redisxStartBlockAsync()

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

◆ 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 redisxDestroyRESP(), redisxReadReplyAsync(), redisxSkipReplyAsync(), RESP_ARRAY, RESP_ERROR, TRUE, RESP::type, x_error(), and x_trace_null().

◆ redisxGetClient()

RedisClient * redisxGetClient ( Redis redis,
enum redisx_channel  channel 
)

Returns the redis client for a given connection type in a Redis instance.

Parameters
redisPointer to a Redis instance.
channelREDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, or REDISX_SUBSCRIPTION_CHANNEL
Returns
Pointer to the matching Redis client, or NULL if the channel argument is invalid.

References REDISX_CHANNELS, and x_error().

◆ redisxGetLockedConnectedClient()

RedisClient * redisxGetLockedConnectedClient ( Redis redis,
enum redisx_channel  channel 
)

Returns the redis client for a given connection type in a Redis instance, with the exclusive access lock if the client is valid and is connected, or else NULL. It is effectively the combination of redisxGetClient() followed by redisxLockConnected().

Parameters
redisPointer to a Redis instance.
channelREDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, or REDISX_SUBSCRIPTION_CHANNEL
Returns
The locked client, if it is enabled, or NULL if the redis argument is NULL, the channel is invalid, or the requested client is not currently connected.
See also
redisxGetClient()
redisxUnlockClient()
redisxLockConnected()

References redisxGetClient(), redisxLockConnected(), X_SUCCESS, and x_trace_null().

◆ redisxIgnoreReplyAsync()

int redisxIgnoreReplyAsync ( RedisClient cl)

Silently consumes a reply from the specified Redis channel.

Parameters
clPointer to a Redis channel.
Returns
X_SUCCESS if a response was successfully consumed, or REDIS_NULL if a valid response could not be obtained.

References REDIS_NULL, redisxDestroyRESP(), redisxReadReplyAsync(), x_error(), X_NULL, X_SUCCESS, and x_trace().

◆ redisxLockClient()

int redisxLockClient ( RedisClient cl)

Get exclusive write access to the specified Redis channel.

Parameters
clPointer to the Redis client instance.
Returns
X_SUCCESS if the exclusive lock for the channel was successfully obtained X_FAILURE if pthread_mutex_lock() returned an error X_NULL if the client is NULL.
See also
redisxLockConnected()
redisxUnlockClient()

References x_error(), X_FAILURE, X_NULL, and X_SUCCESS.

◆ redisxLockConnected()

int redisxLockConnected ( RedisClient cl)

Lock a channel, but only if it has been enabled for communication.

Parameters
clPointer to the Redis client instance
Returns
X_SUCCESS (0) if an excusive lock to the channel has been granted. X_FAILURE if pthread_mutex_lock() returned an error X_NULL if the client is NULL REDIS_INVALID_CHANNEL if the channel is not enabled/connected.
See also
redisxLockClient()
redisxUnlockClient()
redisxGetLockedConnectedClient()

References redisxLockClient(), redisxUnlockClient(), x_error(), X_NO_SERVICE, and X_SUCCESS.

◆ 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(), redisxReadReplyAsync(), RESP_ARRAY, RESP_BULK_STRING, RESP_ERROR, RESP_INT, RESP_SIMPLE_STRING, RESP::type, RESP::value, x_error(), X_FAILURE, X_PARSE_ERROR, X_SUCCESS, x_trace_null(), and xStringCopyOf().

◆ redisxResetClient()

int redisxResetClient ( RedisClient cl)

Sends a RESET request to the specified Redis client. The server will perform a reset as if the client disconnected and reconnected again.

Parameters
clThe Redis client
Returns
X_SUCCESS (0) if successful, or X_NULL if the client is NULL, or another error code (<0) from redisx.h / xchange.h.

References REDIS_UNEXPECTED_RESP, redisxCheckRESP(), redisxDestroyRESP(), redisxLockConnected(), redisxReadReplyAsync(), redisxSendRequestAsync(), redisxUnlockClient(), RESP_SIMPLE_STRING, RESP::value, x_error(), X_NULL, and X_SUCCESS.

◆ 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
X_SUCCESS (0) on success or X_NULL if the client is NULL, or else X_NO_SERVICE if not connected to the client or if send() failed.

References FALSE, REDISX_CMDBUF_SIZE, TRUE, x_error(), 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
X_SUCCESS (0) on success or X_NULL if the client is NULL, or else X_NO_SERVICE if not connected to the client or if send() failed

References redisxSendArrayRequestAsync(), x_error(), X_NAME_INVALID, X_NULL, and X_SUCCESS.

◆ 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 X_NULL if the client is NULL, or else X_NO_SERVICE if not connected to the Redis server on the requested channel, or if send() failed.

References TRUE, x_error(), 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 X_NO_SERVICE if not connected to the client server or if send() failed.
See also
redisxExecBlockAsync()
redisxAbortBlockAsync()

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

◆ redisxUnlockClient()

int redisxUnlockClient ( RedisClient cl)

Relinquish exclusive write access to the specified Redis channel

Parameters
clPointer to the Redis client instance
Returns
X_SUCCESS if the exclusive lock for the channel was successfully obtained X_FAILURE if pthread_mutex_lock() returned an error X_NULL if the client is NULL
See also
redisxLockClient()
redisxLockConnected()

References x_error(), X_FAILURE, X_NULL, and X_SUCCESS.