]>
git.saurik.com Git - redis.git/blob - deps/hiredis/example-libev.c
7894f1f487bbac4fcf570801feddf386fb0eb36b
7 #include "adapters/libev.h"
9 void getCallback(redisAsyncContext
*c
, void *r
, void *privdata
) {
10 redisReply
*reply
= r
;
11 if (reply
== NULL
) return;
12 printf("argv[%s]: %s\n", (char*)privdata
, reply
->str
);
14 /* Disconnect after receiving the reply to GET */
15 redisAsyncDisconnect(c
);
18 void connectCallback(const redisAsyncContext
*c
, int status
) {
19 if (status
!= REDIS_OK
) {
20 printf("Error: %s\n", c
->errstr
);
23 printf("Connected...\n");
26 void disconnectCallback(const redisAsyncContext
*c
, int status
) {
27 if (status
!= REDIS_OK
) {
28 printf("Error: %s\n", c
->errstr
);
31 printf("Disconnected...\n");
34 int main (int argc
, char **argv
) {
35 signal(SIGPIPE
, SIG_IGN
);
37 redisAsyncContext
*c
= redisAsyncConnect("127.0.0.1", 6379);
39 /* Let *c leak for now... */
40 printf("Error: %s\n", c
->errstr
);
44 redisLibevAttach(EV_DEFAULT_ c
);
45 redisAsyncSetConnectCallback(c
,connectCallback
);
46 redisAsyncSetDisconnectCallback(c
,disconnectCallback
);
47 redisAsyncCommand(c
, NULL
, NULL
, "SET key %b", argv
[argc
-1], strlen(argv
[argc
-1]));
48 redisAsyncCommand(c
, getCallback
, (char*)"end-1", "GET key");
49 ev_loop(EV_DEFAULT_
0);