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

Fix connecting through sentinels #78

Merged
merged 1 commit into from
Oct 14, 2023
Merged

Conversation

Yenya
Copy link
Contributor

@Yenya Yenya commented Jun 27, 2023

Fix for #76 :

When connecting to sentinels and sending get-master-addr-by-name query, the Mojo::Promise object should be bound to the Mojo::Redis' own ioloop, otherwise it is not fulfilled and the ->then() callback is not called.

Despite originally reported as authentication problem in #76, sentinel connection does not work at all, even when no authentication is set up. A minimal test case:

$ cat redis.conf
port 7000

$ cat sentinel.conf
port 7001
sentinel monitor mymaster 127.0.0.1 7000 1
sentinel down-after-milliseconds mymaster 60000

$ redis-server ./redis.conf &
$ redis-sentinel ./sentinel.conf &
$ perl -MRedis -E 'my $r = Redis->new(service=>"mymaster", sentinels=>["127.0.0.1:7001"]); $r->set("/test" => 42, EX => 100); say $r->get("/test")'
42
$ MOJO_REDIS_DEBUG=1 perl -MMojo::Redis -E 'my $r = Mojo::Redis->new("redis://mymaster?sentinel=127.0.0.1:7001"); $r->db->set("/test" => 42); say $r->db->get("/test");'

Fix for jhthorsen#76 :

When connecting to sentinels and sending get-master-addr-by-name
query, the Mojo::Promise object should be bound to the Mojo::Redis'
own ioloop, otherwise it is not fulfilled and the ->then() callback
is not called.

Despite originally reported as authentication problem in jhthorsen#76,
sentinel connection does not work at all, even when no authentication
is set up. A minimal test case:

$ cat redis.conf
port 7000

$ cat sentinel.conf
port 7001
sentinel monitor mymaster 127.0.0.1 7000 1
sentinel down-after-milliseconds mymaster 60000

$ redis-server ./redis.conf &
$ redis-sentinel ./sentinel.conf &
$ perl -MRedis -E 'my $r = Redis->new(service=>"mymaster", sentinels=>["127.0.0.1:7001"]); $r->set("/test" => 42, EX => 100); say $r->get("/test")'
42
$ MOJO_REDIS_DEBUG=1 perl -MMojo::Redis -E 'my $r = Mojo::Redis->new("redis://mymaster?sentinel=127.0.0.1:7001"); $r->db->set("/test" => 42); say $r->db->get("/test");'
Copy link
Owner

@jhthorsen jhthorsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. I would've liked a test for this. but going to take it either way 👍

@jhthorsen jhthorsen added the bug Something isn't working label Oct 14, 2023
@jhthorsen jhthorsen merged commit 5f55a3a into jhthorsen:main Oct 14, 2023
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants