There's only one way (currently) to invoke Lua scripts in Redis, and that's by explicitly rubbing them using EVAL (or EVALSHA) - no tricks nor trigger-like/time-based manners. This means that your first example is solvable only with a client application that periodically updates the relevant key.
As for your second example, Lua can definitely help with that. Instead of directly calling INCRBY to do the decrement, call a script that wraps it and the logic (if + DEL). That script would probably look something like:
if redis.call('INCRBY', KEYS[1], -1) == 0) then redis.call('DEL', KEYS[1]) end
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Edits:
^rubbing^running
Extra unneeded closing parenthesis in snippet, should be:
if redis.call('INCRBY', KEYS[1], -1) == 0 then redis.call('DEL', KEYS[1]) end