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
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Select the correct Redis database (db 1, matching backend config)
|
-- Authenticate FIRST if password is set (must happen before any other commands)
|
||||||
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
|
|
||||||
if REDIS_PASSWORD and REDIS_PASSWORD ~= "" then
|
if REDIS_PASSWORD and REDIS_PASSWORD ~= "" then
|
||||||
local res, err = red:auth(REDIS_PASSWORD)
|
local res, err = red:auth(REDIS_PASSWORD)
|
||||||
if not res then
|
if not res then
|
||||||
ngx.log(ngx.ERR, "Failed to authenticate to Redis: ", err)
|
ngx.log(ngx.ERR, "Failed to authenticate to Redis: ", err)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
ngx.log(ngx.WARN, "No Redis password set, trying without auth")
|
|
||||||
|
-- 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
|
end
|
||||||
|
|
||||||
return red
|
return red
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue