How to include third party library when programmin

2019-09-02 06:44发布

I'm using Redis script by Lua to do some module related to money (http://redis.io/commands/eval). Unfortunately, Redis Lua does not support big decimal type. I searched through the internet and found some library for supporting decimal for lua like lmapm. But unfortunately, I don't know how to install to use it in Redis script.

For a general question, how can I install third party library for Redis script (like https://github.com/amakawa/ohm.lua), because seem like Redis script does not understand some basic function of Lua like "module", and has some restrict like no global variable and function...

Please help me to solve this. I searched around for days but can't find any solution. Thanks so much, I really appreciate!

1条回答
欢心
2楼-- · 2019-09-02 07:25

You can't - Redis' Lua engine does not support the use of external libraries.

The only way around this is to refactor the library and turn it into a Redis script that you can run. The refactored script can then be a part of your script, or you can SCRIPT LOAD it and call it from your script using an undocumented feature - in you script call the function f_sha1 where sha1 is the sha1 hash of the library script (but make sure that you SCRIPT LOAD the library script first).

查看更多
登录 后发表回答