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

[QUESTION] What happens if the master redis ip address changes? #11701

Open
cihatsolak opened this issue Jan 9, 2023 · 6 comments
Open

[QUESTION] What happens if the master redis ip address changes? #11701

cihatsolak opened this issue Jan 9, 2023 · 6 comments

Comments

@cihatsolak
Copy link

cihatsolak commented Jan 9, 2023

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.

@CharlesChen888
Copy link
Contributor

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

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

@cihatsolak
Copy link
Author

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.

@CharlesChen888
Copy link
Contributor

CharlesChen888 commented Jan 10, 2023

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.

@cihatsolak
Copy link
Author

cihatsolak commented Jan 10, 2023

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.

@igxlin
Copy link
Contributor

igxlin commented Jan 11, 2023

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?

@cihatsolak
Copy link
Author

cihatsolak commented Jan 11, 2023

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 .

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

3 participants