Convenience wrapper for Redis EVAL/EVALSHA
This library provides a convenient wrapper for sending Lua scripts to a Redis server via
EVALSHA is a Redis command that takes advantage of Redis's Lua script caching. Once a Lua script has been sent to Redis via
SET SCRIPT, the script will be cached. You can use
EVALSHA to execute the same script by sending the SHA-1 hash of the script, rather than the body of the script itself.
A shavaluator object wraps a Redis client for executing Lua scripts. It will always attempt
EVALSHA first, falling back on
EVAL if the script has not yet been cached by the Redis server.
Shavaluator = require'shavaluator'// 1. Initialize a shavaluator with a Redis clientvar shavaluator = redis;// 2. Load a series of named Lua scripts into the shavaluator.shavaluatorloaddelequal: " \if redis.call('GET', KEYS) == ARGV then \return redis.call('DEL', KEYS[i]) \end \return 0 \";// 3. The 'delequal' script is now loaded into the shavaluator and bound// as a method. When you call this, the shavaluator will first attempt// an EVALSHA, and fall back onto EVAL.shavaluatordelequal keys: 'someKey' args: 'deleteMe' ;