diff --git a/API.md b/API.md index 9831ecc..de3c1f9 100644 --- a/API.md +++ b/API.md @@ -3,8 +3,8 @@ Redis Modules: an introduction to the API The modules documentation is composed of the following files: -* `INTRO.md` (this file). An overview about Redis Modules system and API. It's a good idea to start your reading here. -* `API.md` is generated from module.c top comments of RedisMoule functions. It is a good reference in order to understand how each function works. +* `API.md` (this file). An overview about Redis Modules system and API. It's a good idea to start your reading here. +* `FUNCTIONS.md` is generated from module.c top comments of RedisMoule functions. It is a good reference in order to understand how each function works. * `TYPES.md` covers the implementation of native data types into modules. * `BLOCK.md` shows how to write blocking commands that will not reply immediately, but will block the client, without blocking the Redis server, and will provide a reply whenever will be possible. @@ -573,7 +573,7 @@ To create a new key, open it for writing and then write to it using one of the key writing functions. Example: RedisModuleKey *key; - key = RedisModule_OpenKey(ctx,argv[1],REDISMODULE_READ); + key = RedisModule_OpenKey(ctx,argv[1],REDISMODULE_WRITE); if (RedisModule_KeyType(key) == REDISMODULE_KEYTYPE_EMPTY) { RedisModule_StringSet(key,argv[2]); } diff --git a/BLOCK.md b/BLOCK.md index d4f3c93..b32adc7 100644 --- a/BLOCK.md +++ b/BLOCK.md @@ -66,7 +66,7 @@ To better understand how the API works, we can imagine writing a command that blocks a client for one second, and then send as reply "Hello!". Note: arity checks and other non important things are not implemented -int his command, in order to take the example simple. +in this command, in order to take the example simple. int Example_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) @@ -87,7 +87,7 @@ int his command, in order to take the example simple. RedisModule_UnblockClient(bc,NULL); } -The above command blocks the client ASAP, spawining a thread that will +The above command blocks the client ASAP, spawning a thread that will wait a second and will unblock the client. Let's check the reply and timeout callbacks, which are in our case very similar, since they just reply the client with a different reply type. @@ -126,19 +126,20 @@ can be passed to the reply function so that we return it to the command caller. In order to make this working, we modify the functions as follow: void *threadmain(void *arg) { - RedisModuleBlockedClient *bc = arg; + RedisModuleBlockedClient *bc = (RedisModuleBlockedClient *)arg; sleep(1); /* Wait one second and unblock. */ long *mynumber = RedisModule_Alloc(sizeof(long)); *mynumber = rand(); RedisModule_UnblockClient(bc,mynumber); + return NULL; } As you can see, now the unblocking call is passing some private data, that is the `mynumber` pointer, to the reply callback. In order to obtain this private data, the reply callback will use the following -fnuction: +function: void *RedisModule_GetBlockedClientPrivateData(RedisModuleCtx *ctx); @@ -162,7 +163,7 @@ long value must be freed. Our callback will look like the following: } NOTE: It is important to stress that the private data is best freed in the -`free_privdata` callback becaues the reply function may not be called +`free_privdata` callback because the reply function may not be called if the client disconnects or timeout. Also note that the private data is also accessible from the timeout