Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / modules / presence / redis-lua / presence-categorize-users.lua
blob3c9f8991e42a97cc03aefa7b7dae38b4ce5caafc
1 local key_working_set = KEYS[1];
2 local key_working_output_set = KEYS[2];
3 local key_active_users = KEYS[3]
4 local key_mobile_users = KEYS[4]
6 local user_ids = ARGV;
8 -- create a temporary set of all the user ids that we want to categorize
9 for i, name in ipairs(user_ids) do
10 redis.call("ZADD", key_working_set, 1, user_ids[i])
11 end
13 -- store all the users that are in both the active users set and our temp query set in an output set
14 redis.call("ZINTERSTORE", key_working_output_set, 2, key_active_users, key_working_set)
16 -- get all the user ids from the temp output set
17 local online_user_ids = redis.call("ZRANGEBYSCORE", key_working_output_set, 1, '+inf')
19 -- delete the temporary sets
20 redis.call("DEL", key_working_output_set)
22 -- store all the users that are in both the active users set and our temp query set in an output set
23 redis.call("ZINTERSTORE", key_working_output_set, 2, key_mobile_users, key_working_set)
25 -- get all the user ids from the temp output set
26 local mobile_user_ids = redis.call("ZRANGEBYSCORE", key_working_output_set, 1, '+inf')
29 redis.call("DEL", key_working_set, key_working_output_set)
31 return { online_user_ids, mobile_user_ids }