Lambda Store is a Redis compatible server implementation that is optimized and built for for serverless usecases. It doesn’t support all of the Redis commands yet. We started with the most used Redis commands and we are gradually implementing missing commands according to feedback from our users.
Lua scripting in Redis is a bit advanced but also powerful feature compared to simpler
string/list/set/zset/hashcommands. It allows combining multiple Redis commands and pure application specific logic into a single Lua script and execute it on the server atomically.
With the help of Lua scripts, it's possible to execute multiple dependent or conditional commands in a single call atomically. This is similar to
MULTI/EXEC case, but with a single Redis command. Also you can use to batch multiple commands in a single call to avoid extra network hops.
For instance, following script increments the value of a HASH field only if the field exists.
if redis.call("HEXISTS", KEYS, ARGV) == 1 then return redis.call("HINCR", KEYS, ARGV) else return nil end
Following is a more complex case, a capped queue implementation using Redis list;
local len=redis.call('llen',KEYS) local cap=tonumber(ARGV) -- return -1 if queue is full -- or cap will be exceeded with given ARGS if len >= cap then return -1 elseif len + #ARGV - 1 > cap then return -1 end -- otherwise push ARGS for i,k in ipairs(ARGV) do if i > 1 then len=redis.call('rpush',KEYS,k) end end return len
Libraries such as Redisson client or redis-semaphore provides lots of custom data structures and services on top of a Redis server using flexibility of Lua scripts. From now on you can use these libraries with Lambda Store.
There are also downsides of using Lua scripts.
eval/evalsha commands are blocking, so while an
eval command is being executed, no other commands can be executed. A slow Lua script can hog the command execution pipeline. To avoid that situation, initially we will be limiting max execution time of a Lua script to one second. We can revisit this limitation according to user feedback later.
Additionally we don't support
struct Lua libraries and
redis.debug functions yet.