Below is my lua script:
     local ckid = redis.pcall('get',KEYS[1])
     local meta = redis.call('hgetall', ckid)
     return {ckid, meta}
if the key does not exits for the first call I would not like to execute the second.
So...I don't what the return value is for None. In python the return value would be None.
if ckid ~= '???????' then 
    local meta = redis.call('hgetall', ckid)
else
     local meta = 'empty'
retrun {ckid, meta}
So...how do I do this is lua?
     local ckid = redis.pcall('get',KEYS[1])
     if ckid ~= nil then
         local meta = redis.call('hgetall', ckid)
     else
         local meta = 'none'
         local ckid = 'none'
     end
     return {ckid, meta}
When using nil..
ResponseError: ERR Error running script (call to f_1400713412b0063a26eb0dc063f53a4e3be26380): user_script:12: Script attempted to access unexisting global variable 'meta'
                If you define a Local variable with in an if statement it only exists for the if statement. Check out local variable scope in the manual.
Try
 local ckid = redis.pcall('get',KEYS[1])
 local meta
 if ckid ~= nil then
     meta = redis.call('hgetall', ckid)
 else
     meta = 'none'
     ckid = 'none'
 end
 return {ckid, meta}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With