Skip to content

Instantly share code, notes, and snippets.

@noogen
Last active April 19, 2017 20:57
Show Gist options
  • Save noogen/17ea36e67c5507e986e5 to your computer and use it in GitHub Desktop.
Save noogen/17ea36e67c5507e986e5 to your computer and use it in GitHub Desktop.
Redis get unique user identity by key
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