diff options
author | Alessio M <masariello@gmail.com> | 2020-09-04 09:31:47 +0100 |
---|---|---|
committer | Alessio M <masariello@gmail.com> | 2020-09-04 09:31:47 +0100 |
commit | d7b1d21e807f8a90a086b2ef5cea9b707d4cc858 (patch) | |
tree | 748b00a48a8b625f1dca22ae4cc5721ab7de87c5 /examples | |
parent | 07c3618ffe7912c2ebc589ea45501c687a19cf2c (diff) | |
parent | fb0e6c0dd9affd5728c6e0a6423f5dcb7b207947 (diff) |
Merge branch 'master' of github.com:redis/hiredis
Diffstat (limited to 'examples')
-rw-r--r-- | examples/example-libevent.c | 2 | ||||
-rw-r--r-- | examples/example-push.c | 22 | ||||
-rw-r--r-- | examples/example-ssl.c | 7 | ||||
-rw-r--r-- | examples/example.c | 5 |
4 files changed, 27 insertions, 9 deletions
diff --git a/examples/example-libevent.c b/examples/example-libevent.c index f3fa2a6..49bddd0 100644 --- a/examples/example-libevent.c +++ b/examples/example-libevent.c @@ -47,7 +47,7 @@ int main (int argc, char **argv) { REDIS_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379); struct timeval tv = {0}; tv.tv_sec = 1; - options.timeout = &tv; + options.connect_timeout = &tv; redisAsyncContext *c = redisAsyncConnectWithOptions(&options); diff --git a/examples/example-push.c b/examples/example-push.c index 23dbd17..6bc1205 100644 --- a/examples/example-push.c +++ b/examples/example-push.c @@ -31,7 +31,6 @@ #include <stdlib.h> #include <string.h> #include <hiredis.h> -#include <win32.h> #define KEY_COUNT 5 @@ -97,6 +96,13 @@ void pushReplyHandler(void *privdata, void *r) { freeReplyObject(reply); } +/* 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 */ +void privdata_dtor(void *privdata) { + unsigned int *icount = privdata; + printf("privdata_dtor(): In context privdata dtor (invalidations: %u)\n", *icount); +} + int main(int argc, char **argv) { unsigned int j, invalidations = 0; redisContext *c; @@ -108,6 +114,16 @@ int main(int argc, char **argv) { redisOptions o = {0}; REDIS_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. + * + * 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); + /* Set our custom PUSH message handler */ o.push_cb = pushReplyHandler; @@ -118,10 +134,6 @@ int main(int argc, char **argv) { /* Enable RESP3 and turn on client tracking */ enableClientTracking(c); - /* 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 */ - c->privdata = &invalidations; - /* Set some keys and then read them back. Once we do that, Redis will deliver * invalidation push messages whenever the key is modified */ for (j = 0; j < KEY_COUNT; j++) { diff --git a/examples/example-ssl.c b/examples/example-ssl.c index 5eb2bbb..b8ca442 100644 --- a/examples/example-ssl.c +++ b/examples/example-ssl.c @@ -4,7 +4,10 @@ #include <hiredis.h> #include <hiredis_ssl.h> -#include <win32.h> + +#ifdef _MSC_VER +#include <winsock2.h> /* For struct timeval */ +#endif int main(int argc, char **argv) { unsigned int j; @@ -33,7 +36,7 @@ int main(int argc, char **argv) { struct timeval tv = { 1, 500000 }; // 1.5 seconds redisOptions options = {0}; REDIS_OPTIONS_SET_TCP(&options, hostname, port); - options.timeout = &tv; + options.connect_timeout = &tv; c = redisConnectWithOptions(&options); if (c == NULL || c->err) { diff --git a/examples/example.c b/examples/example.c index 15dacbd..f1b8b4a 100644 --- a/examples/example.c +++ b/examples/example.c @@ -2,7 +2,10 @@ #include <stdlib.h> #include <string.h> #include <hiredis.h> -#include <win32.h> + +#ifdef _MSC_VER +#include <winsock2.h> /* For struct timeval */ +#endif int main(int argc, char **argv) { unsigned int j, isunix = 0; |