Last active
March 3, 2021 11:46
-
-
Save borbit/4739255 to your computer and use it in GitHub Desktop.
CAS implementation for Redis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LUA_GETS = | |
'return {' | |
+ 'redis.call(\'get\', KEYS[1]),' | |
+ 'redis.call(\'get\', KEYS[1]..\'_ver\')' | |
+ '}'; | |
var LUA_CAS = | |
'local ver = redis.call(\'get\', KEYS[1]..\'_ver\') ' | |
+ 'if not ver or ver == KEYS[3] ' | |
+ 'then ' | |
+ 'redis.call(\'incr\', KEYS[1]..\'_ver\') ' | |
+ 'return redis.call(\'set\', KEYS[1], KEYS[2]) ' | |
+ 'else ' | |
+ 'return redis.error_reply(\'LATE\') ' | |
+ 'end'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment