Plex/src/main/java/dev/plex/storage/RedisConnection.java

40 lines
1.2 KiB
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.storage;
2021-01-03 07:21:15 +00:00
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.util.PlexLog;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
2022-02-04 18:51:16 +00:00
import redis.clients.jedis.JedisPoolConfig;
public class RedisConnection extends PlexBase
{
private JedisPool pool;
private Jedis jedis;
public JedisPool openPool()
{
ClassLoader previous = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(RedisConnection.class.getClassLoader());
2022-02-04 18:51:16 +00:00
this.pool = new JedisPool(new JedisPoolConfig(), plugin.config.getString("data.side.hostname"), Plex.get().getConfig().getInt("data.side.port"));
Thread.currentThread().setContextClassLoader(previous);
PlexLog.log("Connected to Redis!");
return pool;
}
public Jedis getJedis()
{
this.jedis = pool.getResource();
if (plugin.config.getBoolean("data.side.auth"))
{
jedis.auth(plugin.config.getString("data.side.password"));
}
return jedis;
}
public final boolean isEnabled()
{
return plugin.config.getBoolean("data.side.enabled");
}
}