CTO at Orbulo·

At Tabulo, we make extensive use of Redis as a state store. However, for common operations, we found ourselves making multiple requests to the Redis server from our Elixir microservice. These network requests became a bottleneck, and so we turned to using Lua scripts that could be run on the context of the Redis server, which would only require one network request per script.

However, the Redis implementation of Lua had its restrictions; for one, we couldn't use require() calls in Lua. There were also times when we wanted to call one Lua script from another, which Redis didn't support (there was an undocumented workaround, but it made debugging a pain). So, we wrote a preprocessor that would replace require() calls with the actual content of the file it was requiring and create generated Lua files that could be read and loaded into the Redis server.

However, as our Lua scripts got more complex, we wanted a more maintainable way to write them. We turned to Teal (https://github.com/teal-language/tl), a dialect of Lua that adds static types while still compiling to Lua (similar to TypeScript for JavaScript). Teal worked beautifully, and we now write our Lua scripts using Teal, compile them into Lua, and preprocess them using our custom preprocessor.

For us, while Lua may not be the most powerful language, it has served us beautifully for writing Redis scripts, especially in combination with Teal.

2 upvotes·32.4K views
Avatar of Leon Si

Leon Si

CTO at Orbulo