2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2025-07-10 06:48:02 +00:00
RedisBungee/src/main/resources/lua/server_to_players.lua
Tux 8b5eacec40 Introduce a set of performance tweaks.
The most notable changes are a refactor of DataManager to make the caching system easier to tweak, and the ability to use Lua scripts that run on the Redis server to optimize certain batch operations (currently, only getServersToPlayers() uses this).

This also paves the way for me to deprecate old versions of Redis. Anything older than 2.6 is ancient, and even 2.6 is ancient, so it ends up being a net overall benefit.
2015-06-21 17:32:28 -04:00

20 lines
681 B
Lua

-- This script needs all active proxies available specified as args.
local serverToData = {}
for _, proxy in ipairs(ARGV) do
local players = redis.call("SMEMBERS", "proxy:" .. proxy .. ":usersOnline")
for _, player in ipairs(players) do
local server = redis.call("HGET", "player:" .. player, "server")
if server then
if serverToData[server] then
local data = serverToData[server]
data[#data + 1] = player
else
serverToData[server] = {player}
end
end
end
end
-- Redis can't map a Lua table back, so we have to send it as JSON.
return cjson.encode(serverToData)