Hi!

I am developing a project in Net 6 version. There are high-availability productions that are master, slave, and sentinel. I know who the master is before the project starts. So i can use master ip. But if the master crashes at run time, the sentinels will choose a new master. This selection will change the ip address of master redis. I cannot change the ip address that I specified at the beginning because I created a single instance of the redis service in my net project. (Services.AddSingleton). What should I do in this situation? if the master changes, I will get an error because there is no write operation to the slaves. How do I select master?

Click for a simple redis service example.

Comment From: CharlesChen888

https://redis.io/docs/management/sentinel/

Use this command with the original master's name SENTINEL get-master-addr-by-name <master_name>

Comment From: cihatsolak

I didn't quite understand what you wanted to say. What ip address do I have to give when registering to a container like redis autofac? Or how should I set up this scenario? It would be great for me if you provide sample code.

Comment From: CharlesChen888

What I meant was that you can send the command to the sentinel (you must know the sentinel's ip), and it will return the new master's ip and port when the failover is done.

Comment From: cihatsolak

I create a single (Services.AddSingleton) instance from redis and use the same instance throughout the lifecycle of the app. (.Net 6 LTS) At first I left a link on this topic. if the ip changes do i change the new ip ?

Even if sentinel sends me the ip address of the new master, I have to restart the application to be able to change the ip address, as I am creating a single instance.

Comment From: igxlin

Even if sentinel sends me the ip address of the new master, I have to restart the application to be able to change the ip address

You just need to add some code logic to refresh the redis config in client and make your client connect to the new instance when the failover happens, right? Why restart the application?

Comment From: cihatsolak

like this, i know the ip address of the master. I define this ip address and create a singleton class and use this class throughout the application's lifecycle. So if at any time the ip address of the master changes, there will be a problem. Because I have defined the master's address as a constant.

services.AddSingleton<IRedisService, RedisService>() You can think like.

Actually, the scenario I imagined is as follows. Let me define the IP address of all slaves and the IP address of the master to the application. if any of the slaves become the administrator, I want the code to detect it .