Skip to content

Instantly share code, notes, and snippets.

@arthurtsang
Created March 24, 2013 22:10
Show Gist options
  • Save arthurtsang/5233778 to your computer and use it in GitHub Desktop.
Save arthurtsang/5233778 to your computer and use it in GitHub Desktop.
LUA script to update a list & a hash cache together
protected static final String UPDATE_OHASH_SCRIPT =
"local listkey = KEYS[1];" +
"local hashkey = KEYS[2];" +
"local id = ARGV[1];" +
"local item = ARGV[2];" +
"local found = false;" +
"local ids = redis.call('lrange', listkey, 0, -1 );" +
"for i = 1,#ids do " +
"if id == ids[i] then " +
"found = true;" +
"break; " +
"end " +
"end " +
"if not found then " +
"redis.call('rpush', listkey, id );" +
"end " +
"redis.call('hset', hashkey, id, item );";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment