Add Redis check in API endpoints

This commit is contained in:
Théophile Diot 2024-02-21 11:05:25 +01:00
parent 93e4e63503
commit 638df130ec
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
2 changed files with 7 additions and 1 deletions

View file

@ -38,6 +38,9 @@ end
function redis:api()
if self.ctx.bw.uri == "/redis/ping" and self.ctx.bw.request_method == "POST" then
if self.variables["USE_REDIS"] ~= "yes" then
return self:ret(true, "redis is not enabled", HTTP_OK)
end
-- Check redis connection
local ok, err = self.clusterstore:connect(true)
if not ok then
@ -59,6 +62,9 @@ function redis:api()
return self:ret(true, "success", HTTP_OK)
end
if self.ctx.bw.uri == "/redis/stats" and self.ctx.bw.request_method == "GET" then
if self.variables["USE_REDIS"] ~= "yes" then
return self:ret(true, "redis is not enabled", HTTP_OK)
end
-- Connect to redis
local ok, err = self.clusterstore:connect(true)
if not ok then

View file

@ -17,4 +17,4 @@ def redis(**kwargs):
except:
data = {"redis_nb_keys": 0}
return {**ping, **data}
return ping | data