Skip to content

Commit ec830ea

Browse files
DOC-5963 prepared hiredis landing page for notebook
1 parent 3ba34c0 commit ec830ea

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

content/develop/clients/hiredis/_index.md

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,8 @@ a string key using [`SET`]({{< relref "/commands/set" >}}) and
3838
[`GET`]({{< relref "/commands/get" >}}), and then finally closes the
3939
connection. 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

8144
For a real project, you would build your code with a makefile, but for
8245
this simple test, you can just place it in a file called `main.c` and
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// EXAMPLE: landing
2+
// BINDER_ID c-landing
3+
// STEP_START connect
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
#include <hiredis/hiredis.h>
8+
9+
int main() {
10+
// The `redisContext` type represents the connection
11+
// to the Redis server. Here, we connect to the
12+
// default host and port.
13+
redisContext *c = redisConnect("127.0.0.1", 6379);
14+
15+
// Check if the context is null or if a specific
16+
// error occurred.
17+
if (c == NULL || c->err) {
18+
if (c != NULL) {
19+
printf("Error: %s\n", c->errstr);
20+
// handle error
21+
} else {
22+
printf("Can't allocate redis context\n");
23+
}
24+
25+
exit(1);
26+
}
27+
28+
// Set a string key.
29+
redisReply *reply = redisCommand(c, "SET foo bar");
30+
printf("Reply: %s\n", reply->str); // >>> Reply: OK
31+
freeReplyObject(reply);
32+
33+
// Get the key we have just stored.
34+
reply = redisCommand(c, "GET foo");
35+
printf("Reply: %s\n", reply->str); // >>> Reply: bar
36+
freeReplyObject(reply);
37+
38+
// Close the connection.
39+
redisFree(c);
40+
}
41+
// STEP_END

0 commit comments

Comments
 (0)