]>
git.saurik.com Git - redis.git/blob - deps/hiredis/example-ae.c
7 #include "adapters/ae.h"
9 /* Put event loop in the global scope, so it can be explicitly stopped */
10 static aeEventLoop
*loop
;
12 void getCallback(redisAsyncContext
*c
, void *r
, void *privdata
) {
13 redisReply
*reply
= r
;
14 if (reply
== NULL
) return;
15 printf("argv[%s]: %s\n", (char*)privdata
, reply
->str
);
17 /* Disconnect after receiving the reply to GET */
18 redisAsyncDisconnect(c
);
21 void connectCallback(const redisAsyncContext
*c
, int status
) {
22 if (status
!= REDIS_OK
) {
23 printf("Error: %s\n", c
->errstr
);
26 printf("Connected...\n");
29 void disconnectCallback(const redisAsyncContext
*c
, int status
) {
30 if (status
!= REDIS_OK
) {
31 printf("Error: %s\n", c
->errstr
);
34 printf("Disconnected...\n");
37 int main (int argc
, char **argv
) {
38 signal(SIGPIPE
, SIG_IGN
);
40 redisAsyncContext
*c
= redisAsyncConnect("127.0.0.1", 6379);
42 /* Let *c leak for now... */
43 printf("Error: %s\n", c
->errstr
);
47 loop
= aeCreateEventLoop();
48 redisAeAttach(loop
, c
);
49 redisAsyncSetConnectCallback(c
,connectCallback
);
50 redisAsyncSetDisconnectCallback(c
,disconnectCallback
);
51 redisAsyncCommand(c
, NULL
, NULL
, "SET key %b", argv
[argc
-1], strlen(argv
[argc
-1]));
52 redisAsyncCommand(c
, getCallback
, (char*)"end-1", "GET key");