luca3m / redis3m

A C++ Redis client
Apache License 2.0
189 stars 78 forks source link

redis with haproxy #46

Open aidevr opened 7 years ago

aidevr commented 7 years ago

I'm using redis using haproxy and not managing connections with sentinels. Sentinels is being used for automatic fail-over, when fail-over happens redis3m returns transport_failur which I have put in try catch and haved continued once the exception is caught. But my connection object gets invalid and no other command is running on that object whereas connection with haproxy remains intact. What i want is to refresh redisContext of my connection such that my connection with haproxy does not break and redisContext gets refreshed. I have used redisFreeKeepFd and redisConnectFd but I'm unable to set new context to current connection object.

luca3m commented 7 years ago

Are you using this class? It automatically recycles connection.

aidevr commented 7 years ago

Im using connection class here is the sample code

connection::ptr_t conn = connection::create("127.0.0.1",port);
    unsigned int i = 0;
    while(i <numMessage) {
        if(conn->is_valid())
        {
            cout << " valid" << endl;
        }
      i++;
    string index = boost::lexical_cast<string>(i);
    string key = "mystore"+ index;
    string message = "Test message";
   cout << "in here" << endl;
    command t = command("SET") << key << message;
    try {
    conn->run(t);
    } catch(std::exception &ex) {
     sleep(2);
     continue;
    }

all iteration goes into the exception......

luca3m commented 7 years ago

I got your point, unfortunately redis3m has not been built for this scenario. But if you manage to find a solution a pull request is very welcome!