is it possible to call lua functions defined in other lua scripts in redis?

后端 未结 3 1662
滥情空心
滥情空心 2020-12-19 14:12

I have tried to declare a function without the local keyword and then call that function from anther script but it gives me an error when I run the command.

         


        
3条回答
  •  孤城傲影
    2020-12-19 14:54

    Because I'm not one to leave well enough alone, I built a package that allows for simple internal calling semantics. The package (for Python) is available on GitHub.

    Long story short, it uses ARGV as a call stack, translates KEYS/ARGV references to _KEYS and _ARGV, uses Redis as a name -> hash mapping internally, and translates CALL.(, ) to a table append + Redis lookup + Lua function call.

    The METHOD.txt file describes what goes on, and all of the regular expressions I used to translate the Lua scripts are available in lua_call.py. Feel free to re-use my semantics.

    The use of the function registry makes this very unlikely to work in Redis cluster or any other multi-shard setup, but for single-master applications, it should work for the foreseeable future.

提交回复
热议问题