RedisX v0.9
A simple, light-weight Redis database client
|
Macros | |
#define | REDIS_SIMPLE_STRING_SIZE 256 |
(bytes) Only store up to this many characters from Redis confirms and errors. | |
Functions | |
int | redisxAbortBlockAsync (RedisClient *cl) |
int | redisxClearAttributesAsync (RedisClient *cl) |
RESP * | redisxExecBlockAsync (RedisClient *cl, int *pStatus) |
const RESP * | redisxGetAttributesAsync (const RedisClient *cl) |
RedisClient * | redisxGetClient (Redis *redis, enum redisx_channel channel) |
RedisClient * | redisxGetLockedConnectedClient (Redis *redis, enum redisx_channel channel) |
int | redisxIgnoreReplyAsync (RedisClient *cl) |
int | redisxLockClient (RedisClient *cl) |
int | redisxLockConnected (RedisClient *cl) |
RESP * | redisxReadReplyAsync (RedisClient *cl, int *pStatus) |
int | redisxResetClient (RedisClient *cl) |
int | redisxSendArrayRequestAsync (RedisClient *cl, const char **args, const 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) |
Basic I/O (send/receive) functions for the RedisX library.
int redisxAbortBlockAsync | ( | RedisClient * | cl | ) |
Abort an atomic transaction block. It sends DISCARD
.
cl | Pointer to a Redis client |
References redisxIgnoreReplyAsync(), TRUE, x_error(), X_NO_INIT, and X_SUCCESS.
int redisxClearAttributesAsync | ( | RedisClient * | cl | ) |
Clears the attributes for the specified client. The caller should have an exclusive lock on the client's mutex prior to making this call.
Typically a user migh call this function prior to calling redisxReadReplyAsync() on the same client, to ensure that any attributes that are available after the read will be the ones that were sent with the last response from the server.
cl | The Redis client instance |
References X_SUCCESS.
RESP * redisxExecBlockAsync | ( | RedisClient * | cl, |
int * | pStatus | ||
) |
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.
cl | Pointer to a Redis client |
pStatus | Pointer to int in which to return error status. or NULL if not required. |
References redisxDestroyRESP(), redisxReadReplyAsync(), redisxSkipReplyAsync(), RESP_ARRAY, RESP_ERROR, TRUE, RESP::type, x_error(), X_SUCCESS, and x_trace_null().
const RESP * redisxGetAttributesAsync | ( | const RedisClient * | cl | ) |
Returns the attributes (if any) that were last sent along a response to the client. This function should be called only if the caller has an exclusive lock on the client's mutex. Also, there are a few rules the caller should follow:
Normally the user would typically call this function right after a redisxReadReplyAsync() call, for which atributes are expected. The caller might also want to call redisxClearAttributeAsync() before attempting to read the response to ensure that the attributes returned are for the same reply from the server.
cl | The Redis client instance |
References x_error().
RedisClient * redisxGetClient | ( | Redis * | redis, |
enum redisx_channel | channel | ||
) |
Returns the redis client for a given connection type in a Redis instance.
redis | Pointer to a Redis instance. |
channel | REDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, or REDISX_SUBSCRIPTION_CHANNEL |
References REDISX_CHANNELS, redisxCheckValid(), x_error(), X_SUCCESS, and x_trace_null().
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()
.
redis | Pointer to a Redis instance. |
channel | REDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, or REDISX_SUBSCRIPTION_CHANNEL |
References redisxGetClient(), redisxLockConnected(), X_SUCCESS, and x_trace_null().
int redisxIgnoreReplyAsync | ( | RedisClient * | cl | ) |
Silently consumes a reply from the specified Redis channel.
cl | Pointer to a Redis channel. |
References REDIS_NULL, redisxDestroyRESP(), redisxReadReplyAsync(), X_SUCCESS, and x_trace().
int redisxLockClient | ( | RedisClient * | cl | ) |
Get exclusive write access to the specified Redis channel.
cl | Pointer to the Redis client instance. |
int redisxLockConnected | ( | RedisClient * | cl | ) |
Lock a channel, but only if it has been enabled for communication.
cl | Pointer to the Redis client instance |
References redisxLockClient(), redisxUnlockClient(), x_error(), X_NO_INIT, X_NO_SERVICE, and X_SUCCESS.
RESP * redisxReadReplyAsync | ( | RedisClient * | cl, |
int * | pStatus | ||
) |
Reads a response from Redis and returns it.
cl | Pointer to a Redis channel |
pStatus | Pointer to int in which to return an error status, or NULL if not required. |
References FALSE, RedisMap::key, RESP::n, rCloseClientAsync(), REDIS_INCOMPLETE_TRANSFER, REDIS_SIMPLE_STRING_SIZE, REDIS_UNEXPECTED_RESP, redisxAppendRESP(), redisxDestroyRESP(), redisxHasComponents(), redisxReadReplyAsync(), RESP3_ATTRIBUTE, RESP3_BIG_NUMBER, RESP3_BLOB_ERROR, RESP3_BOOLEAN, RESP3_CONTINUED, RESP3_DOUBLE, RESP3_MAP, RESP3_NULL, RESP3_PUSH, RESP3_SET, RESP3_VERBATIM_STRING, RESP_ARRAY, RESP_BULK_STRING, RESP_ERROR, RESP_INT, RESP_SIMPLE_STRING, TRUE, RESP::type, RESP::value, RedisMap::value, x_error(), X_FAILURE, X_NO_INIT, X_NO_SERVICE, X_PARSE_ERROR, X_SUCCESS, x_trace_null(), xParseDouble(), and xStringCopyOf().
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.
cl | The Redis client |
References REDIS_UNEXPECTED_RESP, redisxCheckRESP(), redisxDestroyRESP(), redisxLockConnected(), redisxReadReplyAsync(), redisxSendRequestAsync(), redisxUnlockClient(), RESP_SIMPLE_STRING, RESP::value, x_error(), and X_SUCCESS.
int redisxSendArrayRequestAsync | ( | RedisClient * | cl, |
const char ** | args, | ||
const int * | lengths, | ||
int | n | ||
) |
Send a Redis request with an arbitrary number of arguments.
cl | Pointer to the Redis client. |
args | The array of string arguments to send. If you have an char ** array, you may need to cast to (const char **) to avoid compiler warnings. |
lengths | Array 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. |
n | The number of arguments to send. |
References FALSE, REDISX_CMDBUF_SIZE, TRUE, x_error(), X_NO_INIT, X_NO_SERVICE, X_SUCCESS, and xvprintf.
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.
cl | Pointer to the Redis client instance. |
command | Redis command string. |
arg1 | Optional first string argument or NULL. |
arg2 | Optional second string argument or NULL. |
arg3 | Optional third string argument or NULL. |
References redisxSendArrayRequestAsync(), x_error(), X_NAME_INVALID, and X_SUCCESS.
int redisxSkipReplyAsync | ( | RedisClient * | cl | ) |
Instructs Redis to skip sending a reply for the next command.
Sends CLIENT REPLY SKIP
cl | Pointer to the Redis client to use. |
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.
cl | Pointer to a Redis client. |
int redisxUnlockClient | ( | RedisClient * | cl | ) |
Relinquish exclusive write access to the specified Redis channel
cl | Pointer to the Redis client instance |