{"action":"opened","issue":{"url":"https://api.github.com/repos/siddontang/ledisdb/issues/219","labels_url":"https://api.github.com/repos/siddontang/ledisdb/issues/219/labels{/name}","comments_url":"https://api.github.com/repos/siddontang/ledisdb/issues/219/comments","events_url":"https://api.github.com/repos/siddontang/ledisdb/issues/219/events","html_url":"https://github.com/siddontang/ledisdb/issues/219","id":125929223,"number":219,"title":"Lua script, HMGET, value for absent key","user":{"login":"nikolay-turpitko","id":1192730,"avatar_url":"https://avatars.githubusercontent.com/u/1192730?v=3","gravatar_id":"","url":"https://api.github.com/users/nikolay-turpitko","html_url":"https://github.com/nikolay-turpitko","followers_url":"https://api.github.com/users/nikolay-turpitko/followers","following_url":"https://api.github.com/users/nikolay-turpitko/following{/other_user}","gists_url":"https://api.github.com/users/nikolay-turpitko/gists{/gist_id}","starred_url":"https://api.github.com/users/nikolay-turpitko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikolay-turpitko/subscriptions","organizations_url":"https://api.github.com/users/nikolay-turpitko/orgs","repos_url":"https://api.github.com/users/nikolay-turpitko/repos","events_url":"https://api.github.com/users/nikolay-turpitko/events{/privacy}","received_events_url":"https://api.github.com/users/nikolay-turpitko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-11T12:07:05Z","updated_at":"2016-01-11T12:07:05Z","closed_at":null,"body":"Redis returns `boolean`, while LedisDB returns empty string for absent keys in HMGET in the Lua script.\r\n\r\nDon't know is it a major issue or not, but it worth at list to mention it somewhere in the EVAL command description, I recon.\r\n\r\nIn the samples below I've tried to set some default value for keys absent in the hash and discovered that checks for `not table[key]` or `table[key] == nil` don't work, I've had to check for empty string to make it work.\r\n\r\n    redis redis.socket> hmset zzz 1 2 5 42\r\n    OK\r\n    \r\n    redis redis.socket> hmget zzz 1 2 5 42\r\n    1) \"2\"\r\n    2) (nil)\r\n    3) \"42\"\r\n    4) (nil)\r\n    \r\n    redis redis.socket> eval \"local a=redis.call('hmget', 'zzz', 1, 2, 5, 42); for i,v in ipairs(ARGV) do if not a[i] then a[i]='zz'; end; end; return a\" 0 1 2 3 4 5\r\n    1) \"2\"\r\n    2) \"zz\"\r\n    3) \"42\"\r\n    4) \"zz\"\r\n    5) \"zz\"\r\n\r\n    redis redis.socket> eval \"local a=redis.call('hmget', 'zzz', 1, 2, 5, 42); for i,v in ipairs(ARGV) do a[i] =type(a[i]); end; return a\" 0 1 2 3 4 5\r\n    1) \"string\"\r\n    2) \"boolean\"\r\n    3) \"string\"\r\n    4) \"boolean\"\r\n    5) \"nil\"\r\n    \r\n    ------------------\r\n    \r\n    redis ledisdb.socket> hmset zzz 1 2 5 42\r\n    OK\r\n    \r\n    redis ledisdb.socket> hmget zzz 1 2 5 42\r\n    1) \"2\"\r\n    2) (nil)\r\n    3) \"42\"\r\n    4) (nil)\r\n    \r\n    redis ledisdb.socket> eval \"local a=ledis.call('hmget', 'zzz', 1, 2, 5, 42); for i,v in ipairs(ARGV) do if not a[i] then a[i]='zz'; end; end; return a\" 0 1 2 3 4 5\r\n    1) \"2\"\r\n    2) (nil)\r\n    3) \"42\"\r\n    4) (nil)\r\n    5) \"zz\"\r\n    \r\n    redis ledisdb.socket> eval \"local a=ledis.call('hmget', 'zzz', 1, 2, 5, 42); for i,v in ipairs(ARGV) do a[i] =type(a[i]); end; return a\" 0 1 2 3 4 5\r\n    1) \"string\"\r\n    2) \"string\"\r\n    3) \"string\"\r\n    4) \"string\"\r\n    5) \"nil\"\r\n\r\nTo check that string is empty you can run\r\n\r\n    eval \"local a=ledis.call('hmget', 'zzz', 1, 2, 5, 42); for i,v in ipairs(ARGV) do if not a[i] or a[i] == '' then a[i]='zz'; end; end; return a\" 0 1 2 3 4 5"}}