Very self explanatory title, this beauty it's a Lua
script running inside Redis
interpreter, it will basically grap the ttl
from the passed key
if exist (ttl > 0
) and use it which means that we are overriding the key
or if not will just setex
the key
with the passed data
and ttl
.
red:eval("local ttl = redis.call('ttl', ARGV[1]) if ttl > 0 then return redis.call('SETEX', ARGV[1], ttl, ARGV[2]) else return redis.call('SETEX', ARGV[1], ARGV[3], ARGV[2]) end", 0, key, data, ttl)
Since version 2.6.0 Redis have embebed on it's intrepreter Lua, so we can write Lua scripts that could be interpreted by Redis as shown above
Resources
Some usefull links: