1

I want to be able to check a value from a redis hash, date, to see if it is nil (in other words, the account is active)

local account = {}
local accountIds = redis.call('smembers', accounts)
for i, v in ipairs (accountIds)

    local accountDetails = redis.call('HMGET', 'accountHash' .. v, 'name', 'id', 'date')

    local date = accountDetails[3]

    if (date == nil) then
         table.insert(account, v)
         table.insert(account, list)
    end
end

When I print date on the java side while looping I get something like this:

2018-01-15 00:00:00.0, 2017-02-27 00:00:00.0, null, 2017-03-31 00:00:00.0, 2017-02-27 00:00:00.0, 2018-01-15 00:00:00.0, null,

So there are nils for date values, but my nil check is being skipped over every time. I have also tried:

if (date == 'nil') then
if (date == '') then
if (date == 'null') then
if (accountDetails[3] == nil) then
...

What am i doing wrong?

dk40149
  • 99
  • 1
  • 10
  • 1
    What do you get when you print `accountDetails[3]`? – Nifim Jun 18 '19 at 23:28
  • It returns the correct date – dk40149 Jun 19 '19 at 18:07
  • if `accountDetails[3]` is come out correctly as a date then it is not `null`. Is possible that the start index is 0 and not 1 so the `null` is at `accountDetails[2]`? – Nifim Jun 19 '19 at 19:34
  • @Nifim I should have clariified, it is printing both nulls and dates, which is right.. I want to be able to check if it is null to see if the account is still active. – dk40149 Jun 20 '19 at 20:08
  • I think i have an idea are you sure it is printing `null` or is it printing `null` with a space infront " null". – Nifim Jun 20 '19 at 20:42

0 Answers0