From bb3475e8eb379ee18f3d8f37caa8040b852a6213 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sat, 23 Mar 2024 01:21:46 +0100 Subject: all: rename redis -> redict symbols and comments Signed-off-by: Anna (navi) Figueiredo Gomes --- examples/example-ae.c | 26 ++++++++--------- examples/example-glib.c | 28 +++++++++--------- examples/example-ivykis.c | 26 ++++++++--------- examples/example-libev.c | 26 ++++++++--------- examples/example-libevent-ssl.c | 40 +++++++++++++------------- examples/example-libevent.c | 30 ++++++++++---------- examples/example-libhv.c | 36 +++++++++++------------ examples/example-libsdevent.c | 36 +++++++++++------------ examples/example-libuv.c | 34 +++++++++++----------- examples/example-macosx.c | 26 ++++++++--------- examples/example-poll.c | 28 +++++++++--------- examples/example-push.c | 56 ++++++++++++++++++------------------ examples/example-qt.cpp | 12 ++++---- examples/example-qt.h | 12 ++++---- examples/example-redictmoduleapi.c | 58 ++++++++++++++++++-------------------- examples/example-ssl.c | 52 +++++++++++++++++----------------- examples/example.c | 44 ++++++++++++++--------------- 17 files changed, 284 insertions(+), 286 deletions(-) (limited to 'examples') diff --git a/examples/example-ae.c b/examples/example-ae.c index 983ca9c..170d7b2 100644 --- a/examples/example-ae.c +++ b/examples/example-ae.c @@ -16,17 +16,17 @@ /* Put event loop in the global scope, so it can be explicitly stopped */ static aeEventLoop *loop; -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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); aeStop(loop); return; @@ -35,8 +35,8 @@ void connectCallback(const redisAsyncContext *c, int status) { 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); aeStop(loop); return; @@ -49,7 +49,7 @@ void disconnectCallback(const redisAsyncContext *c, int status) { int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); - 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); @@ -57,11 +57,11 @@ int main (int argc, char **argv) { } loop = aeCreateEventLoop(64); - redisAeAttach(loop, c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAeAttach(loop, c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); aeMain(loop); return 0; } diff --git a/examples/example-glib.c b/examples/example-glib.c index 46aa550..97cf279 100644 --- a/examples/example-glib.c +++ b/examples/example-glib.c @@ -13,10 +13,10 @@ static GMainLoop *mainloop; static void -connect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, +connect_cb (const redictAsyncContext *ac G_GNUC_UNUSED, int status) { - if (status != REDIS_OK) { + if (status != REDICT_OK) { g_printerr("Failed to connect: %s\n", ac->errstr); g_main_loop_quit(mainloop); } else { @@ -25,10 +25,10 @@ connect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, } static void -disconnect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, +disconnect_cb (const redictAsyncContext *ac G_GNUC_UNUSED, int status) { - if (status != REDIS_OK) { + if (status != REDICT_OK) { g_error("Failed to disconnect: %s", ac->errstr); } else { g_printerr("Disconnected...\n"); @@ -37,41 +37,41 @@ disconnect_cb (const redisAsyncContext *ac G_GNUC_UNUSED, } static void -command_cb(redisAsyncContext *ac, +command_cb(redictAsyncContext *ac, gpointer r, gpointer user_data G_GNUC_UNUSED) { - redisReply *reply = r; + redictReply *reply = r; if (reply) { g_print("REPLY: %s\n", reply->str); } - redisAsyncDisconnect(ac); + redictAsyncDisconnect(ac); } gint main (gint argc G_GNUC_UNUSED, gchar *argv[] G_GNUC_UNUSED) { - redisAsyncContext *ac; + redictAsyncContext *ac; GMainContext *context = NULL; GSource *source; - ac = redisAsyncConnect("127.0.0.1", 6379); + ac = redictAsyncConnect("127.0.0.1", 6379); if (ac->err) { g_printerr("%s\n", ac->errstr); exit(EXIT_FAILURE); } - source = redis_source_new(ac); + source = redict_source_new(ac); mainloop = g_main_loop_new(context, FALSE); g_source_attach(source, context); - redisAsyncSetConnectCallback(ac, connect_cb); - redisAsyncSetDisconnectCallback(ac, disconnect_cb); - redisAsyncCommand(ac, command_cb, NULL, "SET key 1234"); - redisAsyncCommand(ac, command_cb, NULL, "GET key"); + redictAsyncSetConnectCallback(ac, connect_cb); + redictAsyncSetDisconnectCallback(ac, disconnect_cb); + redictAsyncCommand(ac, command_cb, NULL, "SET key 1234"); + redictAsyncCommand(ac, command_cb, NULL, "GET key"); g_main_loop_run(mainloop); diff --git a/examples/example-ivykis.c b/examples/example-ivykis.c index 989fa12..8aa2570 100644 --- a/examples/example-ivykis.c +++ b/examples/example-ivykis.c @@ -13,25 +13,25 @@ #include #include -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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; } @@ -45,18 +45,18 @@ int main (int argc, char **argv) { iv_init(); - 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); return 1; } - redisIvykisAttach(c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictIvykisAttach(c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); iv_main(); diff --git a/examples/example-libev.c b/examples/example-libev.c index ade7ed1..b180674 100644 --- a/examples/example-libev.c +++ b/examples/example-libev.c @@ -13,25 +13,25 @@ #include #include -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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; } @@ -43,18 +43,18 @@ int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); #endif - 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); return 1; } - redisLibevAttach(EV_DEFAULT_ c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictLibevAttach(EV_DEFAULT_ c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); ev_loop(EV_DEFAULT_ 0); return 0; } diff --git a/examples/example-libevent-ssl.c b/examples/example-libevent-ssl.c index a142b22..b15e7e2 100644 --- a/examples/example-libevent-ssl.c +++ b/examples/example-libevent-ssl.c @@ -10,29 +10,29 @@ #include #include -#include +#include #include #include -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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; } @@ -61,36 +61,36 @@ int main (int argc, char **argv) { const char *certKey = argv[5]; const char *caCert = argc > 5 ? argv[6] : NULL; - redisSSLContext *ssl; - redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE; + redictSSLContext *ssl; + redictSSLContextError ssl_error = REDICT_SSL_CTX_NONE; - redisInitOpenSSL(); + redictInitOpenSSL(); - ssl = redisCreateSSLContext(caCert, NULL, + ssl = redictCreateSSLContext(caCert, NULL, cert, certKey, NULL, &ssl_error); if (!ssl) { printf("Error: %s\n", redictSSLContextGetError(ssl_error)); return 1; } - redisAsyncContext *c = redisAsyncConnect(hostname, port); + redictAsyncContext *c = redictAsyncConnect(hostname, port); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - if (redisInitiateSSLWithContext(&c->c, ssl) != REDIS_OK) { + if (redictInitiateSSLWithContext(&c->c, ssl) != REDICT_OK) { printf("SSL Error!\n"); exit(1); } - redisLibeventAttach(c,base); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictLibeventAttach(c,base); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); event_base_dispatch(base); - redisFreeSSLContext(ssl); + redictFreeSSLContext(ssl); return 0; } diff --git a/examples/example-libevent.c b/examples/example-libevent.c index 747f343..efc21d6 100644 --- a/examples/example-libevent.c +++ b/examples/example-libevent.c @@ -13,8 +13,8 @@ #include #include -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); @@ -24,19 +24,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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; } @@ -49,25 +49,25 @@ int main (int argc, char **argv) { #endif struct event_base *base = event_base_new(); - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379); struct timeval tv = {0}; tv.tv_sec = 1; options.connect_timeout = &tv; - redisAsyncContext *c = redisAsyncConnectWithOptions(&options); + redictAsyncContext *c = redictAsyncConnectWithOptions(&options); if (c->err) { /* Let *c leak for now... */ printf("Error: %s\n", c->errstr); return 1; } - redisLibeventAttach(c,base); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictLibeventAttach(c,base); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); event_base_dispatch(base); return 0; } diff --git a/examples/example-libhv.c b/examples/example-libhv.c index 4878039..ca053c0 100644 --- a/examples/example-libhv.c +++ b/examples/example-libhv.c @@ -13,37 +13,37 @@ #include #include -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; - redisReply *reply = r; + redictReply *reply = r; if (reply == NULL) { printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; } - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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; } @@ -55,7 +55,7 @@ int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); #endif - 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); @@ -63,13 +63,13 @@ int main (int argc, char **argv) { } hloop_t* loop = hloop_new(HLOOP_FLAG_QUIT_WHEN_NO_ACTIVE_EVENTS); - redisLibhvAttach(c, loop); - redisAsyncSetTimeout(c, (struct timeval){.tv_sec = 0, .tv_usec = 500000}); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); - redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %d", 1); + redictLibhvAttach(c, loop); + redictAsyncSetTimeout(c, (struct timeval){.tv_sec = 0, .tv_usec = 500000}); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %d", 1); hloop_run(loop); hloop_free(&loop); return 0; diff --git a/examples/example-libsdevent.c b/examples/example-libsdevent.c index 8599b76..6e544fc 100644 --- a/examples/example-libsdevent.c +++ b/examples/example-libsdevent.c @@ -13,20 +13,20 @@ #include #include -void debugCallback(redisAsyncContext *c, void *r, void *privdata) { +void debugCallback(redictAsyncContext *c, void *r, void *privdata) { (void)privdata; - 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) { printf("`GET key` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; @@ -34,19 +34,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("`GET key` result: 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("connect 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("disconnect because of error: %s\n", c->errstr); return; } @@ -59,17 +59,17 @@ int main (int argc, char **argv) { struct sd_event *event; sd_event_default(&event); - redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + redictAsyncContext *c = redictAsyncConnect("127.0.0.1", 6379); if (c->err) { printf("Error: %s\n", c->errstr); - redisAsyncFree(c); + redictAsyncFree(c); return 1; } - redisLibsdeventAttach(c,event); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); + redictLibsdeventAttach(c,event); + 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 libsdevent adapter. @@ -78,8 +78,8 @@ int main (int argc, char **argv) { timeout error, which is shown in the `debugCallback`. */ - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); /* sd-event does not quit when there are no handlers registered. Manually exit after 1.5 seconds */ sd_event_source *s; diff --git a/examples/example-libuv.c b/examples/example-libuv.c index 7d0e624..c8992bc 100644 --- a/examples/example-libuv.c +++ b/examples/example-libuv.c @@ -13,20 +13,20 @@ #include #include -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) { printf("`GET key` error: %s\n", c->errstr ? c->errstr : "unknown error"); return; @@ -34,19 +34,19 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { printf("`GET key` result: 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("connect 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("disconnect because of error: %s\n", c->errstr); return; } @@ -60,17 +60,17 @@ int main (int argc, char **argv) { uv_loop_t* loop = uv_default_loop(); - 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); return 1; } - redisLibuvAttach(c,loop); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0}); + redictLibuvAttach(c,loop); + 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 libuv adapter. @@ -79,8 +79,8 @@ int main (int argc, char **argv) { timeout error, which is shown in the `debugCallback`. */ - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); uv_run(loop, UV_RUN_DEFAULT); return 0; diff --git a/examples/example-macosx.c b/examples/example-macosx.c index 659d3b5..265afe4 100644 --- a/examples/example-macosx.c +++ b/examples/example-macosx.c @@ -12,25 +12,25 @@ #include #include -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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; } @@ -47,20 +47,20 @@ int main (int argc, char **argv) { return 1; } - 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); return 1; } - redisMacOSAttach(c, loop); + redictMacOSAttach(c, loop); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); CFRunLoopRun(); diff --git a/examples/example-poll.c b/examples/example-poll.c index eb53659..75d4fd5 100644 --- a/examples/example-poll.c +++ b/examples/example-poll.c @@ -16,17 +16,17 @@ /* Put in the global scope, so that loop can be explicitly stopped */ static int exit_loop = 0; -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) return; printf("argv[%s]: %s\n", (char*)privdata, reply->str); /* Disconnect after receiving the reply to GET */ - redisAsyncDisconnect(c); + redictAsyncDisconnect(c); } -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); exit_loop = 1; return; @@ -35,9 +35,9 @@ void connectCallback(const redisAsyncContext *c, int status) { printf("Connected...\n"); } -void disconnectCallback(const redisAsyncContext *c, int status) { +void disconnectCallback(const redictAsyncContext *c, int status) { exit_loop = 1; - if (status != REDIS_OK) { + if (status != REDICT_OK) { printf("Error: %s\n", c->errstr); return; } @@ -48,21 +48,21 @@ void disconnectCallback(const redisAsyncContext *c, int status) { int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); - 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); return 1; } - redisPollAttach(c); - redisAsyncSetConnectCallback(c,connectCallback); - redisAsyncSetDisconnectCallback(c,disconnectCallback); - redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); - redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); + redictPollAttach(c); + redictAsyncSetConnectCallback(c,connectCallback); + redictAsyncSetDisconnectCallback(c,disconnectCallback); + redictAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redictAsyncCommand(c, getCallback, (char*)"end-1", "GET key"); while (!exit_loop) { - redisPollTick(c, 0.1); + redictPollTick(c, 0.1); } return 0; } diff --git a/examples/example-push.c b/examples/example-push.c index ce28c38..1d6d0b5 100644 --- a/examples/example-push.c +++ b/examples/example-push.c @@ -19,12 +19,12 @@ exit(-1); \ } while (0) -static void assertReplyAndFree(redisContext *context, redisReply *reply, int type) { +static void assertReplyAndFree(redictContext *context, redictReply *reply, int type) { if (reply == NULL) panicAbort("NULL reply from server (error: %s)", context->errstr); if (reply->type != type) { - if (reply->type == REDIS_REPLY_ERROR) + if (reply->type == REDICT_REPLY_ERROR) fprintf(stderr, "Redict Error: %s\n", reply->str); panicAbort("Expected reply type %d but got type %d", type, reply->type); @@ -34,34 +34,34 @@ static void assertReplyAndFree(redisContext *context, redisReply *reply, int typ } /* Switch to the RESP3 protocol and enable client tracking */ -static void enableClientTracking(redisContext *c) { - redisReply *reply = redisCommand(c, "HELLO 3"); +static void enableClientTracking(redictContext *c) { + redictReply *reply = redictCommand(c, "HELLO 3"); if (reply == NULL || c->err) { panicAbort("NULL reply or server error (error: %s)", c->errstr); } - if (reply->type != REDIS_REPLY_MAP) { + if (reply->type != REDICT_REPLY_MAP) { fprintf(stderr, "Error: Can't send HELLO 3 command. Are you sure you're "); fprintf(stderr, "connected to redict-server >= 6.0.0?\nRedict error: %s\n", - reply->type == REDIS_REPLY_ERROR ? reply->str : "(unknown)"); + reply->type == REDICT_REPLY_ERROR ? reply->str : "(unknown)"); exit(-1); } freeReplyObject(reply); /* Enable client tracking */ - reply = redisCommand(c, "CLIENT TRACKING ON"); - assertReplyAndFree(c, reply, REDIS_REPLY_STATUS); + reply = redictCommand(c, "CLIENT TRACKING ON"); + assertReplyAndFree(c, reply, REDICT_REPLY_STATUS); } void pushReplyHandler(void *privdata, void *r) { - redisReply *reply = r; + redictReply *reply = r; int *invalidations = privdata; /* Sanity check on the invalidation reply */ - if (reply->type != REDIS_REPLY_PUSH || reply->elements != 2 || - reply->element[1]->type != REDIS_REPLY_ARRAY || - reply->element[1]->element[0]->type != REDIS_REPLY_STRING) + if (reply->type != REDICT_REPLY_PUSH || reply->elements != 2 || + reply->element[1]->type != REDICT_REPLY_ARRAY || + reply->element[1]->element[0]->type != REDICT_REPLY_STRING) { panicAbort("%s", "Can't parse PUSH message!"); } @@ -76,7 +76,7 @@ void pushReplyHandler(void *privdata, void *r) { } /* We aren't actually freeing anything here, but it is included to show that we can - * have hiredis call our data destructor when freeing the context */ + * have hiredict call our data destructor when freeing the context */ void privdata_dtor(void *privdata) { unsigned int *icount = privdata; printf("privdata_dtor(): In context privdata dtor (invalidations: %u)\n", *icount); @@ -84,55 +84,55 @@ void privdata_dtor(void *privdata) { int main(int argc, char **argv) { unsigned int j, invalidations = 0; - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1"; int port = (argc > 2) ? atoi(argv[2]) : 6379; - redisOptions o = {0}; - REDIS_OPTIONS_SET_TCP(&o, hostname, port); + redictOptions o = {0}; + REDICT_OPTIONS_SET_TCP(&o, hostname, port); /* Set our context privdata to the address of our invalidation counter. Each - * time our PUSH handler is called, hiredis will pass the privdata for context. + * time our PUSH handler is called, hiredict will pass the privdata for context. * * This could also be done after we create the context like so: * * c->privdata = &invalidations; * c->free_privdata = privdata_dtor; */ - REDIS_OPTIONS_SET_PRIVDATA(&o, &invalidations, privdata_dtor); + REDICT_OPTIONS_SET_PRIVDATA(&o, &invalidations, privdata_dtor); /* Set our custom PUSH message handler */ o.push_cb = pushReplyHandler; - c = redisConnectWithOptions(&o); + c = redictConnectWithOptions(&o); if (c == NULL || c->err) panicAbort("Connection error: %s", c ? c->errstr : "OOM"); /* Enable RESP3 and turn on client tracking */ enableClientTracking(c); - /* Set some keys and then read them back. Once we do that, Redis will deliver + /* Set some keys and then read them back. Once we do that, Redict will deliver * invalidation push messages whenever the key is modified */ for (j = 0; j < KEY_COUNT; j++) { - reply = redisCommand(c, "SET key:%d initial:%d", j, j); - assertReplyAndFree(c, reply, REDIS_REPLY_STATUS); + reply = redictCommand(c, "SET key:%d initial:%d", j, j); + assertReplyAndFree(c, reply, REDICT_REPLY_STATUS); - reply = redisCommand(c, "GET key:%d", j); - assertReplyAndFree(c, reply, REDIS_REPLY_STRING); + reply = redictCommand(c, "GET key:%d", j); + assertReplyAndFree(c, reply, REDICT_REPLY_STRING); } /* Trigger invalidation messages by updating keys we just read */ for (j = 0; j < KEY_COUNT; j++) { printf(" main(): SET key:%d update:%d\n", j, j); - reply = redisCommand(c, "SET key:%d update:%d", j, j); - assertReplyAndFree(c, reply, REDIS_REPLY_STATUS); + reply = redictCommand(c, "SET key:%d update:%d", j, j); + assertReplyAndFree(c, reply, REDICT_REPLY_STATUS); printf(" main(): SET REPLY OK\n"); } printf("\nTotal detected invalidations: %d, expected: %d\n", invalidations, KEY_COUNT); /* PING server */ - redisFree(c); + redictFree(c); } diff --git a/examples/example-qt.cpp b/examples/example-qt.cpp index 9ed61e8..8f6926c 100644 --- a/examples/example-qt.cpp +++ b/examples/example-qt.cpp @@ -12,9 +12,9 @@ using namespace std; #include "example-qt.h" -void getCallback(redisAsyncContext *, void * r, void * privdata) { +void getCallback(redictAsyncContext *, void * r, void * privdata) { - redisReply * reply = static_cast(r); + redictReply * reply = static_cast(r); ExampleQt * ex = static_cast(privdata); if (reply == nullptr || ex == nullptr) return; @@ -25,18 +25,18 @@ void getCallback(redisAsyncContext *, void * r, void * privdata) { void ExampleQt::run() { - m_ctx = redisAsyncConnect("localhost", 6379); + m_ctx = redictAsyncConnect("localhost", 6379); if (m_ctx->err) { cerr << "Error: " << m_ctx->errstr << endl; - redisAsyncFree(m_ctx); + redictAsyncFree(m_ctx); emit finished(); } m_adapter.setContext(m_ctx); - redisAsyncCommand(m_ctx, NULL, NULL, "SET key %s", m_value); - redisAsyncCommand(m_ctx, getCallback, this, "GET key"); + redictAsyncCommand(m_ctx, NULL, NULL, "SET key %s", m_value); + redictAsyncCommand(m_ctx, getCallback, this, "GET key"); } int main (int argc, char **argv) { diff --git a/examples/example-qt.h b/examples/example-qt.h index 31195ae..f48df17 100644 --- a/examples/example-qt.h +++ b/examples/example-qt.h @@ -4,8 +4,8 @@ // SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: LGPL-3.0-or-later -#ifndef __HIREDIS_EXAMPLE_QT_H -#define __HIREDIS_EXAMPLE_QT_H +#ifndef __HIREDICT_EXAMPLE_QT_H +#define __HIREDICT_EXAMPLE_QT_H #include @@ -28,11 +28,11 @@ class ExampleQt : public QObject { private: const char * m_value; - redisAsyncContext * m_ctx; - RedisQtAdapter m_adapter; + redictAsyncContext * m_ctx; + RedictQtAdapter m_adapter; friend - void getCallback(redisAsyncContext *, void *, void *); + void getCallback(redictAsyncContext *, void *, void *); }; -#endif /* !__HIREDIS_EXAMPLE_QT_H */ +#endif /* !__HIREDICT_EXAMPLE_QT_H */ 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 #include -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; } diff --git a/examples/example-ssl.c b/examples/example-ssl.c index ac3dfb8..c9b8818 100644 --- a/examples/example-ssl.c +++ b/examples/example-ssl.c @@ -9,7 +9,7 @@ #include #include -#include +#include #ifdef _MSC_VER #include /* For struct timeval */ @@ -17,10 +17,10 @@ int main(int argc, char **argv) { unsigned int j; - redisSSLContext *ssl; - redisSSLContextError ssl_error = REDIS_SSL_CTX_NONE; - redisContext *c; - redisReply *reply; + redictSSLContext *ssl; + redictSSLContextError ssl_error = REDICT_SSL_CTX_NONE; + redictContext *c; + redictReply *reply; if (argc < 4) { printf("Usage: %s [ca]\n", argv[0]); exit(1); @@ -31,78 +31,78 @@ int main(int argc, char **argv) { const char *key = argv[4]; const char *ca = argc > 4 ? argv[5] : NULL; - redisInitOpenSSL(); - ssl = redisCreateSSLContext(ca, NULL, cert, key, NULL, &ssl_error); - if (!ssl || ssl_error != REDIS_SSL_CTX_NONE) { + redictInitOpenSSL(); + ssl = redictCreateSSLContext(ca, NULL, cert, key, NULL, &ssl_error); + if (!ssl || ssl_error != REDICT_SSL_CTX_NONE) { printf("SSL Context error: %s\n", redictSSLContextGetError(ssl_error)); exit(1); } struct timeval tv = { 1, 500000 }; // 1.5 seconds - redisOptions options = {0}; - REDIS_OPTIONS_SET_TCP(&options, hostname, port); + redictOptions options = {0}; + REDICT_OPTIONS_SET_TCP(&options, hostname, port); options.connect_timeout = &tv; - c = redisConnectWithOptions(&options); + c = redictConnectWithOptions(&options); if (c == NULL || c->err) { if (c) { printf("Connection error: %s\n", c->errstr); - redisFree(c); + redictFree(c); } else { printf("Connection error: can't allocate redict context\n"); } exit(1); } - if (redisInitiateSSLWithContext(c, ssl) != REDIS_OK) { + if (redictInitiateSSLWithContext(c, ssl) != REDICT_OK) { printf("Couldn't initialize SSL!\n"); printf("Error: %s\n", c->errstr); - redisFree(c); + redictFree(c); exit(1); } /* PING server */ - reply = redisCommand(c,"PING"); + reply = redictCommand(c,"PING"); printf("PING: %s\n", reply->str); freeReplyObject(reply); /* Set a key */ - reply = redisCommand(c,"SET %s %s", "foo", "hello world"); + reply = redictCommand(c,"SET %s %s", "foo", "hello world"); printf("SET: %s\n", reply->str); freeReplyObject(reply); /* Set a key using binary safe API */ - reply = redisCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); + reply = redictCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); printf("SET (binary API): %s\n", reply->str); freeReplyObject(reply); /* Try a GET and two INCR */ - reply = redisCommand(c,"GET foo"); + reply = redictCommand(c,"GET foo"); printf("GET foo: %s\n", reply->str); freeReplyObject(reply); - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* again ... */ - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* Create a list of numbers, from 0 to 9 */ - reply = redisCommand(c,"DEL mylist"); + reply = redictCommand(c,"DEL mylist"); freeReplyObject(reply); for (j = 0; j < 10; j++) { char buf[64]; snprintf(buf,64,"%u",j); - reply = redisCommand(c,"LPUSH mylist element-%s", buf); + reply = redictCommand(c,"LPUSH mylist element-%s", buf); freeReplyObject(reply); } /* Let's check what we have inside the list */ - reply = redisCommand(c,"LRANGE mylist 0 -1"); - if (reply->type == REDIS_REPLY_ARRAY) { + reply = redictCommand(c,"LRANGE mylist 0 -1"); + if (reply->type == REDICT_REPLY_ARRAY) { for (j = 0; j < reply->elements; j++) { printf("%u) %s\n", j, reply->element[j]->str); } @@ -110,9 +110,9 @@ int main(int argc, char **argv) { freeReplyObject(reply); /* Disconnects and frees the context */ - redisFree(c); + redictFree(c); - redisFreeSSLContext(ssl); + redictFreeSSLContext(ssl); return 0; } diff --git a/examples/example.c b/examples/example.c index 41c8189..28e77e4 100644 --- a/examples/example.c +++ b/examples/example.c @@ -13,10 +13,10 @@ #include /* For struct timeval */ #endif -static void example_argv_command(redisContext *c, size_t n) { +static void example_argv_command(redictContext *c, size_t n) { char **argv, tmp[42]; size_t *argvlen; - redisReply *reply; + redictReply *reply; /* We're allocating two additional elements for command and key */ argv = malloc(sizeof(*argv) * (2 + n)); @@ -36,17 +36,17 @@ static void example_argv_command(redisContext *c, size_t n) { argv[i] = strdup(tmp); } - /* Execute the command using redisCommandArgv. We're sending the arguments with + /* Execute the command using redictCommandArgv. We're sending the arguments with * two explicit arrays. One for each argument's string, and the other for its * length. */ - reply = redisCommandArgv(c, n + 2, (const char **)argv, (const size_t*)argvlen); + reply = redictCommandArgv(c, n + 2, (const char **)argv, (const size_t*)argvlen); if (reply == NULL || c->err) { fprintf(stderr, "Error: Couldn't execute redictCommandArgv\n"); exit(1); } - if (reply->type == REDIS_REPLY_INTEGER) { + if (reply->type == REDICT_REPLY_INTEGER) { printf("%s reply: %lld\n", argv[0], reply->integer); } @@ -63,8 +63,8 @@ static void example_argv_command(redisContext *c, size_t n) { int main(int argc, char **argv) { unsigned int j, isunix = 0; - redisContext *c; - redisReply *reply; + redictContext *c; + redictReply *reply; const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1"; if (argc > 2) { @@ -79,14 +79,14 @@ int main(int argc, char **argv) { struct timeval timeout = { 1, 500000 }; // 1.5 seconds if (isunix) { - c = redisConnectUnixWithTimeout(hostname, timeout); + c = redictConnectUnixWithTimeout(hostname, timeout); } else { - c = redisConnectWithTimeout(hostname, port, timeout); + c = redictConnectWithTimeout(hostname, port, timeout); } if (c == NULL || c->err) { if (c) { printf("Connection error: %s\n", c->errstr); - redisFree(c); + redictFree(c); } else { printf("Connection error: can't allocate redict context\n"); } @@ -94,58 +94,58 @@ int main(int argc, char **argv) { } /* PING server */ - reply = redisCommand(c,"PING"); + reply = redictCommand(c,"PING"); printf("PING: %s\n", reply->str); freeReplyObject(reply); /* Set a key */ - reply = redisCommand(c,"SET %s %s", "foo", "hello world"); + reply = redictCommand(c,"SET %s %s", "foo", "hello world"); printf("SET: %s\n", reply->str); freeReplyObject(reply); /* Set a key using binary safe API */ - reply = redisCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); + reply = redictCommand(c,"SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); printf("SET (binary API): %s\n", reply->str); freeReplyObject(reply); /* Try a GET and two INCR */ - reply = redisCommand(c,"GET foo"); + reply = redictCommand(c,"GET foo"); printf("GET foo: %s\n", reply->str); freeReplyObject(reply); - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* again ... */ - reply = redisCommand(c,"INCR counter"); + reply = redictCommand(c,"INCR counter"); printf("INCR counter: %lld\n", reply->integer); freeReplyObject(reply); /* Create a list of numbers, from 0 to 9 */ - reply = redisCommand(c,"DEL mylist"); + reply = redictCommand(c,"DEL mylist"); freeReplyObject(reply); for (j = 0; j < 10; j++) { char buf[64]; snprintf(buf,64,"%u",j); - reply = redisCommand(c,"LPUSH mylist element-%s", buf); + reply = redictCommand(c,"LPUSH mylist element-%s", buf); freeReplyObject(reply); } /* Let's check what we have inside the list */ - reply = redisCommand(c,"LRANGE mylist 0 -1"); - if (reply->type == REDIS_REPLY_ARRAY) { + reply = redictCommand(c,"LRANGE mylist 0 -1"); + if (reply->type == REDICT_REPLY_ARRAY) { for (j = 0; j < reply->elements; j++) { printf("%u) %s\n", j, reply->element[j]->str); } } freeReplyObject(reply); - /* See function for an example of redisCommandArgv */ + /* See function for an example of redictCommandArgv */ example_argv_command(c, 10); /* Disconnects and frees the context */ - redisFree(c); + redictFree(c); return 0; } -- cgit v1.2.3