2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Use more efficient HMSET when possible.

This commit is contained in:
Tux 2015-06-22 04:00:25 -04:00
parent b21c02eca0
commit 4834b7826f
3 changed files with 12 additions and 7 deletions

View File

@ -75,12 +75,15 @@ public class RedisBungeeListener implements Listener {
plugin.getService().submit(new RedisCallable<Void>(plugin) { plugin.getService().submit(new RedisCallable<Void>(plugin) {
@Override @Override
protected Void call(Jedis jedis) { protected Void call(Jedis jedis) {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", event.getPlayer().getAddress().getAddress().getHostAddress());
playerData.put("proxy", RedisBungee.getConfiguration().getServerId());
Pipeline pipeline = jedis.pipelined(); Pipeline pipeline = jedis.pipelined();
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getPlayer().getUniqueId().toString()); pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getPlayer().getUniqueId().toString());
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", "0");
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), pipeline); plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), pipeline);
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "proxy", RedisBungee.getConfiguration().getServerId()); pipeline.hmset("player:" + event.getPlayer().getUniqueId().toString(), playerData);
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>( pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN, event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress())))); new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));

View File

@ -30,6 +30,7 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline; import redis.clients.jedis.Pipeline;
class RedisUtil { class RedisUtil {
// Compatibility restraints prevent me from using using HDEL with multiple keys.
public static void cleanUpPlayer(String player, Jedis rsc) { public static void cleanUpPlayer(String player, Jedis rsc) {
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player); rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server"); rsc.hdel("player:" + player, "server");

View File

@ -27,6 +27,7 @@
package com.imaginarycode.minecraft.redisbungee.util; package com.imaginarycode.minecraft.redisbungee.util;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.imaginarycode.minecraft.redisbungee.RedisBungee; import com.imaginarycode.minecraft.redisbungee.RedisBungee;
import lombok.Getter; import lombok.Getter;
@ -200,14 +201,14 @@ public final class UUIDTranslator {
public final void persistInfo(String name, UUID uuid, Jedis jedis) { public final void persistInfo(String name, UUID uuid, Jedis jedis) {
addToMaps(name, uuid); addToMaps(name, uuid);
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid))); String json = RedisBungee.getGson().toJson(uuidToNameMap.get(uuid));
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid))); jedis.hmset("uuid-cache", ImmutableMap.of(name, json, uuid.toString(), json));
} }
public final void persistInfo(String name, UUID uuid, Pipeline jedis) { public final void persistInfo(String name, UUID uuid, Pipeline jedis) {
addToMaps(name, uuid); addToMaps(name, uuid);
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid))); String json = RedisBungee.getGson().toJson(uuidToNameMap.get(uuid));
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid))); jedis.hmset("uuid-cache", ImmutableMap.of(name, json, uuid.toString(), json));
} }
@RequiredArgsConstructor @RequiredArgsConstructor