diff options
author | Michael Grunder <michael.grunder@gmail.com> | 2022-09-21 15:10:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-21 15:10:37 -0700 |
commit | 68b29e1ad509f45af8a6ca9486463d9a57a391f1 (patch) | |
tree | 81a54114a9e4b783a85ff026fe93ce27e857aee7 /examples | |
parent | 722e3409c7d133524750036655bf24d3193ff951 (diff) |
Add timeout support to libhv adapter. (#1109)
Add timeout support to libhv adapter.
See: #904
Diffstat (limited to 'examples')
-rw-r--r-- | examples/example-libhv.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/example-libhv.c b/examples/example-libhv.c index 23c8bc1..ac68b00 100644 --- a/examples/example-libhv.c +++ b/examples/example-libhv.c @@ -16,6 +16,18 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) { redisAsyncDisconnect(c); } +void debugCallback(redisAsyncContext *c, void *r, void *privdata) { + (void)privdata; + redisReply *reply = r; + + if (reply == NULL) { + printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error"); + return; + } + + redisAsyncDisconnect(c); +} + void connectCallback(const redisAsyncContext *c, int status) { if (status != REDIS_OK) { printf("Error: %s\n", c->errstr); @@ -46,10 +58,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); hloop_run(loop); + hloop_free(&loop); return 0; } |