tags:

views:

66

answers:

1

simple script for connect server:

#include "hiredis.h"
int main(void) {
    int fd;

    unsigned int j;
    redisReply *reply;
    reply = redisConnect(&fd, "test.com", 6379);

    if (reply != NULL) {
        printf("Connection error: %s", reply->reply);
        exit(1);
    }

    reply = redisCommand(fd,"PING");
    printf("PONG: %s\n", reply->reply);
    freeReplyObject(reply);
}

if the server is available - everything is normal. If not - there is a long pause. How to reduce the waiting time to 2 seconds for example ?

A: 

You'll need to modify the hiredis library, and the anetTcpGenericConnect function to make connect timeout aware. There's an example here of how to do it.

hellvinz