Skip to content

Instantly share code, notes, and snippets.

@banker
Created July 3, 2019 14:48
Show Gist options
  • Save banker/3dbed95c79bab81aef30da0e87063860 to your computer and use it in GitHub Desktop.
Save banker/3dbed95c79bab81aef30da0e87063860 to your computer and use it in GitHub Desktop.
public static String script = "" +
"local key = KEYS[1]" +
"local field = ARGV[1]" +
"local value = ARGV[2]" +
"local op = ARGV[3]" +
"local current = redis.call('hget', key, field)" +
"if (current == null) then " +
" redis.call('hset', key, field, value)" +
"elseif op == '>' then" +
" if tonumber(value) > tonumber(current) then" +
" redis.call('hset', key, field, value)" +
" end " +
"elseif op == '<' then" +
" if tonumber(value) < tonumber(current) then" +
" redis.call('hset', key, field, value)" +
" end " +
"end ";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment