]>
git.saurik.com Git - redis.git/blob - deps/hiredis/example.c
12 struct timeval timeout
= { 1, 500000 }; // 1.5 seconds
13 c
= redisConnectWithTimeout((char*)"127.0.0.2", 6379, timeout
);
15 printf("Connection error: %s\n", c
->errstr
);
20 reply
= redisCommand(c
,"PING");
21 printf("PING: %s\n", reply
->str
);
22 freeReplyObject(reply
);
25 reply
= redisCommand(c
,"SET %s %s", "foo", "hello world");
26 printf("SET: %s\n", reply
->str
);
27 freeReplyObject(reply
);
29 /* Set a key using binary safe API */
30 reply
= redisCommand(c
,"SET %b %b", "bar", 3, "hello", 5);
31 printf("SET (binary API): %s\n", reply
->str
);
32 freeReplyObject(reply
);
34 /* Try a GET and two INCR */
35 reply
= redisCommand(c
,"GET foo");
36 printf("GET foo: %s\n", reply
->str
);
37 freeReplyObject(reply
);
39 reply
= redisCommand(c
,"INCR counter");
40 printf("INCR counter: %lld\n", reply
->integer
);
41 freeReplyObject(reply
);
43 reply
= redisCommand(c
,"INCR counter");
44 printf("INCR counter: %lld\n", reply
->integer
);
45 freeReplyObject(reply
);
47 /* Create a list of numbers, from 0 to 9 */
48 reply
= redisCommand(c
,"DEL mylist");
49 freeReplyObject(reply
);
50 for (j
= 0; j
< 10; j
++) {
53 snprintf(buf
,64,"%d",j
);
54 reply
= redisCommand(c
,"LPUSH mylist element-%s", buf
);
55 freeReplyObject(reply
);
58 /* Let's check what we have inside the list */
59 reply
= redisCommand(c
,"LRANGE mylist 0 -1");
60 if (reply
->type
== REDIS_REPLY_ARRAY
) {
61 for (j
= 0; j
< reply
->elements
; j
++) {
62 printf("%u) %s\n", j
, reply
->element
[j
]->str
);
65 freeReplyObject(reply
);