Fix: Redis AUTH must come before SELECT
All checks were successful
Build and Push / build-all (push) Successful in 21s
All checks were successful
Build and Push / build-all (push) Successful in 21s
The SELECT command was failing because Redis requires authentication first. Reordered commands: connect -> auth -> select. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
03e213df98
commit
db7faa5a75
1 changed files with 9 additions and 11 deletions
|
|
@ -18,23 +18,21 @@ local function get_redis_connection()
|
|||
return nil
|
||||
end
|
||||
|
||||
-- Select the correct Redis database (db 1, matching backend config)
|
||||
local db = tonumber(os.getenv("REDIS_DB")) or 1
|
||||
local res, err = red:select(db)
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "Failed to select Redis database: ", err)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Authenticate if password is set
|
||||
-- Authenticate FIRST if password is set (must happen before any other commands)
|
||||
if REDIS_PASSWORD and REDIS_PASSWORD ~= "" then
|
||||
local res, err = red:auth(REDIS_PASSWORD)
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "Failed to authenticate to Redis: ", err)
|
||||
return nil
|
||||
end
|
||||
else
|
||||
ngx.log(ngx.WARN, "No Redis password set, trying without auth")
|
||||
end
|
||||
|
||||
-- Select the correct Redis database (db 1, matching backend config)
|
||||
local db = tonumber(os.getenv("REDIS_DB")) or 1
|
||||
local res, err = red:select(db)
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "Failed to select Redis database: ", err)
|
||||
return nil
|
||||
end
|
||||
|
||||
return red
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue