Redis Lua脚本中无法多次调用函数

我在Redis Lua脚本中有一个函数。如果我只调用一次函数,一切都很顺利。但是当我多次调用函数时,我会得到一个错误"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" });

如果我只调用一次mysplit()函数来填充表'abc',那么一切都会顺利,但是如果我第二次调用mysplit()函数来填充表xyz,它会抛出一个错误"ERR Protocol error: expected '$', got ' '"。

可能的原因是什么?是Redis不允许在Lua脚本中使用函数吗?

点赞