Last active
April 19, 2017 20:57
-
-
Save noogen/17ea36e67c5507e986e5 to your computer and use it in GitHub Desktop.
Redis get unique user identity by key
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
local appPrefix = ARGV[1] | |
local userId = KEYS[1] | |
if not appPrefix then | |
appPrefix = "trak" | |
end | |
if not userId then | |
return "error: userId/keys[1] is required" | |
end | |
local ukey = appPrefix .. "::users::" .. userId | |
local uid = redis.call("GET", ukey) | |
if not uid then | |
uid = redis.call("INCR", appPrefix .. "::identity::users") | |
redis.call("SET", ukey, uid) | |
end | |
return uid .. "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment