2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.storage;
|
2020-10-27 20:12:38 +00:00
|
|
|
|
2022-02-04 08:18:07 +00:00
|
|
|
import dev.plex.PlexBase;
|
|
|
|
import dev.plex.util.PlexLog;
|
2020-10-27 20:12:38 +00:00
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
|
2022-02-28 06:28:00 +00:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
2022-02-04 08:18:07 +00:00
|
|
|
public class RedisConnection extends PlexBase
|
2020-10-27 20:12:38 +00:00
|
|
|
{
|
|
|
|
private Jedis jedis;
|
|
|
|
|
2022-02-04 19:30:05 +00:00
|
|
|
public Jedis getJedis()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
jedis = new Jedis(plugin.config.getString("data.side.hostname"),
|
|
|
|
plugin.config.getInt("data.side.port"));
|
|
|
|
if (plugin.config.getBoolean("data.side.auth"))
|
|
|
|
{
|
|
|
|
jedis.auth(plugin.config.getString("data.side.password"));
|
|
|
|
}
|
|
|
|
return jedis;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
PlexLog.error("An error occurred with Redis.");
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
return jedis;
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 06:28:00 +00:00
|
|
|
public void runAsync(Consumer<Jedis> jedisConsumer)
|
|
|
|
{
|
|
|
|
new Thread(() -> {
|
|
|
|
try (Jedis jedis = getJedis())
|
|
|
|
{
|
|
|
|
jedisConsumer.accept(jedis);
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
2022-02-04 08:18:07 +00:00
|
|
|
public final boolean isEnabled()
|
|
|
|
{
|
|
|
|
return plugin.config.getBoolean("data.side.enabled");
|
|
|
|
}
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|