Module: Redlock::Scripts
- Included in:
- Redlock
- Defined in:
- lib/redlock/scripts.rb
Constant Summary collapse
- UNLOCK_SCRIPT =
" if redis.call(\"get\",KEYS[1]) == ARGV[1] then\n return redis.call(\"del\",KEYS[1])\n else\n return 0\n end\n"- LOCK_SCRIPT =
thanks to github.com/sbertrang/redis-distlock/blob/master/lib/Redis/DistLock.pm also github.com/sbertrang/redis-distlock/issues/2 which proposes the value-checking and @maltoe for github.com/leandromoreira/redlock-rb/pull/20#discussion_r38903633
" if (redis.call(\"exists\", KEYS[1]) == 0 and ARGV[3] == \"yes\") or redis.call(\"get\", KEYS[1]) == ARGV[1] then\n return redis.call(\"set\", KEYS[1], ARGV[1], \"PX\", ARGV[2])\n end\n"- PTTL_SCRIPT =
" return { redis.call(\"get\", KEYS[1]), redis.call(\"pttl\", KEYS[1]) }\n"- UNLOCK_SCRIPT_SHA =
We do not want to load the scripts on every Redlock::Client initialization. Hence, we rely on Redis handing out SHA1 hashes of the cached scripts and pre-calculate them instead of loading the scripts unconditionally. If the scripts have not been cached on Redis, ‘recover_from_script_flush` has our backs.
Digest::SHA1.hexdigest(UNLOCK_SCRIPT)
- LOCK_SCRIPT_SHA =
Digest::SHA1.hexdigest(LOCK_SCRIPT)
- PTTL_SCRIPT_SHA =
Digest::SHA1.hexdigest(PTTL_SCRIPT)