-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Example of sentinel master failover #47
Comments
What do you mean by "deal with master failover" exactly? Redis Sentinel can promote a replica to master in the event of failure, so from the point of view of this module, so long as the sentinels you provide in the config are still available, they should give you the new master when it is ready. You'll need to handle failures during any failover period, and one way of handling that can be to choose a replica for read-only operations (by specifying the role). This document explains what to expect: https://redis.io/topics/sentinel |
No, nothing that complex. I only need to stay connected to the current primary. I'm new to lua/resty and how it manages connections / pools is a bit confusing to me. local function do_redis()
local rc = require("resty.redis.connector").new()
local master, err = local redis, err = rc:connect{
url = 'sentinel://mymaster:m'
sentinels = {
{ host = "sentinel-1", port = 26379 },
{ host = "sentinel-2", port = 26379 },
}
}
}
result, err = master.set('foo', 'bar')
if err then
return err
end
rc.set_keepalive(master)
end So my understanding is every time Sorry for all the questions. I'm just trying to understand how to best use the library |
No worries, yes you're thinking about it in the right way. You might want to check the result from Using this connector module does add an extra layer of abstraction. So when you ask for a master node, you'll get back a To answer your question, yes a connection to a failed master will live in the pool until it is either evicted, or reused - there's nothing actively managing the pool, it's just a cache of recently healthy connections. If a host is suddenly no longer available, the connection will obviously not be usable, and so you'll get errors and any attempt to call |
So this snippet I've got here is basically it? Maybe just a little more / smarter error handling? Do I need to explicitly close a connection if |
is a function call returning an error the only way to know that something is off with the connection? or are there any state properties once can introspect? |
@pintsized is it safe to use the pool settings when using sentinel? |
I'm trying to understand the best way to deal with master failover. Is this something that the module does inherently? Or does every application need to implement this?
What is the best way to do this? And example would be very helpful
The text was updated successfully, but these errors were encountered: