StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.87k stars 1.51k forks source link

Sentinel mode selecting master #2542

Closed joesun99 closed 12 months ago

joesun99 commented 1 year ago

Hi everyone, hope u r all doing fine. I am having problem connecting to my test docker redis-sentinel setup. I have three redis instances on ports 6381, 6382, 6383 and three sentinel instances running on ports 5000, 5001 and 5002.

Am I able to connect through custom ports?

Kind regrads

mgravell commented 1 year ago

Ports can be specified in either a configuration string ("server:port") or via the endpoints API. Do you have an example of how you're trying to connect currently?

joesun99 commented 1 year ago

Sample connections of host property in my Microsoft.Web.Redis.RedisSessionStateProvider:

  1. "redis.local:6381, redis.local:6382, redis.local:6383, serviceName=mymaster" UnableToConnect on redis.local:6381, redis.local:6382, redis.local:6383, serviceName=mymaster:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.6.122.38350

  2. "redis.local:5000, redis.local:5001, redis.local:5002, serviceName=mymaster" UnableToConnect on redis.local:5000, redis.local:5001, redis.local:5002, serviceName=mymaster:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.6.122.38350

  3. redis.local:6381 If 6381 is master then is working

joesun99 commented 1 year ago

Could be that redis and sentinel must be on same instance with default port 6379 and 26379?

slorello89 commented 1 year ago

@joesun99

Something really important to keep in mind when you are experimenting with Sentinel/cluster inside of docker is that the IP addresses / host-names that the sentinel/masters will respond with will not necessarily be accessible outside of your docker network, you might have to deploy your application into the network in order for it to see it.

joesun99 commented 12 months ago

Hi, @slorello89 I have my public ip exposed for example i am using -slave-announce-ip xx.xx.xx.xx --slave-announce-port xxxx I also tested and sentinels are electing master In different test cases. I think problem is with Stackexchange driver that is awaiting redis and sentinel running on same instance with default ports. Of Course the ip addr should be exposed. I think I have to debug the driver to confirm my assumption. In another setup/env where we have multiple public ip with default ports thing are working without problems.

NickCraver commented 12 months ago

@joesun99 I looked over the obvious here: it's spaces in your connection string. That's being parsed as one giant endpoint :)

joesun99 commented 12 months ago

Sorry I found where my bug was sorry for bothering. It was RedisStateProvider https://learn.microsoft.com/de-de/azure/azure-cache-for-redis/cache-aspnet-session-state-provider After using connectionString property not host everything works fine. fyi: connectionString = "