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]
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
])
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
}