I have a function inside Redis Lua script. If I call the function once everything runs smooth. But if I call the function multiple times I get an error "ERR Protocol error: expected '$', got ' '"
var doesExist6 = db.ScriptEvaluate(@" local userName = KEYS[1]
local function mysplit(inputstr, sep)
if sep == nil then
sep = '%s'
end
local t={}
local i=1
for str in string.gmatch(inputstr, '([^'..sep..']+)') do
t[i] = str
i = i + 1
end
return t
end
local abc = {}
abc = mysplit(userName, ':')
for k = 1, #abc, 1
do
print (abc[k])
end
local xyz = {}
xyz = mysplit(userName, ':')
for k = 1, #xyz, 1
do
print (xyz[k])
end
return xyz[1]..abc[2]",
new RedisKey[] { "UserDetails:" + "DummyUser" });
If I call the function mysplit() only once to populate the table 'abc' then everything runs smooth but if I call the function mysplit() second time to populate the table xyz it throws an error "ERR Protocol error: expected '$', got ' '".
What could be the possible reason? Is it that Redis does not allow functions inside Lua scripts?