]>
git.saurik.com Git - redis.git/blob - deps/hiredis/example.c
12 c
= redisConnect((char*)"127.0.0.1", 6379);
14 printf("Connection error: %s\n", c
->errstr
);
19 reply
= redisCommand(c
,"PING");
20 printf("PONG: %s\n", reply
->str
);
21 freeReplyObject(reply
);
24 reply
= redisCommand(c
,"SET %s %s", "foo", "hello world");
25 printf("SET: %s\n", reply
->str
);
26 freeReplyObject(reply
);
28 /* Set a key using binary safe API */
29 reply
= redisCommand(c
,"SET %b %b", "bar", 3, "hello", 5);
30 printf("SET (binary API): %s\n", reply
->str
);
31 freeReplyObject(reply
);
33 /* Try a GET and two INCR */
34 reply
= redisCommand(c
,"GET foo");
35 printf("GET foo: %s\n", reply
->str
);
36 freeReplyObject(reply
);
38 reply
= redisCommand(c
,"INCR counter");
39 printf("INCR counter: %lld\n", reply
->integer
);
40 freeReplyObject(reply
);
42 reply
= redisCommand(c
,"INCR counter");
43 printf("INCR counter: %lld\n", reply
->integer
);
44 freeReplyObject(reply
);
46 /* Create a list of numbers, from 0 to 9 */
47 reply
= redisCommand(c
,"DEL mylist");
48 freeReplyObject(reply
);
49 for (j
= 0; j
< 10; j
++) {
52 snprintf(buf
,64,"%d",j
);
53 reply
= redisCommand(c
,"LPUSH mylist element-%s", buf
);
54 freeReplyObject(reply
);
57 /* Let's check what we have inside the list */
58 reply
= redisCommand(c
,"LRANGE mylist 0 -1");
59 if (reply
->type
== REDIS_REPLY_ARRAY
) {
60 for (j
= 0; j
< reply
->elements
; j
++) {
61 printf("%u) %s\n", j
, reply
->element
[j
]->str
);
64 freeReplyObject(reply
);