2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.storage;
|
2020-10-27 20:12:38 +00:00
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.Plex;
|
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;
|
|
|
|
import redis.clients.jedis.JedisPool;
|
|
|
|
|
2022-02-04 08:18:07 +00:00
|
|
|
public class RedisConnection extends PlexBase
|
2020-10-27 20:12:38 +00:00
|
|
|
{
|
|
|
|
private JedisPool pool;
|
|
|
|
private Jedis jedis;
|
|
|
|
|
|
|
|
public JedisPool openPool()
|
|
|
|
{
|
|
|
|
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
|
|
|
Thread.currentThread().setContextClassLoader(RedisConnection.class.getClassLoader());
|
2022-02-04 08:18:07 +00:00
|
|
|
this.pool = new JedisPool(plugin.config.getString("data.side.hostname"), Plex.get().getConfig().getInt("data.side.port"));
|
2020-10-27 20:12:38 +00:00
|
|
|
Thread.currentThread().setContextClassLoader(previous);
|
2022-02-04 08:18:07 +00:00
|
|
|
PlexLog.log("Connected to Redis!");
|
2020-10-27 20:12:38 +00:00
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Jedis getJedis()
|
|
|
|
{
|
|
|
|
this.jedis = pool.getResource();
|
2022-02-04 08:18:07 +00:00
|
|
|
if (plugin.config.getBoolean("data.side.auth"))
|
2020-10-27 20:12:38 +00:00
|
|
|
{
|
2022-02-04 08:18:07 +00:00
|
|
|
jedis.auth(plugin.config.getString("data.side.password"));
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
return jedis;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|