Created
October 10, 2016 11:10
-
-
Save adrienmo/da3a2b369646395952f7ad0e19e43123 to your computer and use it in GitHub Desktop.
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
-- This script allow you to get an incremented unique integer id from a string | |
-- EVAL "SCRIPT" 1 key member1 -> return 1 | |
-- EVAL "SCRIPT" 1 key member2 -> return 2 | |
-- EVAL "SCRIPT" 1 key member1 -> return 1 | |
-- EVAL "SCRIPT" 1 key member3 -> return 3 | |
local nb_keys = redis.call('zcard', KEYS[1]); | |
local score = redis.call('zscore', KEYS[1], ARGV[1]); | |
if score then | |
return tonumber(score); | |
else | |
redis.call('zadd',KEYS[1], nb_keys + 1, ARGV[1]); | |
return nb_keys + 1; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment