summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/example-libhv.c15
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;
}