Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

example.c: it is now possible to specify server ip/port.

This makes possible to use the example with IPv6 addresses and/or with a
different Redis instance than 127.0.0.1:6379.
commit 253e796a59c68a0ccc57c156cfa61f97e97afad6 1 parent fbf1bb6
@antirez antirez authored
Showing with 4 additions and 2 deletions.
  1. +4 −2 examples/example.c
View
6 examples/example.c
@@ -4,13 +4,15 @@
#include <hiredis.h>
-int main(void) {
+int main(int argc, char **argv) {
unsigned int j;
redisContext *c;
redisReply *reply;
+ const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1";
+ int port = (argc > 2) ? atoi(argv[2]) : 6379;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
- c = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
+ c = redisConnectWithTimeout(hostname, port, timeout);
if (c == NULL || c->err) {
if (c) {
printf("Connection error: %s\n", c->errstr);
Please sign in to comment.
Something went wrong with that request. Please try again.