Redis - Lua tables as return values - why is this not working

后端 未结 2 1576
悲&欢浪女
悲&欢浪女 2021-02-08 15:47

When I run this code through redis EVAL it return no results. Any idea why this is not working?

redis-cli EVAL \"$(cat bug.lua)\" 0

bug.lua

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 16:20

    Answer from @deltheil is valid.

    Remember though that you can use cjson library to pack tables and pass them to consumers.

    Your lua file:

    local retv = {"This", "is", "a", "bug" }
    retv["test"] = 1000
    
    return cjson.encode(retv)
    

    Command:

    redis-cli EVAL "$(cat bug.lua)" 0
    

    Result:

    "{\"1\":\"This\",\"2\":\"is\",\"3\":\"a\",\"4\":\"bug\",\"test\":1000}"
    

提交回复
热议问题