Created
March 24, 2013 22:10
-
-
Save arthurtsang/5233778 to your computer and use it in GitHub Desktop.
LUA script to update a list & a hash cache together
This file contains 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
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