Lua functions in Redis w/string splitting
If you need to write a function for use in a redis lua script, create it as an anonymous function and assign it to a local variable. You can then use it like you would a first class function stored in a variable.
Also, lua does not appear to have a “split/explode” function which is available in many other languages. Here is one that I’ve copied from their site and modified a bit. It works well for my needs in lua 5.1.
The Redis Lua interpreter loads the following Lua libraries:
- base lib.
- table lib.
- string lib.
- math lib.
- debug lib.
- cjson lib.
- cmsgpack lib.
Every Redis instance is guaranteed to have all the above libraries so you can be sure that the environment for your Redis scripts is always the same.
The CJSON library provides extremely fast JSON manipulation within Lua. All the other libraries are standard Lua libraries.
To understand all of the functions which are available for use in redis 2.6, this is helpful.