summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-10-30 10:20:28 +0100
committerantirez <antirez@gmail.com>2019-10-30 10:20:28 +0100
commitfb6110ac2062a548aa79c9bb5f11e3fa10e71ba2 (patch)
treec2030848e674aac37637fc6bf583d4f3f82cf850
parent3649568ff22dbb6ea3e26c722d115ba5635547ae (diff)
downloadredis-fb6110ac2062a548aa79c9bb5f11e3fa10e71ba2.tar.gz
Modules: block on keys: export APIs.
-rw-r--r--src/module.c11
-rw-r--r--src/redismodule.h4
2 files changed, 15 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c
index bdafc1590..113375e75 100644
--- a/src/module.c
+++ b/src/module.c
@@ -4128,6 +4128,15 @@ RedisModuleBlockedClient *RM_BlockClientOnKeys(RedisModuleCtx *ctx, RedisModuleC
return moduleBlockClient(ctx,reply_callback,timeout_callback,free_privdata,timeout_ms, keys,numkeys,is_key_ready,privdata);
}
+/* This function is used in order to potentially unblock a client blocked
+ * on keys with RedisModule_BlockClientOnKeys(). When this function is called,
+ * all the clients blocked for this key will get their is_key_ready callback,
+ * and if the callback returns non-zero the client will be unblocked and the
+ * reply callback will be called in order to reply to the client. */
+void RM_SignalKeyAsReady(RedisModuleCtx *ctx, RedisModuleString *key) {
+ signalKeyAsReady(ctx->client->db, key);
+}
+
/* Unblock a client blocked by `RedisModule_BlockedClient`. This will trigger
* the reply callbacks to be called in order to reply to the client.
* The 'privdata' argument will be accessible by the reply callback, so
@@ -6634,4 +6643,6 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(InfoAddFieldULongLong);
REGISTER_API(GetClientInfoById);
REGISTER_API(SubscribeToServerEvent);
+ REGISTER_API(BlockClientOnKeys);
+ REGISTER_API(SignalKeyAsReady);
}
diff --git a/src/redismodule.h b/src/redismodule.h
index 4b63a227c..5b4c31b19 100644
--- a/src/redismodule.h
+++ b/src/redismodule.h
@@ -492,6 +492,8 @@ int REDISMODULE_API_FUNC(RedisModule_InfoAddFieldDouble)(RedisModuleInfoCtx *ctx
int REDISMODULE_API_FUNC(RedisModule_InfoAddFieldLongLong)(RedisModuleInfoCtx *ctx, char *field, long long value);
int REDISMODULE_API_FUNC(RedisModule_InfoAddFieldULongLong)(RedisModuleInfoCtx *ctx, char *field, unsigned long long value);
int REDISMODULE_API_FUNC(RedisModule_SubscribeToServerEvent)(RedisModuleCtx *ctx, RedisModuleEvent event, RedisModuleEventCallback callback);
+RedisModuleBlockedClient *REDISMODULE_API_FUNC(RedisModule_BlockClientOnKeys)(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(RedisModuleCtx*,void*), long long timeout_ms, RedisModuleString **keys, int numkeys, int (*is_key_ready)(RedisModuleCtx*, RedisModuleString *keyname, void *privdata), void *privdata);
+void REDISMODULE_API_FUNC(RedisModule_SignalKeyAsReady)(RedisModuleCtx *ctx, RedisModuleString *key);
/* Experimental APIs */
#ifdef REDISMODULE_EXPERIMENTAL_API
@@ -688,6 +690,8 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(InfoAddFieldULongLong);
REDISMODULE_GET_API(GetClientInfoById);
REDISMODULE_GET_API(SubscribeToServerEvent);
+ REDISMODULE_GET_API(BlockClientOnKeys);
+ REDISMODULE_GET_API(SignalKeyAsReady);
#ifdef REDISMODULE_EXPERIMENTAL_API
REDISMODULE_GET_API(GetThreadSafeContext);