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

68 lines
1.9 KiB
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.storage;
import dev.plex.PlexBase;
import dev.plex.util.PlexLog;
import redis.clients.jedis.Jedis;
public class RedisConnection extends PlexBase
{
private Jedis jedis;
2022-02-04 19:30:05 +00:00
/*public JedisPool openPool()
{
2022-02-04 19:30:05 +00:00
JedisPoolConfig jedisConfig = new JedisPoolConfig();
//jedisConfig.setMaxIdle(10);
//jedisConfig.setMaxTotal(100);
ClassLoader previous = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(RedisConnection.class.getClassLoader());
2022-02-04 19:30:05 +00:00
this.pool = new JedisPool(jedisConfig, plugin.config.getString("data.side.hostname"),
plugin.config.getInt("data.side.port"));
Thread.currentThread().setContextClassLoader(previous);
PlexLog.log("Connected to Redis!");
return pool;
}
public Jedis getJedis()
{
2022-02-04 19:30:05 +00:00
try
{
this.jedis = pool.getResource();
}
catch (Exception ex)
{
PlexLog.error("An error occurred with Redis.");
ex.printStackTrace();
}
if (plugin.config.getBoolean("data.side.auth"))
{
jedis.auth(plugin.config.getString("data.side.password"));
}
return 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;
}
public final boolean isEnabled()
{
return plugin.config.getBoolean("data.side.enabled");
}
}