RedisX v0.9
A simple, light-weight Redis database client
|
A Redis client library that compiles on older and newer platforms alike, such as LynxOS 3.1.0 PowerPCs. It is quite full featured, supporting multiple Redis instances, pipelining, user-specified connect and disconnect hooks, multiple user-specified subscription listeners, and user-specified pipeline processors. More...
Functions | |
RESP * | redisxArrayRequest (Redis *redis, char *args[], int lengths[], int n, int *status) |
int | redisxCheckDestroyRESP (RESP *resp, char expectedType, int expectedSize) |
int | redisxCheckRESP (const RESP *resp, char expectedType, int expectedSize) |
void | redisxDebugTraffic (boolean value) |
void | redisxDestroyRESP (RESP *resp) |
int | redisxError (const char *func, int errorCode) |
const char * | redisxErrorDescription (int code) |
int | redisxGetTime (Redis *redis, struct timespec *t) |
boolean | redisxHasPipeline (Redis *redis) |
boolean | redisxIsVerbose () |
int | redisxPing (Redis *redis, const char *message) |
RESP * | redisxRequest (Redis *redis, const char *command, const char *arg1, const char *arg2, const char *arg3, int *status) |
int | redisxSelectDB (Redis *redis, int idx) |
int | redisxSetPassword (Redis *redis, const char *passwd) |
int | redisxSetPipelineConsumer (Redis *redis, void(*f)(RESP *)) |
int | redisxSetTransmitErrorHandler (Redis *redis, RedisErrorHandler f) |
int | redisxSetUser (Redis *redis, const char *username) |
void | redisxSetVerbose (boolean value) |
A Redis client library that compiles on older and newer platforms alike, such as LynxOS 3.1.0 PowerPCs. It is quite full featured, supporting multiple Redis instances, pipelining, user-specified connect and disconnect hooks, multiple user-specified subscription listeners, and user-specified pipeline processors.
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, redisxLockConnected(), redisxReadReplyAsync(), redisxSendArrayRequestAsync(), redisxUnlockClient(), x_error(), X_NULL, X_SUCCESS, x_trace_null(), and xvprintf.
int redisxCheckDestroyRESP | ( | RESP * | resp, |
char | expectedType, | ||
int | expectedSize | ||
) |
Like redisxCheckRESP(), but it also destroys the RESP in case of an error.
resp | Pointer to the RESP structure from Redis. |
expectedType | The RESP type expected (e.g. RESP_ARRAY) or 0 if not checking type. |
expectedSize | The expected size of the RESP (array or bytes) or <=0 to skip checking |
References redisxCheckRESP(), and redisxDestroyRESP().
int redisxCheckRESP | ( | const RESP * | resp, |
char | expectedType, | ||
int | expectedSize | ||
) |
Checks a Redis RESP for NULL values or unexpected values.
resp | Pointer to the RESP structure from Redis. |
expectedType | The RESP type expected (e.g. RESP_ARRAY) or 0 if not checking type. |
expectedSize | The expected size of the RESP (array or bytes) or <=0 to skip checking |
or the error returned in resp->n.
References RESP::n, REDIS_NULL, REDIS_UNEXPECTED_RESP, RESP_INT, RESP::type, RESP::value, x_error(), X_FAILURE, X_NULL, and X_SUCCESS.
void redisxDebugTraffic | ( | boolean | value | ) |
Enable or disable verbose reporting of all Redis bound traffic. It may be useful when debugging programs that use the redisx interface. Verbose reporting is DISABLED by default.
value | TRUE to enable verbose reporting, or FALSE to disable. |
void redisxDestroyRESP | ( | RESP * | resp | ) |
Frees up the resources used by a RESP structure that was dynamically allocated. The call will segfault if the same RESP is destroyed twice or if the argument is a static allocation.
resp | Pointer to the RESP structure to be destroyed, which may be NULL (no action taken). |
References RESP::n, redisxDestroyRESP(), RESP_ARRAY, RESP::type, and RESP::value.
int redisxError | ( | const char * | func, |
int | errorCode | ||
) |
Prints a descriptive error message to stderr, and returns the error code.
func | A string that describes the function or location where the error occurred. |
errorCode | The error code that describes the failure. |
References MAX_DEBUG_ERROR_COUNT, REDIS_INCOMPLETE_TRANSFER, redisxErrorDescription(), and xDebug.
const char * redisxErrorDescription | ( | int | code | ) |
Returns a string description for one of the RM error codes.
code | One of the error codes defined in 'rm.h' or in 'redisrm.h' (e.g. X_NO_PIPELINE) |
References REDIS_ERROR, REDIS_INCOMPLETE_TRANSFER, REDIS_INVALID_CHANNEL, REDIS_NULL, REDIS_UNEXPECTED_ARRAY_SIZE, REDIS_UNEXPECTED_RESP, and xErrorDescription().
int redisxGetTime | ( | Redis * | redis, |
struct timespec * | t | ||
) |
Returns the current time on the Redis server instance.
redis | Pointer to a Redis instance. | |
[out] | t | Pointer to a timespec structure in which to return the server time. |
References redisxCheckDestroyRESP(), redisxCheckRESP(), redisxDestroyRESP(), redisxRequest(), RESP_ARRAY, RESP_BULK_STRING, RESP::value, x_error(), X_NULL, X_PARSE_ERROR, X_SUCCESS, and x_trace().
Checks if a Redis instance has the pipeline connection enabled.
redis | Pointer to a Redis instance. |
References FALSE, and Redis::pipeline.
boolean redisxIsVerbose | ( | ) |
Checks id verbose reporting is enabled.
References xIsVerbose().
int redisxPing | ( | Redis * | redis, |
const char * | message | ||
) |
Pings the Redis server (see the Redis PING
command), and checks the response.
redis | Pointer to a Redis instance. |
message | Optional message , or NULL for PING without an argument. |
References REDIS_UNEXPECTED_RESP, redisxCheckRESP(), redisxDestroyRESP(), redisxRequest(), RESP_BULK_STRING, RESP_SIMPLE_STRING, RESP::value, x_error(), X_NULL, and X_SUCCESS.
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(), x_error(), X_NULL, and x_trace_null().
int redisxSelectDB | ( | Redis * | redis, |
int | idx | ||
) |
Switches to another database index on the Redis server. Note that you cannot change the database on an active PUB/SUB channel, hence the call will return X_INCOMPLETE if attempted. You should instead switch DB when there are no active subscriptions.
redis | Pointer to a Redis instance. |
idx | zero-based database index |
References REDIS_INVALID_CHANNEL, REDISX_CHANNELS, REDISX_PIPELINE_CHANNEL, REDISX_SUBSCRIPTION_CHANNEL, redisxAddConnectHook(), redisxGetClient(), redisxIsConnected(), redisxLockConnected(), redisxRemoveConnectHook(), redisxUnlockClient(), x_error(), X_INCOMPLETE, X_NULL, X_SUCCESS, and x_trace().
int redisxSetPassword | ( | Redis * | redis, |
const char * | passwd | ||
) |
Sets the password to use for authenticating on the Redis server after connection. See the AUTH Redis command for more explanation. Naturally, you need to call this prior to connecting your Redis instance to have the desired effect.
redis | Pointer to the Redis instance for which to set credentials |
passwd | the password to use for authenticating on the server, or NULL to clear a previously configured password. |
References redisxIsConnected(), X_ALREADY_OPEN, x_error(), X_NULL, X_SUCCESS, and xStringCopyOf().
int redisxSetTransmitErrorHandler | ( | Redis * | redis, |
RedisErrorHandler | f | ||
) |
Sets the user-specific error handler to call if a socket level trasmit error occurs. It replaces any prior handlers set earlier.
redis | The Redis instance to configure. |
f | The error handler function, which is called with the pointer to the redis instance that had the errror, the redis channel index (e.g. REDIS_INTERACTIVE_CHANNEL) and the operation (e.g. 'send' or 'read') that failed. Note, that the call may be made with the affected Redis channel being in a locked state. As such the handler should not directly attempt to change the connection state of the Redis instance. Any calls that require exlusive access to the affected channel should instead be spawn off into a separate thread, which can obtain the necessary lock when it is released. |
int redisxSetUser | ( | Redis * | redis, |
const char * | username | ||
) |
Sets the user name to use for authenticating on the Redis server after connection. See the AUTH
Redis command for more explanation. Naturally, you need to call this prior to connecting your Redis instance to have the desired effect.
redis | Pointer to the Redis instance for which to set credentials |
username | the password to use for authenticating on the server, or NULL to clear a previously configured password. |
References redisxIsConnected(), X_ALREADY_OPEN, x_error(), X_NULL, X_SUCCESS, and xStringCopyOf().
void redisxSetVerbose | ( | boolean | value | ) |
Enable or disable verbose reporting of all Redis operations (and possibly some details of them). Reporting is done on the standard output (stdout). It may be useful when debugging programs that use the redisx interface. Verbose reporting is DISABLED by default.
value | TRUE to enable verbose reporting, or FALSE to disable. |
References xSetVerbose().