Skip to content

Commit 7241d1d

Browse files
committed
Merge branch 'rainest-feature/sentinel-password'
2 parents 2f816a7 + 73a9ff3 commit 7241d1d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ When connecting via Redis Sentinel, the format is as follows:
9191

9292
Again, `PASSWORD` and `DB` are optional. `ROLE` must be either `m` or `s` for master / slave respectively.
9393

94+
On versions of Redis newer than 5.0.1, Sentinels can optionally require their own password. If enabled, provide this password in the `sentinel_password` parameter.
95+
9496
A table of `sentinels` must also be supplied. e.g.
9597

9698
```lua
9799
local redis, err = rc:connect{
98100
url = "sentinel://mymaster:a/2",
99101
sentinels = {
100102
{ host = "127.0.0.1", port = 26379 },
101-
}
103+
},
104+
sentinel_password = "password"
102105
}
103106
```
104107

@@ -133,6 +136,7 @@ If configured as a table of commands, the command methods will be replaced by a
133136
port = "6379",
134137
path = "", -- unix socket path, e.g. /tmp/redis.sock
135138
password = "",
139+
sentinel_password = "",
136140
db = 0,
137141

138142
master_name = "mymaster",

lib/resty/redis/connector.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ local DEFAULTS = setmetatable({
9595
port = 6379,
9696
path = "", -- /tmp/redis.sock
9797
password = "",
98+
sentinel_password = "",
9899
db = 0,
99100
url = "", -- DSN url
100101

@@ -227,6 +228,12 @@ function _M.connect_via_sentinel(self, params)
227228
local role = params.role
228229
local db = params.db
229230
local password = params.password
231+
local sentinel_password = params.sentinel_password
232+
if sentinel_password then
233+
for i,host in ipairs(sentinels) do
234+
host.password = sentinel_password
235+
end
236+
end
230237

231238
local sentnl, err, previous_errors = self:try_hosts(sentinels)
232239
if not sentnl then

lua-resty-redis-connector-0.07-1.rockspec renamed to lua-resty-redis-connector-0.08.rockspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package = "lua-resty-redis-connector"
2-
version = "0.07-1"
2+
version = "0.08"
33
source = {
44
url = "git://github.com/ledgetech/lua-resty-redis-connector",
5-
tag = "v0.07"
5+
tag = "v0.08"
66
}
77
description = {
88
summary = "Connection utilities for lua-resty-redis.",

0 commit comments

Comments
 (0)