![]() |
RedisX v1.0
A simple, light-weight Redis database client
|
Data Structures | |
struct | Redis |
Structure that represents a Redis database instance, with one or more RedisClient connections. More... | |
struct | RedisClient |
Structure that represents a single Redis client connection instance. More... | |
struct | RedisCluster |
struct | RedisEntry |
A single key / value entry, or field, in the Redis database. More... | |
struct | RedisMap |
struct | RedisServer |
struct | RESP |
Structure that represents a Redis response (RESP format). More... | |
Macros | |
#define | REDIS_ERROR |
Redis returned an error. | |
#define | REDIS_INCOMPLETE_TRANSFER |
The transfer to/from Redis is incomplete. | |
#define | REDIS_INVALID_CHANNEL |
There is no such channel in the Redis instance. | |
#define | REDIS_MIGRATING |
The requested key is importing, and you may query with ASKED on the specified node. | |
#define | REDIS_MOVED |
The requested key has moved to another cluster shard. | |
#define | REDIS_NULL |
Redis returned NULL. | |
#define | REDIS_UNEXPECTED_ARRAY_SIZE |
Got a Redis response with different number of elements than expected. | |
#define | REDIS_UNEXPECTED_RESP |
Got a Redis response of a different type than expected. | |
#define | REDISX_CHANNELS |
The number of channels a Redis instance has. | |
#define | REDISX_CMDBUF_SIZE 8192 |
(bytes) Size of many internal arrays, and the max. send chunk size. At least ~16 bytes... | |
#define | REDISX_DEFAULT_SENTINEL_TIMEOUT_MILLIS 100 |
[ms] Default socket read/write timeout for Redis clients | |
#define | REDISX_DEFAULT_TIMEOUT_MILLIS 3000 |
[ms] Default socket read/write timeout for Redis clients | |
#define | REDISX_LISTENER_REL_PRIORITY (0.5) |
#define | REDISX_MAJOR_VERSION 1 |
API major version. | |
#define | REDISX_MINOR_VERSION 0 |
API minor version. | |
#define | REDISX_PATCHLEVEL 0 |
Integer sub version of the release. | |
#define | REDISX_RCVBUF_SIZE 8192 |
(bytes) Redis receive buffer size (at most that much is read from the socket in a single call). | |
#define | REDISX_RELEASE_STRING "-devel" |
Additional release information in version, e.g. "-1", or "-rc1". | |
#define | REDISX_SET_LISTENER_PRIORITY FALSE |
Whether to explicitly set listener thread priorities. | |
#define | REDISX_TCP_BUF_SIZE 0 |
(bytes) Default TCP buffer size (send/recv) for Redis clients. Values <= 0 will use system default. | |
#define | REDISX_TCP_PORT 6379 |
Default TCP/IP port on which Redis server listens to clients. | |
#define | REDISX_VERSION_STRING |
#define | RESP3_CONTINUED |
RESP3 dictionary of attributes (metadata) | |
Typedefs | |
typedef void(* | RedisErrorHandler) (Redis *redis, enum redisx_channel channel, const char *op) |
typedef void(* | RedisPipelineProcessor) (RESP *response) |
typedef void(* | RedisPushProcessor) (RedisClient *cl, RESP *message, void *ptr) |
typedef int(* | RedisSocketConfigurator) (int socket, enum redisx_channel channel) |
typedef void(* | RedisSubscriberCall) (const char *pattern, const char *channel, const char *msg, long length) |
Enumerations | |
enum | redisx_channel { REDISX_INTERACTIVE_CHANNEL , REDISX_PIPELINE_CHANNEL , REDISX_SUBSCRIPTION_CHANNEL } |
enum | redisx_protocol { REDISX_RESP2 , REDISX_RESP3 } |
enum | resp_type { RESP_ARRAY , RESP_INT , RESP_SIMPLE_STRING , RESP_ERROR , RESP_BULK_STRING , RESP3_NULL , RESP3_DOUBLE , RESP3_BOOLEAN , RESP3_BLOB_ERROR , RESP3_VERBATIM_STRING , RESP3_BIG_NUMBER , RESP3_MAP , RESP3_SET , RESP3_ATTRIBUTE , RESP3_PUSH } |
Functions | |
int | redisxAbortBlockAsync (RedisClient *cl) |
int | redisxAddConnectHook (Redis *redis, void(*setupCall)(Redis *)) |
int | redisxAddDisconnectHook (Redis *redis, void(*cleanupCall)(Redis *)) |
int | redisxAddSubscriber (Redis *redis, const char *channelStem, RedisSubscriberCall f) |
RESP * | redisxArrayRequest (Redis *redis, const char **args, const int *length, int n, int *status) |
int | redisxCheckDestroyRESP (RESP *resp, enum resp_type, int expectedSize) |
int | redisxCheckRESP (const RESP *resp, enum resp_type expectedType, int expectedSize) |
int | redisxCheckValid (const Redis *redis) |
int | redisxClearAttributesAsync (RedisClient *cl) |
void | redisxClearConnectHooks (Redis *redis) |
void | redisxClearDisconnectHooks (Redis *redis) |
int | redisxClearSubscribers (Redis *redis) |
RESP * | redisxClusterAskMigrating (Redis *redis, const char **args, const int *lengths, int n, int *status) |
int | redisxClusterAskMigratingAsync (RedisClient *cl, const char **args, const int *lengths, int n) |
int | redisxClusterConnect (RedisCluster *cluster) |
void | redisxClusterDestroy (RedisCluster *cluster) |
int | redisxClusterDisconnect (RedisCluster *cluster) |
Redis * | redisxClusterGetRedirection (RedisCluster *cluster, const RESP *redirect, boolean refresh) |
Redis * | redisxClusterGetShard (RedisCluster *cluster, const char *key) |
RedisCluster * | redisxClusterInit (Redis *node) |
boolean | redisxClusterIsMigrating (const RESP *reply) |
boolean | redisxClusterIsRedirected (const RESP *reply) |
boolean | redisxClusterMoved (const RESP *reply) |
int | redisxConnect (Redis *redis, boolean usePipeline) |
RESP * | redisxCopyOfRESP (const RESP *resp) |
void | redisxDebugTraffic (boolean value) |
void | redisxDestroy (Redis *redis) |
void | redisxDestroyEntries (RedisEntry *entries, int count) |
void | redisxDestroyKeys (char **keys, int count) |
void | redisxDestroyRESP (RESP *resp) |
void | redisxDisconnect (Redis *redis) |
int | redisxEndSubscription (Redis *redis) |
int | redisxError (const char *func, int errorCode) |
const char * | redisxErrorDescription (int code) |
RESP * | redisxExecBlockAsync (RedisClient *cl, int *pStatus) |
RESP * | redisxGetAttributes (Redis *redis) |
const RESP * | redisxGetAttributesAsync (const RedisClient *cl) |
int | redisxGetAvailable (RedisClient *cl) |
int | redisxGetAvailableAsync (RedisClient *cl) |
RedisClient * | redisxGetClient (Redis *redis, enum redisx_channel channel) |
RESP * | redisxGetHelloData (Redis *redis) |
XLookupTable * | redisxGetInfo (Redis *redis, const char *parameter) |
char ** | redisxGetKeys (Redis *redis, const char *table, int *n) |
RedisMap * | redisxGetKeywordEntry (const RESP *map, const char *key) |
RedisClient * | redisxGetLockedConnectedClient (Redis *redis, enum redisx_channel channel) |
RedisMap * | redisxGetMapEntry (const RESP *map, const RESP *key) |
enum redisx_protocol | redisxGetProtocol (Redis *redis) |
int | redisxGetScanCount (Redis *redis) |
char * | redisxGetStringValue (Redis *redis, const char *table, const char *key, int *len) |
RedisEntry * | redisxGetTable (Redis *redis, const char *table, int *n) |
int | redisxGetTime (Redis *redis, struct timespec *t) |
RESP * | redisxGetValue (Redis *redis, const char *table, const char *key, int *status) |
boolean | redisxHasComponents (const RESP *r) |
boolean | redisxHasPipeline (Redis *redis) |
int | redisxIgnoreReplyAsync (RedisClient *cl) |
Redis * | redisxInit (const char *server) |
Redis * | redisxInitSentinel (const char *serviceName, const RedisServer *serverList, int nServers) |
boolean | redisxIsArrayType (const RESP *r) |
boolean | redisxIsConnected (Redis *redis) |
boolean | redisxIsEqualRESP (const RESP *a, const RESP *b) |
int | redisxIsGlobPattern (const char *str) |
boolean | redisxIsMapType (const RESP *r) |
boolean | redisxIsScalarType (const RESP *r) |
boolean | redisxIsStringType (const RESP *r) |
boolean | redisxIsVerbose () |
int | redisxLoadScript (Redis *redis, const char *script, char **sha1) |
int | redisxLockClient (RedisClient *cl) |
int | redisxLockConnected (RedisClient *cl) |
int | redisxMultiSet (Redis *redis, const char *table, const RedisEntry *entries, int n, boolean confirm) |
int | redisxMultiSetAsync (RedisClient *cl, const char *table, const RedisEntry *entries, int n, boolean confirm) |
int | redisxNotify (Redis *redis, const char *channel, const char *message) |
int | redisxPing (Redis *redis, const char *message) |
void | redisxPrintDelimited (const RESP *resp, const char *delim, const char *groupPrefix) |
int | redisxPrintJSON (const char *name, const RESP *resp) |
int | redisxPrintRESP (const RESP *resp) |
int | redisxPublish (Redis *redis, const char *channel, const char *message, int length) |
int | redisxPublishAsync (Redis *redis, const char *channel, const char *data, int length) |
RESP * | redisxReadReplyAsync (RedisClient *cl, int *pStatus) |
int | redisxReconnect (Redis *redis, boolean usePipeline) |
int | redisxRemoveConnectHook (Redis *redis, void(*setupCall)(Redis *)) |
int | redisxRemoveDisconnectHook (Redis *redis, void(*cleanupCall)(Redis *)) |
int | redisxRemoveSubscribers (Redis *redis, RedisSubscriberCall f) |
RESP * | redisxRequest (Redis *redis, const char *command, const char *arg1, const char *arg2, const char *arg3, int *status) |
char * | redisxRESP2JSON (const char *name, const RESP *resp) |
XField * | redisxRESP2XField (const char *name, const RESP *resp) |
RESP * | redisxRunScript (Redis *redis, const char *sha1, const char **keys, const char **params, int *status) |
char ** | redisxScanKeys (Redis *redis, const char *pattern, int *n) |
RedisEntry * | redisxScanTable (Redis *redis, const char *table, const char *pattern, int *n) |
int | redisxSelectDB (Redis *redis, int idx) |
int | redisxSendArrayRequestAsync (RedisClient *cl, const char **args, const int *length, int n) |
int | redisxSendRequestAsync (RedisClient *cl, const char *command, const char *arg1, const char *arg2, const char *arg3) |
int | redisxSetDHCipherParams (Redis *redis, const char *dh_params_file) |
int | redisxSetHostname (Redis *redis, const char *host) |
int | redisxSetMutualTLS (Redis *redis, const char *cert_file, const char *key_file) |
int | redisxSetPassword (Redis *redis, const char *passwd) |
int | redisxSetPipelineConsumer (Redis *redis, RedisPipelineProcessor f) |
int | redisxSetPort (Redis *redis, int port) |
int | redisxSetProtocol (Redis *redis, enum redisx_protocol protocol) |
int | redisxSetPushProcessor (Redis *redis, RedisPushProcessor func, void *arg) |
int | redisxSetReplyTimeout (Redis *redis, int timeoutMillis) |
int | redisxSetScanCount (Redis *redis, int count) |
int | redisxSetSentinelTimeout (Redis *redis, int millis) |
int | redisxSetSocketConfigurator (Redis *redis, RedisSocketConfigurator func) |
int | redisxSetSocketErrorHandler (Redis *redis, RedisErrorHandler f) |
int | redisxSetSocketTimeout (Redis *redis, int millis) |
int | redisxSetTcpBuf (Redis *redis, int size) |
int | redisxSetTLS (Redis *redis, const char *ca_path, const char *ca_file) |
int | redisxSetTLSCiphers (Redis *redis, const char *cipher_list) |
int | redisxSetTLSCipherSuites (Redis *redis, const char *list) |
int | redisxSetTLSServerName (Redis *redis, const char *host) |
int | redisxSetTLSVerify (Redis *redis, boolean value) |
int | redisxSetUser (Redis *redis, const char *username) |
int | redisxSetValue (Redis *redis, const char *table, const char *key, const char *value, boolean confirm) |
int | redisxSetValueAsync (RedisClient *cl, const char *table, const char *key, const char *value, boolean confirm) |
void | redisxSetVerbose (boolean value) |
int | redisxSkipReplyAsync (RedisClient *cl) |
int | redisxSplitText (RESP *resp, char **text) |
int | redisxStartBlockAsync (RedisClient *cl) |
int | redisxSubscribe (Redis *redis, const char *channel) |
int | redisxUnlockClient (RedisClient *cl) |
int | redisxUnsubscribe (Redis *redis, const char *channel) |
int | redisxValidateSentinel (const char *serviceName, const RedisServer *serverList, int nServers) |
RedisX is a completely free Redis / Valkey client library, available on Github as:
#define REDISX_LISTENER_REL_PRIORITY (0.5) |
[0.0:1.0] Listener priority as fraction of available range You may want to set it quite high to ensure that the receive buffer is promptly cleared.
#define REDISX_VERSION_STRING |
The version string for this library
typedef void(* RedisErrorHandler) (Redis *redis, enum redisx_channel channel, const char *op) |
User-specified callback function for handling RedisX errors from socket-level read / write calls. It's mainly there for the application to perform any cleanup as necessary or to report the error. However, it can also interacti with the Redis instance in limited ways. The implementation should follow a set of basic rules:
Async
functions for the client (the client is in a locked state when the handler is called). errno
to gather information about the source of the error, and may even change or reset errno
, to change behavior (e.g. re-setting to EAGAIN
or EWOULBLOCK
will keep the client connected and the return status of the failed call will become X_TIMEDOUT; or setting it to any other value will disconnect the client and the failed call will return X_NO_SERVICE instead.). redis | Pointer to the RedisX instance |
channel | the channel over which the error occurred |
op | the name/ID of the operation where the error occurred. |
typedef void(* RedisPipelineProcessor) (RESP *response) |
A user-defined function for consuming responses from a Redis pipeline connection. The implementation should follow a set of simple rules:
response | A response received from the pipeline client. |
typedef void(* RedisPushProcessor) (RedisClient *cl, RESP *message, void *ptr) |
A user-defined function for consuming push messages from a Redis client. The implementation should follow a set of simple rules:
cl | The Redis client that sent the push. The client is locked for exlusive access when this function is called. |
message | The RESP3 message that was pushed by the client |
ptr | Additional data passed along. |
typedef int(* RedisSocketConfigurator) (int socket, enum redisx_channel channel) |
User callback function allowing additional customization of the client socket before connection.
socket | The socket descriptor. |
channel | REDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, REDISX_SUBSCRIPTION_CHANNEL |
typedef void(* RedisSubscriberCall) (const char *pattern, const char *channel, const char *msg, long length) |
A type of function that handles Redis PUB/SUB messages. These functions should follow a set of basic rules:
The call should return promptly and never block for significant periors. If it has blocking calls or if extended processing is required, the function should simply place a copy of the necessary information on a queue and process queued entries in a separate thread. (The call arguments will not persist beyond the scope of the call, so don't attempt to place them directly in a queue.)
The subscriber call should not attempt to modify or free() the strings it is called with. The same strings maybe used by other subscribers, and thus modifying their content would produce unpredictable results with those subscribers.
If the call needs to manipulate the supplied string arguments, it should operate on copies (e.g. obtained via xStringCopy()).
pattern | The subscription pattern for which this notification came for or NULL if not a pattern match. |
channel | The PUB/SUB channel on which the message arrived. |
msg | A pointer to the message content received. The message buffer itself is not expected to last beyond the call, so the function f() should make a copy if it for any persistent use. |
length | The number of bytes in the message. Since Redis messages can be binary a '\0' termination should no be assumed. Instead, the length of the message is specified explicitly. |
enum redisx_channel |
RedisX channel IDs. RedisX uses up to three separate connections to the server: (1) an interactive client, in which each query is a full round trip, (2) a pipeline clinet, in which queries are submitted in bulk, and responses arrive asynchronously, and (3) a substription client devoted to PUB/SUB requests and push messages. Not all clients are typically initialized at start. The interactive channel is always connected; the pipeline client can be selected when connecting to the server; and the subscription client is connected as needed to process PUB/SUB requests.
Enumerator | |
---|---|
REDISX_INTERACTIVE_CHANNEL | Redis channel number for interactive queries. |
REDISX_PIPELINE_CHANNEL | Redis channel number for pipelined transfers. |
REDISX_SUBSCRIPTION_CHANNEL | Redis channel number for PUB/SUB messages. |
enum redisx_protocol |
enum resp_type |
Enumeration of RESP component types. These are the first character IDs for the standard RESP interface implemented by Redis.
Enumerator | |
---|---|
RESP_ARRAY | RESP array type. |
RESP_INT | RESP integer type. |
RESP_SIMPLE_STRING | RESP simple string type. |
RESP_ERROR | RESP error message type. |
RESP_BULK_STRING | RESP bulk string type. |
RESP3_NULL | RESP3 null value. |
RESP3_DOUBLE | RESP3 floating-point value. |
RESP3_BOOLEAN | RESP3 boolean value. |
RESP3_BLOB_ERROR | RESP3 blob error. |
RESP3_VERBATIM_STRING | RESP3 verbatim string (with type) |
RESP3_BIG_NUMBER | RESP3 big integer / decimal. |
RESP3_MAP | RESP3 dictionary of key / value. |
RESP3_SET | RESP3 unordered set of elements. |
RESP3_ATTRIBUTE | RESP3 dictionary of attributes (metadata) |
RESP3_PUSH | RESP3 dictionary of attributes (metadata) |
int redisxAbortBlockAsync | ( | RedisClient * | cl | ) |
Abort an atomic transaction block. It sends DISCARD
. This function should be called with an exclusive lock on a connected client, and after starting an execution block with redisxStartBlockAsync().
cl | Pointer to a Redis client |
References redisxIgnoreReplyAsync(), TRUE, and X_SUCCESS.
Adds a connect call hook, provided it is not already part of the setup routine.
redis | Pointer to a Redis instance. |
setupCall | User-specified callback routine to be called after the Redis instance has been connected. It will be passed a pointer to the Redis instance, which triggered the call by having established connection. |
Adds a cleanup call, provided it is not already part of the cleanup routine, for when the specified Redis instance is disconnected.
redis | Pointer to a Redis instance. |
cleanupCall | User specified function to call when Redis is disconnected. It will be passed a pointer to the Redis instance, which triggered the call by having disconnected from the Redis server. |
int redisxAddSubscriber | ( | Redis * | redis, |
const char * | channelStem, | ||
RedisSubscriberCall | f | ||
) |
Add a targeted subscriber processing function to the list of functions that process Redis PUB/SUB responses. You will still have to subscribe the relevant PUB/SUB messages from redis separately, using redisxSubscribe() before any messages are delivered to this client. If the subscriber with the same callback function and channel stem is already added, this call simply return and will NOT create a duplicate enry. However, the same callback may be added multiple times with different channel stems (which pre-filter what messages each of the callbacks may get).
redis | Pointer to a Redis instance. |
channelStem | If NULL, the consumer will receive all Redis messages published to the given channel. Otherwise, the consumer will be notified only if the incoming channel begins with the specified stem. |
f | A function that consumes subscription messages. |
References X_SUCCESS, x_warn(), xStringCopyOf(), and xvprintf.
RESP * redisxArrayRequest | ( | Redis * | redis, |
const char ** | args, | ||
const 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...
This is the base interactive query, which is used by all sorts of other interactive transactions. It handles MOVED
and ASK
redirections for Redis clusters automatically and transparently, so long as the target node is a known member of the cluster from before or immediately after the migration message was received.
redis | Pointer to a Redis instance. |
args | An array of strings to send to Redis, corresponding to a single query. 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 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. If not NULL, it will be populated with one of: X_SUCCESS on success. X_NO_INIT if the Redis client library was not initialized via redisxInit(). X_NULL if the argument is NULL or n<1. X_TIMEDOUT if the reading of the response timed out. X_NO_SERVICE if not connected to Redis. X_FAILURE If there was a socket level error. |
References Redis::interactive, redisxArrayRequest(), redisxCheckValid(), redisxClearAttributesAsync(), redisxClusterAskMigrating(), redisxClusterGetRedirection(), redisxClusterIsMigrating(), redisxClusterIsRedirected(), redisxLockConnected(), redisxReadReplyAsync(), redisxSendArrayRequestAsync(), redisxUnlockClient(), x_error(), X_NULL, X_SUCCESS, and x_trace_null().
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().
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_MIGRATING, REDIS_MOVED, REDIS_NULL, REDIS_UNEXPECTED_RESP, redisxClusterIsMigrating(), redisxClusterMoved(), RESP3_BOOLEAN, RESP3_NULL, RESP_INT, RESP::type, RESP::value, x_error(), X_FAILURE, X_NULL, and X_SUCCESS.
int redisxCheckValid | ( | const Redis * | redis | ) |
Checks that a redis instance is valid.
redis | The Redis instance |
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.
void redisxClearConnectHooks | ( | Redis * | redis | ) |
void redisxClearDisconnectHooks | ( | Redis * | redis | ) |
int redisxClearSubscribers | ( | Redis * | redis | ) |
RESP * redisxClusterAskMigrating | ( | Redis * | redis, |
const char ** | args, | ||
const int * | lengths, | ||
int | n, | ||
int * | status | ||
) |
Makes a redirected transaction using the ASKING directive to the specific client. This should be in response to an -ASK redirection error to obtain a key that is in a slot that is currently migrating. The requested Redis command arguments are sent prefixed with the 'ASKING' directive, as per the Redis Cluster specification.
redis | Redirected Redis instance, e.g. from redisxClusterGetRedirect() |
args | Original command arguments that were redirected |
lengths | Original argument byte lengths redirected (or NULL to use strlen() automatically). |
n | Original number of arguments. |
status | Pointer to integer in which to return status: X_SUCCESS (0) if successful or else and error code <0. |
ASKING
query from the redirected server.References Redis::interactive, redisxCheckValid(), redisxClearAttributesAsync(), redisxClusterAskMigratingAsync(), redisxLockConnected(), redisxReadReplyAsync(), redisxUnlockClient(), X_SUCCESS, and x_trace_null().
int redisxClusterAskMigratingAsync | ( | RedisClient * | cl, |
const char ** | args, | ||
const int * | lengths, | ||
int | n | ||
) |
Makes a redirected request using the ASKING directive to the specific client. This should be in response to an -ASK redirection error to obtain a key that is in a slot that is currently migrating. The requested Redis command arguments are sent prefixed with the 'ASKING' directive, as per the Redis Cluster specification.
This function should be called with exclusive access to the client.
cl | Locked client on a redirected Redis instance, e.g. from redisxClusterGetRedirect() |
args | Original command arguments that were redirected |
lengths | Original argument byte lengths redirected (or NULL to use strlen() automatically). |
n | Original number of arguments. |
References redisxSendArrayRequestAsync(), x_error(), X_FAILURE, X_NO_SERVICE, X_NULL, X_SUCCESS, and xStringCopyOf().
int redisxClusterConnect | ( | RedisCluster * | cluster | ) |
Connects all shards of a Redis cluster. Shards normally get connected on demand. Thus, this function is only necessary if the user wants to ensure that all shards are connected before using the cluster.
Note, that if the cluster configuration changes while connected, the automatically reconfigured cluster will not automatically reconnect to the new shards during the reconfiguration. However, the new shards will still connect on demand when accessed via redisClusterGetShard().
cluster | Pointer to a Redis cluster configuration |
References RedisCluster::priv, redisxConnect(), x_error(), X_NO_INIT, X_NULL, X_SUCCESS, x_trace(), and xvprintf.
void redisxClusterDestroy | ( | RedisCluster * | cluster | ) |
Destroys a Redis cluster configuration, freeing up all resources used, but not before disconnecting from all shards that may be in a connected state.
cluster | Pointer to a Redis cluster configuration. |
References RedisCluster::priv, and redisxClusterDisconnect().
int redisxClusterDisconnect | ( | RedisCluster * | cluster | ) |
Disconnects from all shards of a Redis cluster. Note, that a cluster can still be used even after it is disconnected, since each call to redisxClusterGetShard() will automatically reconnect the requested shard as needed.
cluster | Pointer to a Redis cluster configuration |
References RedisCluster::priv, redisxDisconnect(), x_error(), X_NO_INIT, X_NULL, X_SUCCESS, and xvprintf.
Redis * redisxClusterGetRedirection | ( | RedisCluster * | cluster, |
const RESP * | redirect, | ||
boolean | refresh | ||
) |
Parses a -MOVED
or -ASK
redirection response from a Redis cluster node, to obtain the shard from which the same keyword that caused the error can now be accessed.
cluster | Redis cluster configuration |
redirect | the redirection response sent to a keyword query |
refresh | whether it should refresh the cluster configuration and try again if the redirection target is not found in the current cluster configuration. |
References redisxClusterIsMigrating(), redisxClusterMoved(), RESP::value, x_error(), X_PARSE_ERROR, and xStringCopyOf().
Redis * redisxClusterGetShard | ( | RedisCluster * | cluster, |
const char * | key | ||
) |
Returns the Redis server in a cluster which is to be used for queries relating to the specified Redis keyword. In Redis cluster configurations, the database is distributed in a way that each cluster node serves only a subset of the Redis keys. Thus, this function allows to identify the node that serves a given key. The function supports Redish hashtags according to the specification.
cluster | Pointer to a Redis cluster configuration |
key | The Redis keyword of interest. It may use hashtags (i.e., if the keyword contains a segment enclosed in {} brackets, then the hash will be calculated on the bracketed segment only. E.g. {user:1000}.name and {user:1000}.address will both return the same hash for user:1000 only. NULL and empty keys are allowed and will return the shard for slot 0. |
References RedisCluster::priv, rConnectAsync(), redisxIsConnected(), x_error(), X_NO_INIT, X_NULL, and X_SUCCESS.
RedisCluster * redisxClusterInit | ( | Redis * | node | ) |
Initializes a Redis cluster configuration using a known cluster node. The call will connect to the specified node (if not already connected), and will query the cluster configuration from it. On return the input node's connection state remains what it was prior to the call.
The caller may try multiple nodes from a list of known cluster nodes, until a valid (non-NULL) configuration is returned.
The returned cluster will inherit configuration from the node, including user authentication, socket configuration, connection / disconnection hooks, and asynchronous processing functions. Thus, you may configure the node as usual prior to this call, knowing that the nodes in the cluster will be configured the same way also.
node | A known cluster node (connected or not). It's configuration will be used for all cluster nodes discovered also. |
References RedisCluster::priv, redisxClusterDestroy(), redisxHasPipeline(), and x_trace_null().
Checks if the reply is an error indicating that the query is for a slot that is currently migrating to another shard (i.e., ASK
redirection). You may need to use an ASKING
directive, e.g. via redisxClusterAskMigrating() on the node specified in the message to access the key.
reply | The response obtained from the Redis shard / server. |
References FALSE, RESP::n, RESP_ERROR, RESP::type, and RESP::value.
Checks if the reply is an error indicating that the query should be redirected to another node (i.e., MOVED
or ASK
redirection).
reply | The response obtained from the Redis shard / server. |
References redisxClusterIsMigrating(), and redisxClusterMoved().
Checks if the reply is an error indicating that the cluster has been reconfigured and the request can no longer be fulfilled on the given shard (i.e., MOVED
redirection). You might want to obtain the new shard using redisxClusterGetShard() again, and re-submit the request to the new shard.
reply | The response obtained from the Redis shard / server. |
References FALSE, RESP::n, RESP_ERROR, RESP::type, and RESP::value.
Connects to a Redis server.
redis | Pointer to a Redis instance. |
usePipeline | TRUE (non-zero) if Redis should be connected with a pipeline client also, or FALSE (0) if only the interactive client is needed. |
References rConnectAsync(), and X_SUCCESS.
Creates an independent deep copy of the RESP, which shares no references with the original.
resp | The original RESP data structure (it may be NULL). |
References RedisMap::key, RESP::n, redisxCopyOfRESP(), RESP3_ATTRIBUTE, RESP3_BIG_NUMBER, RESP3_BLOB_ERROR, RESP3_DOUBLE, RESP3_MAP, RESP3_PUSH, RESP3_SET, RESP3_VERBATIM_STRING, RESP_ARRAY, RESP_BULK_STRING, RESP_ERROR, RESP_SIMPLE_STRING, RESP::type, RESP::value, and RedisMap::value.
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 redisxDestroy | ( | Redis * | redis | ) |
Destroys a Redis intance, disconnecting any clients that may be connected, and freeing all resources used by that Redis instance.
redis | Pointer to a Redis instance. |
References Redis::id, REDISX_CHANNELS, redisxClearSubscribers(), redisxDestroyRESP(), redisxDisconnect(), and redisxIsConnected().
void redisxDestroyEntries | ( | RedisEntry * | entries, |
int | count | ||
) |
Destroy a RedisEntry array with dynamically allocate keys/values, such as returned e.g. by redisxScanTable().
IMPORTANT:
You should not use this function to destroy RedisEntry[] arrays, which contain static string references (keys or values). If the table contains only static references you can simply call free() on the table. Otherwise, you will have to first free only the dynamically sized string fields within before calling free() on the table itself.
entries | Pointer to the entries array (or single entry data). It may be NULL, in which case this call will return immediately. |
count | The number of elements contained in the array |
References RedisEntry::key, and RedisEntry::value.
void redisxDestroyKeys | ( | char ** | keys, |
int | count | ||
) |
Destroy an array of keywords (i.e. an array of string pointers), such as returned e.g. by redisxScanKeys().
keys | An array of string pointers |
count | The number of strings contained in the array. It may be NULL., in which case this call will return immediately. |
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 RedisMap::key, RESP::n, redisxDestroyRESP(), RESP3_ATTRIBUTE, RESP3_MAP, RESP3_PUSH, RESP3_SET, RESP_ARRAY, RESP::type, RESP::value, and RedisMap::value.
void redisxDisconnect | ( | Redis * | redis | ) |
Disconnect all clients from the Redis server.
redis | Pointer to a Redis instance. |
References rDisconnectAsync(), redisxCheckValid(), and X_SUCCESS.
int redisxEndSubscription | ( | Redis * | redis | ) |
Unsubscribes from all channels, stops the subscription listener thread, and closes the subscription client connection.
redis | Pointer to a Redis instance. |
References X_SUCCESS.
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().
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. This function should be called with an exclusive lock on a connected client.
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().
Returns a copy of the attributes sent along with the last interative request. The user should destroy the returned RESP after using it by calling redisxDestroyRESP().
redis | Pointer to a Redis instance. |
References Redis::interactive, redisxCheckValid(), redisxCopyOfRESP(), redisxGetAttributesAsync(), redisxLockConnected(), redisxUnlockClient(), 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().
int redisxGetAvailable | ( | RedisClient * | cl | ) |
Returns the number of bytes of response available on the given Redis client connection. This is the synchronized version, which will obtain a exclusive lock on the client before determining the result.
cl | a locked and connected Redis client |
References redisxGetAvailable(), redisxLockConnected(), and redisxUnlockClient().
int redisxGetAvailableAsync | ( | RedisClient * | cl | ) |
Returns the number of bytes of response available on the given Redis client connection. This version assumes the caller has exclusive access to the client.
cl | a locked and connected Redis client |
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().
Returns a copy of the RESP map that the Redis server has sent us as a response to HELLO on the last client connection, or NULL if HELLO was not used or available.
redis | The redis instance |
References redisxCopyOfRESP(), and x_trace_null().
XLookupTable * redisxGetInfo | ( | Redis * | redis, |
const char * | parameter | ||
) |
Returns the result of an INFO query (with the optional parameter) as a lookup table of keywords and string values.
redis | Pointer to Redis instance |
parameter | Optional parameter to pass with INFO, or NULL. |
References rConsumeInfoReply(), redisxRequest(), X_SUCCESS, and x_trace_null().
char ** redisxGetKeys | ( | Redis * | redis, |
const char * | table, | ||
int * | n | ||
) |
Returns all the key names stored in a given hash table
[in] | redis | Pointer to a Redis instance. |
[in] | table | The hashtable from which to retrieve a value or NULL if to use the global table. |
[out] | n | Pointer to the integer in which the number of elements or an error (<0) is returned. It may return an error value from redisxRequest(), or: |
REDIS_NULL If got a null or empty response from Redis UNEXPECTED_RESP If the response from Redis was not the expected array type
References RESP::n, redisxCheckDestroyRESP(), redisxDestroyRESP(), redisxRequest(), RESP_ARRAY, RESP::value, x_error(), X_NULL, and x_trace_null().
Retrieves a entry, by its string keyword, from a map-type RESP data structure.
map | The map-type REST data structure containing a dictionary |
key | The string keyword to match |
References RedisMap::key, RESP::n, redisxIsMapType(), redisxIsStringType(), and RESP::value.
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().
Retrieves a keyed entry from a map-type RESP data structure.
map | The map-type REST data structure containing a dictionary |
key | The RESP key to match |
References RedisMap::key, RESP::n, redisxIsMapType(), RESP::type, and RESP::value.
enum redisx_protocol redisxGetProtocol | ( | Redis * | redis | ) |
Returns the actual protocol used with the Redis server. If HELLO was used during connection it will be the protocol that was confirmed in the response of HELLO (and which hopefully matches the protocol requested). Otherwise, RedisX will default to RESP2.
redis | The Redis server instance |
int redisxGetScanCount | ( | Redis * | redis | ) |
char * redisxGetStringValue | ( | Redis * | redis, |
const char * | table, | ||
const char * | key, | ||
int * | len | ||
) |
Retrieve a variable from Redis as a string (or byte array), through the interactive connection. 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...
The call effectively implements a Redis GET (if the table argument is NULL) or HGET call.
[in] | redis | Pointer to a Redis instance. |
[in] | table | Hashtable from which to retrieve a value or NULL if to use the global table. |
[in] | key | Field name (i.e. variable name). |
[out] | len | (optional) pointer in which to return the length (>=0) of the value or else an error code (<0) defined in xchange.h / redisx.h |
References RESP::n, redisxCheckRESP(), redisxDestroyRESP(), redisxGetValue(), RESP_BULK_STRING, RESP::value, X_SUCCESS, and x_trace_null().
RedisEntry * redisxGetTable | ( | Redis * | redis, |
const char * | table, | ||
int * | n | ||
) |
Returns all the key/value pairs stored in a given hash table
[in] | redis | Pointer to a Redis instance. |
[in] | table | Hashtable from which to retrieve a value or NULL if to use the global table. |
[out] | n | Pointer to the integer in which the number of elements or an error (<0) is returned. It may return an error value from redisxRequest(), or: |
REDIS_NULL If got a null or empty response from Redis UNEXPECTED_RESP If the response from Redis was not the expected array type
References RedisMap::key, RedisEntry::key, RESP::n, redisxCheckDestroyRESP(), redisxDestroyRESP(), redisxRequest(), RESP3_MAP, RESP_ARRAY, RESP::type, RESP::value, RedisMap::value, RedisEntry::value, x_error(), X_GROUP_INVALID, and x_trace_null().
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().
Retrieve a variable from Redis (as an undigested RESP), through the interactive connection. 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...
The call effectively implements a Redis GET (if the table argument is NULL) or HGET call.
[in] | redis | Pointer to a Redis instance. |
[in] | table | Hashtable from which to retrieve a value or NULL if to use the global table. |
[in] | key | Field name (i.e. variable name). |
[out] | status | (optional) pointer to the return error status, which is either X_SUCCESS on success or else the error code set by redisxArrayRequest(). It may be NULL if not required. |
References redisxRequest(), x_error(), X_GROUP_INVALID, X_NAME_INVALID, X_SUCCESS, and x_trace_null().
Checks if a RESP has subcomponents, such as arrays or maps (dictionaries).
r | Pointer to a RESP data structure |
References FALSE, RESP::n, redisxIsArrayType(), and redisxIsMapType().
Checks if a Redis instance has the pipeline connection enabled.
redis | Pointer to a Redis instance. |
References Redis::pipeline, redisxCheckValid(), redisxLockClient(), and redisxUnlockClient().
int redisxIgnoreReplyAsync | ( | RedisClient * | cl | ) |
Silently consumes a reply from the specified Redis channel. This function should be called with an exclusive lock on a connected client.
cl | Pointer to a Redis channel. |
References REDIS_NULL, redisxDestroyRESP(), redisxReadReplyAsync(), X_SUCCESS, and x_trace().
Redis * redisxInit | ( | const char * | server | ) |
Initializes the Redis client library, and sets the hostname or IP address for the Redis server.
server | Server host name or numeric IP address, e.g. "127.0.0.1". The string will be copied, not referenced, for the internal configuration, such that the string passed may be destroyed freely after the call. |
References FALSE, Redis::interactive, Redis::pipeline, REDISX_CHANNELS, REDISX_DEFAULT_TIMEOUT_MILLIS, REDISX_INTERACTIVE_CHANNEL, REDISX_PIPELINE_CHANNEL, REDISX_RESP2, REDISX_SUBSCRIPTION_CHANNEL, REDISX_TCP_BUF_SIZE, rSetServerAsync(), Redis::subscription, TRUE, x_error(), X_SUCCESS, and x_trace_null().
Redis * redisxInitSentinel | ( | const char * | serviceName, |
const RedisServer * | serverList, | ||
int | nServers | ||
) |
Initializes a Redis client with a Sentinel configuration of alternate servers, and the default sentinel node connection timeout.
serviceName | The service name as registered in the Sentinel server configuration. The supplied name will be copied, not referenced, so that the value passed may be freely destroyed after the call. |
serverList | An set of Sentinel servers to use to dynamically find the current master. The list itself and its contents are not referenced. Instead a deep copy will be made of it, so the list that was pased can be freely destroyed after the call. |
nServers | The number of servers in the list |
References REDISX_DEFAULT_SENTINEL_TIMEOUT_MILLIS, redisxInit(), redisxValidateSentinel(), x_error(), X_SUCCESS, x_trace_null(), and xStringCopyOf().
Checks if a RESP holds an array of RESP pointers, and whose value
can be cast to (RESP **)
to use.
r | Pointer to a RESP data structure |
RESP *
pointers, or else FALSE (0).References FALSE, RESP3_PUSH, RESP3_SET, RESP_ARRAY, TRUE, and RESP::type.
Checks if a Redis instance is connected.
redis | Pointer to a Redis instance. |
References FALSE, Redis::interactive, redisxCheckValid(), and X_SUCCESS.
Checks if two RESP are equal, that is they hold the same type of data, have the same 'n' value, and the values match byte-for-byte, or are both NULL.
References FALSE, RESP::n, TRUE, RESP::type, and RESP::value.
int redisxIsGlobPattern | ( | const char * | str | ) |
Checks if a RESP holds a dictionary, and whose value
can be cast to (RedisMap *)
to use.
r | Pointer to a RESP data structure |
References FALSE, RESP3_ATTRIBUTE, RESP3_MAP, TRUE, and RESP::type.
Checks if a RESP holds a scalar type value, such as an integer, a boolean or a double-precision value, or a null value.
r | Pointer to a RESP data structure |
References FALSE, RESP3_BOOLEAN, RESP3_DOUBLE, RESP3_NULL, RESP_INT, TRUE, and RESP::type.
Checks if a RESP holds a string type value, whose value
can be cast to (char *)
to use.
r | Pointer to a RESP data structure |
References FALSE, RESP3_BIG_NUMBER, RESP3_BLOB_ERROR, RESP3_VERBATIM_STRING, RESP_BULK_STRING, RESP_ERROR, RESP_SIMPLE_STRING, TRUE, and RESP::type.
boolean redisxIsVerbose | ( | ) |
Checks id verbose reporting is enabled.
References xIsVerbose().
int redisxLoadScript | ( | Redis * | redis, |
const char * | script, | ||
char ** | sha1 | ||
) |
Loads a LUA script into Redis, returning its SHA1 hash to use as it's call ID.
[in] | redis | Pointer to a Redis instance. |
[in] | script | String containing the full LUA script. |
[out] | sha1 | Buffer into which SHA1 key returned by Redis to use as call ID. (It must be at least 41 bytes, and will be string terminated). By default it will return an empty string. |
References redisxCheckDestroyRESP(), redisxDestroyRESP(), redisxRequest(), RESP_BULK_STRING, RESP::value, x_error(), X_NULL, and X_SUCCESS.
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_SERVICE, and X_SUCCESS.
int redisxMultiSet | ( | Redis * | redis, |
const char * | table, | ||
const RedisEntry * | entries, | ||
int | n, | ||
boolean | confirm | ||
) |
Sets multiple key/value pairs in a given hash table.
redis | Pointer to a Redis instance. |
table | Hashtable from which to retrieve a value. |
entries | Pointer to an array of key/value pairs. |
n | Number of entries. |
confirm | Whether we should get a confirmation from the server (requires a round-trip). |
References Redis::interactive, REDIS_UNEXPECTED_RESP, redisxArrayRequest(), redisxCheckValid(), redisxDestroyRESP(), redisxMultiSetAsync(), RESP::value, x_error(), X_FAILURE, X_SUCCESS, and x_trace().
int redisxMultiSetAsync | ( | RedisClient * | cl, |
const char * | table, | ||
const RedisEntry * | entries, | ||
int | n, | ||
boolean | confirm | ||
) |
Sets multiple key/value pairs in a given hash table. This function should be called with exclusive access to the client.
cl | A Redis client to which we have exclusive access. |
table | Hashtable from which to retrieve a value. |
entries | Pointer to an array of key/value pairs. |
n | Number of entries. |
confirm | Whether we should get a confirmation from the server (requires a round-trip). |
References redisxSendArrayRequestAsync(), redisxSkipReplyAsync(), X_FAILURE, X_SUCCESS, and x_trace().
int redisxNotify | ( | Redis * | redis, |
const char * | channel, | ||
const char * | message | ||
) |
Sends a regular string terminated Redis PUB/SUB message on the specified channel. Same as redisxPublish() with the length argument set to the length of the string message. Redis must be connected before attempting to send messages.
redis | Pointer to a Redis instance. |
channel | Redis PUB/SUB channel on which to notify |
message | Message to send. |
References redisxPublish(), and X_SUCCESS.
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, redisxCheckDestroyRESP(), redisxDestroyRESP(), redisxRequest(), RESP_BULK_STRING, RESP_SIMPLE_STRING, RESP::value, x_error(), and X_SUCCESS.
void redisxPrintDelimited | ( | const RESP * | resp, |
const char * | delim, | ||
const char * | groupPrefix | ||
) |
Prints a RESP in raw form using delimiters only.
resp | Pointer to a RESP (it may be NULL) |
delim | Delimiter between elements |
groupPrefix | Prefix in front of arrays and maps |
References RESP::n, redisxPrintDelimited(), RESP3_ATTRIBUTE, RESP3_BIG_NUMBER, RESP3_BLOB_ERROR, 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, RESP::type, and RESP::value.
int redisxPrintJSON | ( | const char * | name, |
const RESP * | resp | ||
) |
Prints a RESP as a JSON fragmen to the standard output with the specified name
References redisxRESP2JSON(), and X_SUCCESS.
int redisxPrintRESP | ( | const RESP * | resp | ) |
int redisxPublish | ( | Redis * | redis, |
const char * | channel, | ||
const char * | data, | ||
int | length | ||
) |
Sends a generic Redis PUB/SUB message on the specified channel. Redis must be connected before attempting to send messages. It will send the message over the pipeline client if it is avaiable, or else over the interactive client.
redis | Pointer to a Redis instance. |
channel | Redis PUB/SUB channel on which to notify |
data | Data to send. |
length | Bytes of data to send, or 0 to determine automatically with strlen(). |
References Redis::id, Redis::interactive, redisxCheckValid(), redisxLockConnected(), redisxPublishAsync(), redisxUnlockClient(), X_SUCCESS, and xvprintf.
int redisxPublishAsync | ( | Redis * | redis, |
const char * | channel, | ||
const char * | data, | ||
int | length | ||
) |
Sends a Redis notification asynchronously using the Redis "PUBLISH" command. The caller should have an exclusive lock on the interactive Redis channel before calling this.
redis | Pointer to a Redis instance. |
channel | Redis PUB/SUB channel on which to notify |
data | Message body data. |
length | Bytes of message data to send, ot 0 to determine automatically with strlen(). |
References Redis::interactive, redisxCheckValid(), redisxSendArrayRequestAsync(), redisxSkipReplyAsync(), x_error(), X_NULL, and X_SUCCESS.
RESP * redisxReadReplyAsync | ( | RedisClient * | cl, |
int * | pStatus | ||
) |
Reads a response from Redis and returns it. It should be used with an exclusive lock on a connected client, to collect responses for requests sent previously. It is up to the caller to keep track of what request the response is for. The responses arrive in the same order (and same nummber) as the requests that were sent out.
To follow cluster MOVED or ASK redirections, the caller should check the reponse for redirections (e.g. via redisxIsRedirected()) and then act accordingly to re-submit the corresponding request, as is or with an ASKING directive to follow the redirection.
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(), redisxClusterMoved(), 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().
Disconnects from Redis, and then connects again...
redis | Pointer to a Redis instance. |
usePipeline | Whether to reconnect in pipelined mode. |
or else an error (<0) as would be returned by redisxConnect().
References X_SUCCESS.
int redisxRemoveSubscribers | ( | Redis * | redis, |
RedisSubscriberCall | f | ||
) |
Removes all instances of a subscribe consumer function from the current list of consumers. This calls only deactivates the specified processing callback function(s), without stopping the delivery of associated messages. To stop Redis sending messages that are no longer being processed, you should also call redisxUnsubscribe() as appropriate.
redis | Pointer to a Redis instance. |
f | The consumer function to remove from the list of active subscribers. |
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(), redisxDestroyRESP(), X_SUCCESS, and x_trace_null().
char * redisxRESP2JSON | ( | const char * | name, |
const RESP * | resp | ||
) |
Converts a RESP to the xchange representation as an appropriate XField.
name | The name to assign to the field |
resp | The RESP data to convert |
References redisxRESP2XField(), and xjsonFieldToString().
Converts a RESP to the xchange representation as an appropriate XField.
name | The name to assign to the field |
resp | The RESP data to convert |
References RESP::n, RESP3_ATTRIBUTE, RESP3_BIG_NUMBER, RESP3_BLOB_ERROR, RESP3_BOOLEAN, 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, RESP::type, RESP::value, X_UNKNOWN, xCreateBooleanField(), xCreateDoubleField(), xCreateIntField(), xCreateScalarField(), and xCreateStringField().
RESP * redisxRunScript | ( | Redis * | redis, |
const char * | sha1, | ||
const char ** | keys, | ||
const char ** | params, | ||
int * | status | ||
) |
Runs a LUA script that has been loaded into the Redis database, returning the response received, or NULL if there was an error.
redis | The Redis instance |
sha1 | The SHA1 sum of the script that was previously loaded into the Redis DB. |
keys | A NULL-terminated array of Redis keywords, or NULL if the script does not take any keyword argument. |
params | A NULL-terminated array of additional parameters to pass onto the script, or NULL if the script does not take any parameters. |
status | Pointer to int in which to return status, or NULL if not required. |
References redisxArrayRequest(), redisxCheckValid(), x_error(), X_NULL, X_SUCCESS, and x_trace_null().
char ** redisxScanKeys | ( | Redis * | redis, |
const char * | pattern, | ||
int * | n | ||
) |
Returns an alphabetical list of the Redis keys using the Redis SCAN command. Because it uses the scan command, it is guaranteed to not hog the database for excessive periods, and hence it is preferable to redisxGetKeys(table=NULL).
Some data may be returned even if there was an error, and the caller is responsible for cleaning up the returned srotage elements.
The caller may adjust the amount of work performed in each scan call via the redisxSetScanCount() function, prior to calling this.
[in] | redis | Pointer to a Redis instance. |
[in] | pattern | keyword pattern to match, or NULL for all keys. |
[out] | n | Pointer to the integer in which the number of elements (>=0), or else an error code (<0), such as: |
X_NULL If one of the arguments is NULL REDIS_NULL If got a null or empty response from Redis UNEXPECTED_RESP If the response from Redis was not the expected array type lt
References RESP::n, redisxArrayRequest(), redisxCheckRESP(), redisxDestroyKeys(), redisxDestroyRESP(), redisxGetScanCount(), RESP_ARRAY, RESP_BULK_STRING, SCAN_INITIAL_STORE_CAPACITY, RESP::value, x_error(), X_SUCCESS, x_trace_null(), xStringCopyOf(), and xvprintf.
RedisEntry * redisxScanTable | ( | Redis * | redis, |
const char * | table, | ||
const char * | pattern, | ||
int * | n | ||
) |
Returns an alphabetical list of the Redis hash table data using the Redis HSCAN command. Because it uses the scan command, it is guaranteed to not hog the database for excessive periods, and hence it is preferable to redisxGetTable().
Some data may be returned even if there was an error, and the caller is responsible for cleaning up the returned srotage elements.
The caller may adjust the amount of work performed in each scan call via the redisxSetScanCount() function, prior to calling this.
[in] | redis | Pointer to a Redis instance. |
[in] | table | Name of Redis hash table to scan data from |
[in] | pattern | keyword pattern to match, or NULL for all keys. |
[out] | n | Pointer to the integer in which the number of elements (>=0) or else an error code (<0), such as: |
X_NULL if one of the arguments is NULL X_GROUP_INVALID if the table name is empty REDIS_NULL if got a null or empty response from Redis UNEXPECTED_RESP if the response from Redis was not the expected array type
References RedisEntry::key, RedisEntry::length, RESP::n, redisxArrayRequest(), redisxCheckRESP(), redisxDestroyEntries(), redisxDestroyRESP(), redisxGetScanCount(), RESP_ARRAY, RESP_BULK_STRING, SCAN_INITIAL_STORE_CAPACITY, RESP::value, RedisEntry::value, x_error(), X_GROUP_INVALID, X_NULL, X_SUCCESS, x_trace_null(), xStringCopyOf(), and xvprintf.
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_INCOMPLETE, X_SUCCESS, and x_trace().
int redisxSendArrayRequestAsync | ( | RedisClient * | cl, |
const char ** | args, | ||
const int * | lengths, | ||
int | n | ||
) |
Send a Redis request with an arbitrary number of arguments. This function should be called with an exclusive lock on a connected client.
Unlike its interactive counterpart, redisxArrayRequest(), this method does not follow cluster MOVED or ASK redirections automatically. It cannot, since it returns without waiting for a response. To implement redirections, the caller must keep track of the asynchronous requests sent, and check for redirections when processing responses via redisxReadReplyAsync(). If the response is a redirection, then the caller can decide if and how to re-submit the request to follow the redirection.
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_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.
Unlike its interactive counterpart, redisxRequest(), this method does not follow cluster MOVED or ASK redirections automatically. It cannot, since it returns without waiting for a response. To implement redirections, the caller must keep track of the asynchronous requests sent, and check for redirections when processing responses via redisxReadReplyAsync(). If the response is a redirection, then the caller can decide if and how to re-submit the request to follow the redirection.
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 redisxSetDHCipherParams | ( | Redis * | redis, |
const char * | dh_params_file | ||
) |
Sets parameters for DH-based cyphers when using a TLS encrypted connection to Redis.
redis | A Redis instance. |
dh_params_file | Path to the DH-based cypher parameters file (in PEM format; we don't support the old DER format), or NULL for no params. |
References x_error(), X_FAILURE, X_SUCCESS, and xStringCopyOf().
int redisxSetHostname | ( | Redis * | redis, |
const char * | host | ||
) |
Changes the host name for the Redis server, prior to calling redisxConnect()
.
redis | Pointer to a Redis instance. |
host | New host name or IP address to use. |
References redisxIsConnected(), rSetServerAsync(), X_ALREADY_OPEN, x_error(), X_FAILURE, X_NULL, and X_SUCCESS.
int redisxSetMutualTLS | ( | Redis * | redis, |
const char * | cert_file, | ||
const char * | key_file | ||
) |
Set a TLS certificate and private key for mutual TLS. You will still need to call redisxSetTLS() also to create a complete TLS configuration. Redis normally uses mutual TLS, which requires both the client and the server to authenticate themselves. For this you need the server's TLS certificate and private key also. It is possible to configure Redis servers to verify one way only with a CA certificate, in which case you don't need to call this to configure the client.
To disable mutual TLS, set both file name arguments to NULL.
redis | A Redis instance. |
cert_file | Path to the server's certificate file. |
key_file | Path to the server'sprivate key file. |
References x_error(), X_FAILURE, X_NULL, X_SUCCESS, and xStringCopyOf().
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_SUCCESS, and xStringCopyOf().
int redisxSetPipelineConsumer | ( | Redis * | redis, |
RedisPipelineProcessor | f | ||
) |
Sets the function processing valid pipeline responses. The implementation should follow a simple set of rules:
redis | Pointer to a Redis instance. |
f | The function that processes a single argument of type RESP pointer. |
References X_SUCCESS.
int redisxSetPort | ( | Redis * | redis, |
int | port | ||
) |
Sets a non-standard TCP port number to use for the Redis server, prior to calling redisxConnect()
.
redis | Pointer to a Redis instance. |
port | The TCP port number to use. |
References redisxIsConnected(), X_ALREADY_OPEN, x_error(), X_FAILURE, and X_SUCCESS.
int redisxSetProtocol | ( | Redis * | redis, |
enum redisx_protocol | protocol | ||
) |
Sets the RESP prorocol version to use for future client connections. The protocol is set with the HELLO command, which was introduced in Redis 6.0.0 only. For older Redis server instances, the protocol will default to RESP2. Calling this function will enable using HELLO to handshake with the server.
redis | The Redis server instance |
protocol | REDISX_RESP2 or REDISX_RESP3. |
int redisxSetPushProcessor | ( | Redis * | redis, |
RedisPushProcessor | func, | ||
void * | arg | ||
) |
Sets a user-defined function to process push messages for a specific Redis instance. The function's implementation must follow a simple set of rules:
redis | Redis instance |
func | Function to use for processing push messages from the given Redis instance, or NULL to ignore push messages. |
arg | (optional) User-defined pointer argument to pass along to the processing function. |
References X_SUCCESS.
int redisxSetReplyTimeout | ( | Redis * | redis, |
int | timeoutMillis | ||
) |
Set a timeout for getting replies on the interactive client. This does not affect the pipeline and subscription clients, which do not have a timeout (appropriately for asynchronous processing)
redis | Pointer to a Redis instance. |
timeoutMillis | [ms] timeout for interactive responses, or <0 for indefinite. |
References Redis::interactive, and X_SUCCESS.
int redisxSetScanCount | ( | Redis * | redis, |
int | count | ||
) |
Sets the COUNT parameter to use with Redis SCAN type commands. COUNT specifies how much work Redis should do in a single scan iteration. 0 (or negative) values can be used to scan with defaults (without the COUNT option), which is usually equivalent to COUNT=10. When scanning large datasets, it may take many scan calls to go through all the data. When networking has limited bandwidth, or large latencies it may be desirable to do more work per call on the server side to reduce traffic. However, the cost of larger COUNT values is that it may increase server latencies for other queries.
redis | Pointer to a Redis instance. |
count | The new COUNT to use for SCAN-type commands or <0 to use default. |
References X_SUCCESS.
int redisxSetSentinelTimeout | ( | Redis * | redis, |
int | millis | ||
) |
Changes the connection timeout for Sentinel server instances in the discovery phase. This is different from the timeout that is used for the master server, once it is discovered.
redis | The Redis instance, which was initialized for Sentinel via redisxInitSentinel(). |
millis | [ms] The new connection timeout or <=0 to use the default value. |
References REDISX_DEFAULT_SENTINEL_TIMEOUT_MILLIS, x_error(), X_NO_INIT, and X_SUCCESS.
int redisxSetSocketConfigurator | ( | Redis * | redis, |
RedisSocketConfigurator | func | ||
) |
Sets a user-defined callback for additioan custom configuring of client sockets
redis | The Redis server instance |
func | The user-defined callback function, which performs the additional socket configuration |
int redisxSetSocketErrorHandler | ( | 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. |
References X_SUCCESS.
int redisxSetSocketTimeout | ( | Redis * | redis, |
int | millis | ||
) |
Sets a socket timeout for future client connections on a Redis instance. Effectively this is a timeout for send() only. The timeout for interatvice replies is controlled separately via redisxSetReplyTimoeut().
If not set (or set to zero or a negative value), then the timeout will not be configured for sockets, and the system default timeout values will apply.
redis | The Redis instance |
millis | [ms] The desired socket read/write timeout, or <0 for socket default. |
References REDISX_DEFAULT_TIMEOUT_MILLIS, and X_SUCCESS.
int redisxSetTcpBuf | ( | Redis * | redis, |
int | size | ||
) |
Set the size of the TCP/IP buffers (send and receive) for future client connections.
redis | Pointer to a Redis instance. |
size | (bytes) requested buffer size, or <= 0 to use default value |
References X_SUCCESS.
int redisxSetTLS | ( | Redis * | redis, |
const char * | ca_path, | ||
const char * | ca_file | ||
) |
Configures a TLS-encrypted connection to Redis with the specified CA certificate file. Normally you will want to set up mutual TLS with redisxSetMutualTLS() also, unless the server is not requiring mutual authentication. Additionally, you might also want to set parameters for DH-based cyphers if needed using redisxSetDHCypherParams().
redis | A Redis instance. |
ca_path | Directory containing CA certificates. It may be NULL to use the default locations. |
ca_file | CA certificate file relative to specified directory. It may be NULL to use default certificate. |
References TRUE, x_error(), X_FAILURE, X_SUCCESS, and xStringCopyOf().
int redisxSetTLSCiphers | ( | Redis * | redis, |
const char * | cipher_list | ||
) |
Sets the TLS ciphers to try (TLSv1.2 and earlier).
redis | A Redis instance. |
cipher_list | a colon (:) separated list of ciphers, or NULL for default ciphers. |
References x_error(), X_FAILURE, X_SUCCESS, and xStringCopyOf().
int redisxSetTLSCipherSuites | ( | Redis * | redis, |
const char * | list | ||
) |
Sets the TLS ciphers suites to try (TLSv1.3 and later).
redis | A Redis instance. |
list | a colon (:) separated list of cipher suites, or NULL for default cipher suites. |
References x_error(), X_FAILURE, X_SUCCESS, and xStringCopyOf().
int redisxSetTLSServerName | ( | Redis * | redis, |
const char * | host | ||
) |
Sets the Server name for TLS Server Name Indication (SNI), an optional extra later of security.
redis | A Redis instance. |
host | server name to use for SNI. |
References x_error(), X_FAILURE, X_SUCCESS, and xStringCopyOf().
Sets whether to verify the the certificate. Certificates are verified by default.
redis | A Redis instance. |
value | TRUE (non-zero) to verify certificates, or else FALSE (0) |
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_SUCCESS, and xStringCopyOf().
int redisxSetValue | ( | Redis * | redis, |
const char * | table, | ||
const char * | key, | ||
const char * | value, | ||
boolean | confirm | ||
) |
Sets a global or hashtable value on Redis.
redis | Pointer to a Redis instance. |
table | Hash table identifier or NULL if setting a global value. |
key | Redis field name (i.e. variable name). |
value | A proper 0-terminated string value to store. |
confirm | Whether we should get a confirmation from the server (requires a round-trip). |
References FALSE, Redis::interactive, redisxCheckRESP(), redisxDestroyRESP(), redisxLockConnected(), redisxRequest(), redisxSetValueAsync(), redisxUnlockClient(), RESP_INT, x_error(), X_NULL, and X_SUCCESS.
int redisxSetValueAsync | ( | RedisClient * | cl, |
const char * | table, | ||
const char * | key, | ||
const char * | value, | ||
boolean | confirm | ||
) |
Sends a request for setting a table value, using the Redis "SET" or "HSET" command.
cl | Pointer to a Redis channel. |
table | Hashtable from which to retrieve a value or NULL if to use the global table. |
key | Field name (i.e. variable name). |
value | The string value to set (assumes normal string termination).' |
confirm | Whether confirmation is requested from Redis to acknowledge. |
References redisxSendRequestAsync(), redisxSkipReplyAsync(), x_error(), X_NAME_INVALID, X_NULL, X_SUCCESS, and xvprintf.
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().
int redisxSkipReplyAsync | ( | RedisClient * | cl | ) |
Instructs Redis to skip sending a reply for the next command. This function should be called with an exclusive lock on a connected client, and just before redisxSendRequest() or redisxSendArrayRequestAsync().
Sends CLIENT REPLY SKIP
cl | Pointer to the Redis client to use. |
int redisxSplitText | ( | RESP * | resp, |
char ** | text | ||
) |
Splits the string value of a RESP into two components, by terminating the first component with a null byte and optionally returning the remaining part and length in the output parameters. Only RESP_ERROR RESP_BLOB_ERROR and RESP_VERBATIM_STRING types can be split this way. All others will return REDIS_UNEXPECTED_RESP.
resp | The input RESP. | |
[out] | text | (optional) pointer in which to return the start of the remnant text component. |
References RESP::n, REDIS_UNEXPECTED_RESP, RESP3_BLOB_ERROR, RESP3_VERBATIM_STRING, RESP_ERROR, RESP::type, RESP::value, x_error(), X_NULL, and X_PARSE_ERROR.
int redisxStartBlockAsync | ( | RedisClient * | cl | ) |
Starts an atomic Redis transaction block, by sending MULTI
on the specified client connection. This function should be called with an exclusive lock on a connected client.
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 redisxSubscribe | ( | Redis * | redis, |
const char * | pattern | ||
) |
Subscribe to a specific Redis channel. The call will also start the subscription listener thread to processing incoming subscription messages. Subscribing only enabled the delivery of the messages to this client without any actions on these messages. In order to process the messages for your subscriptons, you will also want to call redisxAddSubscriber() to add your custom processor function(s).
redis | Pointer to a Redis instance. |
pattern | The Channel pattern to subscribe to, e.g. 'acc1', or 'acc*'... |
References redisxIsGlobPattern(), redisxLockConnected(), redisxSendRequestAsync(), redisxUnlockClient(), Redis::subscription, x_error(), X_NULL, and X_SUCCESS.
int redisxUnlockClient | ( | RedisClient * | cl | ) |
Relinquish exclusive write access to the specified Redis channel
cl | Pointer to the Redis client instance |
int redisxUnsubscribe | ( | Redis * | redis, |
const char * | pattern | ||
) |
Unsubscribe from one or all Redis PUB/SUB channel(s). If there are no active subscriptions when Redis confirms the unsubscrive command, the subscription listener thread will also conclude automatically. Unsubscribing will stop delivery of mesasages for the affected channels but any associated processing callbacks remain registered, until redisxRemovesubscribers() is called to deactive them as appropriate.
redis | Pointer to a Redis instance. |
pattern | The channel pattern, or NULL to unsubscribe all channels and patterns. |
References redisxCheckValid(), redisxIsGlobPattern(), redisxLockConnected(), redisxSendRequestAsync(), redisxUnlockClient(), Redis::subscription, and X_SUCCESS.
int redisxValidateSentinel | ( | const char * | serviceName, |
const RedisServer * | serverList, | ||
int | nServers | ||
) |
Validates a Sentinel configuration.
serviceName | The service name as registered in the Sentinel server configuration. |
serverList | An set of Sentinel servers to use to dynamically find the current master. |
nServers | The number of servers in the list |
References x_error(), X_GROUP_INVALID, X_NAME_INVALID, X_NULL, X_SIZE_INVALID, and X_SUCCESS.