summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMark Nunberg <mnunberg@haskalah.org>2018-12-06 04:55:47 -0500
committerMark Nunberg <mnunberg@haskalah.org>2019-02-20 09:10:10 -0500
commit7b705936f66f34f79ec0bc45c6c7cf4ab40296e7 (patch)
tree251435bca3306d9ef22bffe72cac23c9803dd106 /examples
parent53d9b12b76858bb236113628ad8585abbccd9f87 (diff)
libevent-example: Use timeout
Diffstat (limited to 'examples')
-rw-r--r--examples/example-libevent.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/examples/example-libevent.c b/examples/example-libevent.c
index d333c22..1fe71ae 100644
--- a/examples/example-libevent.c
+++ b/examples/example-libevent.c
@@ -9,7 +9,12 @@
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
- if (reply == NULL) return;
+ if (reply == NULL) {
+ if (c->errstr) {
+ printf("errstr: %s\n", c->errstr);
+ }
+ return;
+ }
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
@@ -35,8 +40,14 @@ void disconnectCallback(const redisAsyncContext *c, int status) {
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
struct event_base *base = event_base_new();
+ redisOptions options = {0};
+ REDIS_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379);
+ struct timeval tv = {0};
+ tv.tv_sec = 1;
+ options.timeout = &tv;
+
- redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
+ redisAsyncContext *c = redisAsyncConnectWithOptions(&options);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);