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.
This commit is contained in:
parent
fbf1bb648e
commit
253e796a59
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
#include <hiredis.h>
|
#include <hiredis.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char **argv) {
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
redisContext *c;
|
redisContext *c;
|
||||||
redisReply *reply;
|
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
|
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 == NULL || c->err) {
|
||||||
if (c) {
|
if (c) {
|
||||||
printf("Connection error: %s\n", c->errstr);
|
printf("Connection error: %s\n", c->errstr);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user