1
local password = json_string["password"] or "None"
local redisPassword = red:hmget(userName,"password") or None
local redisAuthtoken = red:hmget(userName,"authToken")
if (tostring(password)   ==  tostring(redisPassword))
then
    ngx.say(redisAuthtoken) 
else
    ngx.say("Error User or Service Not found 1510")
end 

password = admin redisPassword = admin

i am able to see both password as output admin but it is not matching in lua code and control always going to else part.

when i am comparing like this

if (tostring(password) == "admin" )

it is working fine which means the issue is with the redis value but i have set password value admin in redis.

1
  • What does the variable None contain? Commented May 1, 2016 at 20:54

1 Answer 1

2

My understanding is that hmget returns multi-bulk reply, which has the result in a lua table, so you should probably do something like this:

local res, err = red:hmget(userName,"password")
local redisPassword
if res and res ~= ngx.null then redisPassword = res[1] end
ngx.say(redisPassword)

From the documentation:

A non-nil Redis "multi-bulk reply" results in a Lua table holding all the composing values (if any). If any of the composing value is a valid redis error value, then it will be a two element table {false, err}. A nil multi-bulk reply returns in a ngx.null value.

Note that ngx.null value is not the same as Lua nil value, so you may need to check for that separately.

Also note that you use None as a variable and "None" as a string in two different places, which may not do what you expect.

Sign up to request clarification or add additional context in comments.

1 Comment

Awsome thanx @Paul

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.