boostorg / redis

An async redis client designed for performance and scalability
https://www.boost.org/doc/libs/develop/libs/redis/doc/html/index.html
Boost Software License 1.0
212 stars 38 forks source link

Using AWS cluster - Trouble writing values to it #166

Open ferchor2003 opened 8 months ago

ferchor2003 commented 8 months ago

Hi, Working on my app, everything looks fine in my local development environment with a single redis server on standard port. Running into problems when using an AWS environment with a cluster. Is there anything specific that needs to be set for a cluster?

The initial connection seems to go correctly using the following:

boost::redis::config cfg;
cfg.addr.host = "clustercfg.xxx-xxx-xxx.cache.amazonaws.com";
cfg.addr.port = "7000";
cfg.use_ssl = true;
cfg.clientname = "webserver";
cfg.log_prefix = "webserver.redis ";

and I see the following on std::cout, so it seems the cluster was correctly identified:

webserver.redis Resolve results: 10.32.35.71:7000, 10.32.35.244:7000, 10.32.34.195:7000, 10.32.34.189:7000
webserver.redis Connected to endpoint: 10.32.35.71:7000
webserver.redis SSL handshake: Success
webserver.redis Bytes written: 105
webserver.redis Hello: Success
webserver.redis Bytes written: 32

However, when trying an HSET operation I got an exception: Exception saving session to Redis. %s - keyid - Got RESP3 simple-error. [boost.redis:11]

This is the code that tries to write to the Cluster: (redisInst is an instance of sync_connection as it came from the examples dir)

    request req;
    boost::redis::response<
        int, // HSET
        boost::redis::ignore_t// EXPIRE
    > res;  
    try {
        req.push("HSET", key, "response", responseField);
        req.push("EXPIRE", key, maxSessionTimeToLiveSecs, "NX");    // Have the session teid expire 
        redisInst->exec(req, res);
        return true;
    }
    catch ( const std::exception& e )
    {
        LogError("Exception saving session to Redis. %s - %s", key.c_str(), e.what());
    }
mzimbres commented 8 months ago

Running into problems when using an AWS environment with a cluster

Do you mean a Redis cluster? So far there is not support for Redis-cluster in Boost.Redis.

mzimbres commented 8 months ago

Got RESP3 simple-error. [boost.redis:11]

It is important to know what message is contained in that error.

mzimbres commented 8 months ago

Can you please replace response<int, boost::redis::ignore_t> with response<int, int> and add this to your code

      if (std::get<0>(resp).has_error()) {
         std::cout << "Type: " << to_string(std::get<0>(resp).error().data_type) << std::endl;    
         std::cout << "Diagnostic: " << std::get<0>(resp).error().diagnostic << std::endl;        
      }
      if (std::get<1>(resp).has_error()) {
         std::cout << "Type: " << to_string(std::get<1>(resp).error().data_type) << std::endl;    
         std::cout << "Diagnostic: " << std::get<1>(resp).error().diagnostic << std::endl;        
      }

Let me then know what diagnostic do you get.

ferchor2003 commented 8 months ago

This is what the response now:

Type: simple_error
Diagnostic: MOVED 10848 xxx-xxx-xxx-xxx-xxx.cache.amazonaws.com:7000
Type: simple_error
Diagnostic: MOVED 10848 xxx-xxx-xxx-xxx-xxx.cache.amazonaws.com:7000

Where xxx-xxx-xxx is one of the cluster nodes

mzimbres commented 8 months ago

Ok, this means you are using a Redis cluster. As I said above, Boost.Redis does not provide any facility for cluster setups. In this case you would have to deal with the redirect yourself as describe under the in MOVED Redirection, which means creating a new connection to that node and maintaining a map of connections to prevent from opening more than one connection to the same node. Feel free to open an issue to add Redis cluster support, however I can't give you an estimate about when I will come up with it.