RedisX v0.9
A simple, light-weight Redis database client
|
Functions | |
int | redisxAddSubscriber (Redis *redis, const char *channelStem, RedisSubscriberCall f) |
int | redisxClearSubscribers (Redis *redis) |
int | redisxEndSubscription (Redis *redis) |
int | redisxNotify (Redis *redis, const char *channel, const char *message) |
int | redisxPublish (Redis *redis, const char *channel, const char *data, int length) |
int | redisxPublishAsync (Redis *redis, const char *channel, const char *data, int length) |
int | redisxRemoveSubscribers (Redis *redis, RedisSubscriberCall f) |
int | redisxSubscribe (Redis *redis, const char *pattern) |
int | redisxUnsubscribe (Redis *redis, const char *pattern) |
PUB/SUB functions for the RedisX library.
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.
int redisxClearSubscribers | ( | Redis * | redis | ) |
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 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 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.
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. |
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 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.