Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ With DHSM storage you can use the following settings (set the `storage` to `"dsh
| `ssl` | `nil` | Enable SSL. |
| `ssl_verify` | `nil` | Verify server certificate. |
| `server_name` | `nil` | The server name for the new TLS extension Server Name Indication (SNI). |
| `force_auth` | `nil` | The flag controls whether to invoke auth after obtaining each Redis connection. |

Please refer to [ngx-distributed-shm](https://github.com/grrolland/ngx-distributed-shm) to get necessary
dependencies installed.
Expand Down
11 changes: 5 additions & 6 deletions lib/resty/session/redis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function exec(self, func, ...)
return nil, err
end

if red:get_reused_times() == 0 then
if self.force_auth == true or red:get_reused_times() == 0 then
local password = self.password
if password then
local username = self.username
Expand Down Expand Up @@ -99,11 +99,6 @@ local metatable = {}
metatable.__index = metatable


function metatable.__newindex()
error("attempt to update a read-only table", 2)
end


---
-- Store session data.
--
Expand Down Expand Up @@ -233,6 +228,8 @@ function storage.new(configuration)
local ssl_verify = configuration and configuration.ssl_verify
local server_name = configuration and configuration.server_name

local force_auth = configuration and configuration.force_auth
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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


if ssl ~= nil or ssl_verify ~= nil or server_name or pool or pool_size or backlog then
return setmetatable({
prefix = prefix,
Expand All @@ -247,6 +244,7 @@ function storage.new(configuration)
send_timeout = send_timeout,
read_timeout = read_timeout,
keepalive_timeout = keepalive_timeout,
force_auth = force_auth,
options = {
ssl = ssl,
ssl_verify = ssl_verify,
Expand All @@ -271,6 +269,7 @@ function storage.new(configuration)
send_timeout = send_timeout,
read_timeout = read_timeout,
keepalive_timeout = keepalive_timeout,
force_auth = force_auth,
}, metatable)
end

Expand Down
9 changes: 4 additions & 5 deletions lib/resty/session/redis/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ local metatable = {}
metatable.__index = metatable


function metatable.__newindex()
error("attempt to update a read-only table", 2)
end


---
-- Store session data.
--
Expand Down Expand Up @@ -206,6 +201,8 @@ function storage.new(configuration)
local ssl_verify = configuration and configuration.ssl_verify
local server_name = configuration and configuration.server_name

local force_auth = configuration and configuration.force_auth
Copy link
Copy Markdown
Contributor Author

@Water-Melon Water-Melon Nov 24, 2025

Choose a reason for hiding this comment

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



local auth
if not username then
Expand Down Expand Up @@ -235,6 +232,7 @@ function storage.new(configuration)
auth = auth,
username = username,
password = password,
force_auth = force_auth,
Copy link
Copy Markdown
Contributor Author

@Water-Melon Water-Melon Nov 21, 2025

Choose a reason for hiding this comment

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

ref: Kong/resty-redis-cluster#44

Only kong-resty-rediscluster will make this flag take effect.

connect_opts = {
ssl = ssl,
ssl_verify = ssl_verify,
Expand Down Expand Up @@ -266,6 +264,7 @@ function storage.new(configuration)
auth = auth,
username = username,
password = password,
force_auth = force_auth,
},
}, metatable)
end
Expand Down