boostorg/redis

Using AWS cluster - Trouble writing values to it

ferchor2003 opened this issue · 5 comments

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());
   }

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.

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

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

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.

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

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.