How to include third party library when programming Lua script in Redis

佐手、 提交于 2019-12-12 02:25:17

问题


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:


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).



来源:https://stackoverflow.com/questions/31259067/how-to-include-third-party-library-when-programming-lua-script-in-redis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!