Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using AWS cluster - Trouble writing values to it #166

Open
ferchor2003 opened this issue Nov 3, 2023 · 5 comments
Open

Using AWS cluster - Trouble writing values to it #166

ferchor2003 opened this issue Nov 3, 2023 · 5 comments

Comments

@ferchor2003
Copy link

ferchor2003 commented Nov 3, 2023

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
Copy link
Collaborator

mzimbres commented Nov 3, 2023

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
Copy link
Collaborator

mzimbres commented Nov 3, 2023

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

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

@mzimbres
Copy link
Collaborator

mzimbres commented Nov 3, 2023

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
Copy link
Author

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
Copy link
Collaborator

mzimbres commented Nov 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants