mirror of
https://github.com/plexusorg/Plex.git
synced 2024-11-16 16:46:11 +00:00
48 lines
1.1 KiB
Java
48 lines
1.1 KiB
Java
package dev.plex.storage;
|
|
|
|
import dev.plex.PlexBase;
|
|
import dev.plex.util.PlexLog;
|
|
import java.util.function.Consumer;
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
public class RedisConnection implements PlexBase
|
|
{
|
|
private Jedis jedis;
|
|
|
|
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;
|
|
}
|
|
|
|
public void runAsync(Consumer<Jedis> jedisConsumer)
|
|
{
|
|
new Thread(() ->
|
|
{
|
|
try (Jedis jedis = getJedis())
|
|
{
|
|
jedisConsumer.accept(jedis);
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
public final boolean isEnabled()
|
|
{
|
|
return plugin.config.getBoolean("data.side.enabled");
|
|
}
|
|
}
|