@@ -38,45 +38,8 @@ a string key using [`SET`]({{< relref "/commands/set" >}}) and
3838[ ` GET ` ] ({{< relref "/commands/get" >}}), and then finally closes the
3939connection. An explanation of the code follows the example.
4040
41- ``` c
42- #include < stdio.h>
43- #include < stdlib.h>
44-
45- #include < hiredis/hiredis.h>
46-
47- int main () {
48- // The `redisContext` type represents the connection
49- // to the Redis server. Here, we connect to the
50- // default host and port.
51- redisContext *c = redisConnect("127.0.0.1", 6379);
52-
53- // Check if the context is null or if a specific
54- // error occurred.
55- if (c == NULL || c->err) {
56- if (c != NULL) {
57- printf ("Error: %s\n", c->errstr);
58- // handle error
59- } else {
60- printf("Can't allocate redis context\n");
61- }
62-
63- exit (1);
64- }
65-
66- // Set a string key.
67- redisReply *reply = redisCommand(c, "SET foo bar");
68- printf ("Reply: %s\n", reply->str); // >>> Reply: OK
69- freeReplyObject(reply);
70-
71- // Get the key we have just stored.
72- reply = redisCommand(c, "GET foo");
73- printf ("Reply: %s\n", reply->str); // >>> Reply: bar
74- freeReplyObject(reply);
75-
76- // Close the connection.
77- redisFree (c);
78- }
79- ```
41+ {{< clients-example set="landing" step="connect" lang_filter="C" >}}
42+ {{< /clients-example >}}
8043
8144For a real project, you would build your code with a makefile, but for
8245this simple test, you can just place it in a file called ` main.c ` and
0 commit comments