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] #617

Open
hsh258 opened this issue Feb 4, 2025 · 12 comments
Open

[QUESTION] #617

hsh258 opened this issue Feb 4, 2025 · 12 comments

Comments

@hsh258
Copy link

hsh258 commented Feb 4, 2025

As sentinel mode,master restart,IP change , which change to slave, and origianl slave change to master.
How to set sentinel deploy blueprint and labels?

@sewenew
Copy link
Owner

sewenew commented Feb 5, 2025

If the old master is replaced by a new one, redis-plus-plus will get the new master's address from sentinels automatically. You don't need to worry about that. You only need to deploy the sentinel and master, slaves as the official site mentioned, and use the following code to create a Redis instance:

SentinelOptions sentinel_opts;
sentinel_opts.nodes = {{"127.0.0.1", 9000},
                        {"127.0.0.1", 9001},
                        {"127.0.0.1", 9002}};   // Required. List of Redis Sentinel nodes.

auto sentinel = std::make_shared<Sentinel>(sentinel_opts);

ConnectionOptions connection_opts;
connection_opts.password = "auth";  // Optional. No password by default.

auto redis = Redis(sentinel, "master_name", Role::MASTER, connection_opts);

Regards

@hsh258
Copy link
Author

hsh258 commented Feb 5, 2025

If the old master is replaced by a new one, redis-plus-plus will get the new master's address from sentinels automatically. You don't need to worry about that. You only need to deploy the sentinel and master, slaves as the official site mentioned, and use the following code to create a Redis instance:

SentinelOptions sentinel_opts;
sentinel_opts.nodes = {{"127.0.0.1", 9000},
                        {"127.0.0.1", 9001},
                        {"127.0.0.1", 9002}};   // Required. List of Redis Sentinel nodes.

auto sentinel = std::make_shared<Sentinel>(sentinel_opts);

ConnectionOptions connection_opts;
connection_opts.password = "auth";  // Optional. No password by default.

auto redis = Redis(sentinel, "master_name", Role::MASTER, connection_opts);

Regards

Hi,
sentinel,master,slave are in dockers. Could the IP 127.0.0.1 be founded by the others? thanks.
Is AsyncSentinel possible to use DNS service discovery methods?

@sewenew
Copy link
Owner

sewenew commented Feb 5, 2025

In your case, I don't think 127.0.0.1 can be used. If you specify a domain instead of IP, and your operation system can resolve it, AsyncSentinel can work. redis-plus-plus does not do any special service discovery job but rely on the operation system.

You'd better ask help from your network system admin or Redis admin for how to deploy Redis in sentinel mode.

Regards

@hsh258
Copy link
Author

hsh258 commented Feb 5, 2025

In your case, I don't think 127.0.0.1 can be used. If you specify a domain instead of IP, and your operation system can resolve it, AsyncSentinel can work. redis-plus-plus does not do any special service discovery job but rely on the operation system.

You'd better ask help from your network system admin or Redis admin for how to deploy Redis in sentinel mode.

Regards

Hi
If AsyncSentinel use DNS service discovery,How to config SentinelOptions? thanks.

@sewenew
Copy link
Owner

sewenew commented Feb 6, 2025

Replace the IP address with URI. However, as I mentioned, you need to ensure your operation system (not an external name service, e.g. zookeeper, etcd) can resolve the URI to IP.

Regards

@hsh258
Copy link
Author

hsh258 commented Feb 6, 2025

Replace the IP address with URI. However, as I mentioned, you need to ensure your operation system (not an external name service, e.g. zookeeper, etcd) can resolve the URI to IP.

Regards

Hi,
As you mentioned,Is it like this? thanks.

sentinel.conf
sentinel monitor mymaster redis-master 6379 2
sentinel announce-ip sentinel-hostname
replica-announce-ip replica-hostname
resolve-hostnames yes
announce-hostnames yes
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1

#include <sw/redis++/redis++.h>
#include
using namespace sw::redis;
int main() {
auto sentinel = AsyncSentinel("tcp://sentinel-hostname:26379");
......
}

@sewenew
Copy link
Owner

sewenew commented Feb 6, 2025

NO. AsyncSentinel's constructor does not take URI as parameter, instead, you can try to specify the hostname with SentinelOptions::nodes. However, I did not use sentinel with this setting (e.g. sentinel announce-ip sentinel-hostname), you'd better do some test. Good luck!

Regards

@hsh258
Copy link
Author

hsh258 commented Feb 7, 2025

NO. AsyncSentinel's constructor does not take URI as parameter, instead, you can try to specify the hostname with SentinelOptions::nodes. However, I did not use sentinel with this setting (e.g. sentinel announce-ip sentinel-hostname), you'd better do some test. Good luck!

Regards

Hi,
As you mentioned,Maybe like this? thanks.

#include <sw/redis++/async_redis++.h>
SentinelOptions sentinel_opts;
sentinel_opts.nodes = {
{"sentinel-hostname", 26379},
{"replica-hostname", 26380},
};
sentinel_opts.connect_timeout = std::chrono::milliseconds(100);
sentinel_opts.socket_timeout = std::chrono::milliseconds(100);
auto sentinel = std::make_shared(sentinel_opts);
onnectionOptions connection_opts;
connection_opts.connect_timeout = std::chrono::milliseconds(100);
connection_opts.socket_timeout = std::chrono::milliseconds(100);

ConnectionPoolOptions pool_opts;
pool_opts.size = 3;
AsyncRedis redis(sentinel, "mymaster", Role::MASTER, connection_opts, pool_opts);
AsyncRedis redis(sentinel, "mymaster", Role::SLAVE, connection_opts, pool_opts);

@sewenew
Copy link
Owner

sewenew commented Feb 8, 2025

You should specify all sentinel nodes' host and port to SentinelOptions::nodes, not a single one. Also, you might not need the replica-hostname.

Regards

@hsh258
Copy link
Author

hsh258 commented Feb 8, 2025

You should specify all sentinel nodes' host and port to SentinelOptions::nodes, not a single one. Also, you might not need the replica-hostname.

Regards

Hi,
As you mentioned,Maybe like this? thank you very much.

#include <sw/redis++/async_redis++.h>
SentinelOptions sentinel_opts;
sentinel_opts.nodes = {
{"sentinel1-hostname", 26379},
{"sentinel2-hostname", 26379},
{"sentinel3-hostname", 26379},
};
sentinel_opts.connect_timeout = std::chrono::milliseconds(100);
sentinel_opts.socket_timeout = std::chrono::milliseconds(100);
auto sentinel = std::make_shared(sentinel_opts);
onnectionOptions connection_opts;
connection_opts.connect_timeout = std::chrono::milliseconds(100);
connection_opts.socket_timeout = std::chrono::milliseconds(100);

ConnectionPoolOptions pool_opts;
pool_opts.size = 3;
AsyncRedis redis(sentinel, "mymaster", Role::MASTER, connection_opts, pool_opts);
AsyncRedis redis(sentinel, "mymaster", Role::SLAVE, connection_opts, pool_opts);

@sewenew
Copy link
Owner

sewenew commented Feb 10, 2025

YES, you can try this code.

Regards

@hsh258
Copy link
Author

hsh258 commented Feb 10, 2025

YES, you can try this code.

Regards

Thank you very much! Good luck!

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