summaryrefslogtreecommitdiff
path: root/example.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-05-18 17:11:09 +0200
committerantirez <antirez@gmail.com>2010-05-18 17:11:09 +0200
commit4f6fc6dfb13ba65a88b3976814f41f5f5ce24dc0 (patch)
tree9031cf1936722715aba14135781e05cec1af8592 /example.c
hiredis was extracted from redis-tools, reverted to standard malloc/free, ported to the new protocol, and started as a stand alone project in order to support the need of a C client in the Redis community
Diffstat (limited to 'example.c')
-rw-r--r--example.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/example.c b/example.c
new file mode 100644
index 0000000..05a0fa4
--- /dev/null
+++ b/example.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "hiredis.h"
+
+int main(void) {
+ int fd;
+ redisReply *reply;
+
+ reply = redisConnect(&fd, "127.0.0.1", 6379);
+ if (reply != NULL) {
+ printf("Connection error: %s", reply->reply);
+ exit(1);
+ }
+
+ /* PING server */
+ reply = redisCommand(fd,"PING");
+ printf("PONG: %s\n", reply->reply);
+ freeReplyObject(reply);
+
+ /* Set a key */
+ reply = redisCommand(fd,"SET %s %s\n", "foo", "hello world");
+ printf("SET: %s\n", reply->reply);
+ freeReplyObject(reply);
+
+ /* Set a key using binary safe API */
+ reply = redisCommand(fd,"SET %b %b\n", "bar", 3, "hello", 5);
+ printf("SET (binary API): %s\n", reply->reply);
+ freeReplyObject(reply);
+
+ return 0;
+}