How can I correctly check the type of a Redis key in Lua scripting?
I've found the answer here: Using the TYPE command inside a Redis / Lua Script
Short answer is that in lua scripts redis.call("TYPE", key) returns not string but lua table with key "ok" which holds string value of the type.
So to check the type of the key you should compare like this:
if redis.call("TYPE", key)["ok"] == "string"

for example:
127.0.0.1:6379> EVAL 'local type = redis.call("TYPE", KEYS[1])["ok"]; local res; if type == "string" then res = "ok" else res = "not ok" end return res' 1 test_key
"ok"


Correct way to check redis key's type in lua script.
I'm trying to wrap my head around redis lua scripting and I can't find the correct way to check what type the key has.
Here is what I've tried:
127.0.0.1:6379> SET test_key test_value
OK
127.0.0.1:6379> GET test_key
"test_value"
127.0.0.1:6379> EVAL 'local type = redis.call("TYPE", KEYS[1]); return type' 1 test_key
string

So I see that the type = "string", but:
127.0.0.1:6379> EVAL 'local type = redis.call("TYPE", KEYS[1]); local res; if type == string then res = "ok" else res = "not ok" end return res' 1 test_key
"not ok"
127.0.0.1:6379> EVAL 'local type = redis.call("TYPE", KEYS[1]); local res; if type == string then res = "ok" else res = "not ok" end return res' 1 "test_key"
"not ok"
127.0.0.1:6379> EVAL 'local type = redis.call("TYPE", KEYS[1]); local res; if type == "string" then res = "ok" else res = "not ok" end return res' 1 "test_key"
"not ok"
127.0.0.1:6379> EVAL 'local type = redis.call("TYPE", KEYS[1]); local res; if type == "string" then res = "ok" else res = "not ok" end return res' 1 test_key
"not ok"

