diff options
Diffstat (limited to 'examples/example-redictmoduleapi.c')
-rw-r--r-- | examples/example-redictmoduleapi.c | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/examples/example-redictmoduleapi.c b/examples/example-redictmoduleapi.c index f929ffc..84dea0d 100644 --- a/examples/example-redictmoduleapi.c +++ b/examples/example-redictmoduleapi.c @@ -13,20 +13,20 @@ #include <async.h> #include <adapters/redictmoduleapi.h> -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; //unused - redisReply *reply = r; + redictReply *reply = r; if (reply == NULL) { /* The DEBUG SLEEP command will almost always fail, because we have set a 1 second timeout */ printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; } /* Disconnect after receiving the reply of DEBUG SLEEP (which will not)*/ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void getCallback(redisAsyncContext *c, void *r, void *privdata) { - redisReply *reply = r; +void getCallback(redictAsyncContext *c, void *r, void *privdata) { + redictReply *reply = r; if (reply == NULL) { if (c->errstr) { printf("errstr: %s\n", c->errstr); @@ -36,19 +36,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* start another request that demonstrate timeout */ - redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); + redictAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); } -void connectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void connectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { - if (status != REDIS_OK) { +void disconnectCallback(const redictAsyncContext *c, int status) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -56,28 +56,26 @@ void disconnectCallback(const redisAsyncContext *c, int status) { } /* - * This example requires Redis 7.0 or above. - * - * 1- Compile this file as a shared library. Directory of "redismodule.h" must + * 1- Compile this file as a shared library. Directory of "redictmodule.h" must * be in the include path. - * gcc -fPIC -shared -I../../redis/src/ -I.. example-redismoduleapi.c -o example-redismoduleapi.so + * gcc -fPIC -shared -I../../redict/src/ -I.. example-redictmoduleapi.c -o example-redictmoduleapi.so * * 2- Load module: - * redis-server --loadmodule ./example-redismoduleapi.so value + * redict-server --loadmodule ./example-redictmoduleapi.so value */ -int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { +int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) { - int ret = RedisModule_Init(ctx, "example-redictmoduleapi", 1, REDISMODULE_APIVER_1); - if (ret != REDISMODULE_OK) { + int ret = RedictModule_Init(ctx, "example-redictmoduleapi", 1, REDICTMODULE_APIVER_1); + if (ret != REDICTMODULE_OK) { printf("error module init \n"); - return REDISMODULE_ERR; + return REDICTMODULE_ERR; } - if (redisModuleCompatibilityCheck() != REDIS_OK) { - return REDISMODULE_ERR; + if (redictModuleCompatibilityCheck() != REDICT_OK) { + return REDICTMODULE_ERR; } - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); @@ -85,13 +83,13 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) } size_t len; - const char *val = RedisModule_StringPtrLen(argv[argc-1], &len); + const char *val = RedictModule_StringPtrLen(argv[argc-1], &len); - RedisModuleCtx *module_ctx = RedisModule_GetDetachedThreadSafeContext(ctx); - redisModuleAttach(c, module_ctx); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); + RedictModuleCtx *module_ctx = RedictModule_GetDetachedThreadSafeContext(ctx); + redictModuleAttach(c, module_ctx); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); /* In this demo, we first `set key`, then `get key` to demonstrate the basic usage of the adapter. @@ -100,7 +98,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) timeout error, which is shown in the `debugCallback`. */ - redisAsyncCommand(c, NULL, NULL, "SET key %b", val, len); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", val, len); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); return 0; } |