![]() |
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. | |
| #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) |
| RESP * | redisxArrayRequest (Redis *redis, char *args[], int lengths[], int n, int *status) |
| RESP * | redisxExecBlockAsync (RedisClient *cl) |
| RESP * | redisxReadReplyAsync (RedisClient *cl) |
| RESP * | redisxRequest (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) |
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 redisxError(), redisxIgnoreReplyAsync(), TRUE, X_NULL, and X_SUCCESS.
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...
| redis | Pointer to a Redis instance. |
| args | An array of strings to send to Redis, corresponding to a single query. |
| lengths | Array 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. |
| n | Number of string arguments. |
| status | Pointer 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.
|
References Redis::interactive, redisxError(), redisxLockEnabled(), redisxReadReplyAsync(), redisxSendArrayRequestAsync(), redisxUnlockClient(), X_NULL, X_SUCCESS, and xvprintf.
| 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.
| cl | Pointer to a Redis client |
References REDIS_NULL, redisxDestroyRESP(), redisxError(), redisxReadReplyAsync(), redisxSkipReplyAsync(), RESP_ARRAY, RESP_ERROR, TRUE, RESP::type, and X_NULL.
| RESP * redisxReadReplyAsync | ( | RedisClient * | cl | ) |
Reads a response from Redis and returns it.
| cl | Pointer to a Redis channel |
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.
| 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.
| redis | Pointer to a Redis instance. |
| command | Redis command, e.g. "HGET" |
| arg1 | First terminated string argument or NULL. |
| arg2 | Second terminated string argument or NULL. |
| arg3 | Third terminated string argument or NULL. |
| status | Pointer to the return error status, which is either X_SUCCESS on success or else the error code set by redisxArrayRequest(). |
References redisxArrayRequest().
| int redisxSendArrayRequestAsync | ( | RedisClient * | cl, |
| char * | args[], | ||
| 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. |
| 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, REDIS_CMDBUF_SIZE, redisxError(), TRUE, X_NULL, and X_SUCCESS.
| 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_NAME_INVALID, X_NO_INIT, and X_NULL.
| 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. |
X_NULL if the client is NULL.
References redisxError(), TRUE, X_NULL, and X_SUCCESS.
| 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. |
or else the error set by send().
References redisxError(), TRUE, X_NULL, and X_SUCCESS.