Use a try-with-resources for gem hunters redis calls
This commit is contained in:
parent
b314744b6d
commit
ce6ee670ed
@ -6,6 +6,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.redis.RedisRepository;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
public class QuitNPCRepository extends RedisRepository
|
||||
{
|
||||
@ -18,16 +19,34 @@ public class QuitNPCRepository extends RedisRepository
|
||||
|
||||
public CompletableFuture<String> loadNpcServer(UUID uuid)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> getResource(false).get(getKey(REDIS_KEY_PREFIX + uuid.toString())));
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
try (Jedis jedis = getResource(false))
|
||||
{
|
||||
return getResource(false).get(getKey(REDIS_KEY_PREFIX + uuid.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteNpc(UUID uuid)
|
||||
{
|
||||
UtilServer.runAsync(() -> getResource(true).del(getKey(REDIS_KEY_PREFIX + uuid.toString())));
|
||||
UtilServer.runAsync(() ->
|
||||
{
|
||||
try (Jedis jedis = getResource(true))
|
||||
{
|
||||
jedis.del(getKey(REDIS_KEY_PREFIX + uuid.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void insertNpc(UUID uuid, String serverName)
|
||||
{
|
||||
UtilServer.runAsync(() -> getResource(true).setex(REDIS_KEY_PREFIX + uuid.toString(), 60, serverName));
|
||||
UtilServer.runAsync(() ->
|
||||
{
|
||||
try (Jedis jedis = getResource(true))
|
||||
{
|
||||
jedis.setex(REDIS_KEY_PREFIX + uuid.toString(), 60, serverName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user