2022-07-16 12:50:09 +00:00
|
|
|
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
2022-04-14 10:12:47 +00:00
|
|
|
|
|
|
|
import redis.clients.jedis.Jedis;
|
2022-04-14 10:34:56 +00:00
|
|
|
import redis.clients.jedis.JedisPool;
|
2022-07-26 13:47:18 +00:00
|
|
|
import redis.clients.jedis.JedisPooled;
|
2022-04-14 10:12:47 +00:00
|
|
|
|
2022-07-16 05:18:33 +00:00
|
|
|
import java.io.IOException;
|
2022-07-06 19:04:09 +00:00
|
|
|
|
2022-07-26 13:47:18 +00:00
|
|
|
public class JedisPooledSummoner implements Summoner<JedisPooled> {
|
2022-04-14 10:12:47 +00:00
|
|
|
|
2022-07-26 13:47:18 +00:00
|
|
|
private final JedisPooled jedisPooled;
|
2022-07-16 05:18:33 +00:00
|
|
|
private final JedisPool jedisPool;
|
2022-04-14 10:12:47 +00:00
|
|
|
|
2022-07-26 13:47:18 +00:00
|
|
|
public JedisPooledSummoner(JedisPooled jedisPooled, JedisPool jedisPool) {
|
|
|
|
this.jedisPooled = jedisPooled;
|
2022-07-16 05:18:33 +00:00
|
|
|
this.jedisPool = jedisPool;
|
2022-07-17 01:25:50 +00:00
|
|
|
try (Jedis jedis = this.jedisPool.getResource()) {
|
|
|
|
// Test the connection to make sure configuration is right
|
|
|
|
jedis.ping();
|
|
|
|
}
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
2022-04-14 10:12:47 +00:00
|
|
|
|
2022-07-16 05:18:33 +00:00
|
|
|
@Override
|
2022-07-26 13:47:18 +00:00
|
|
|
public JedisPooled obtainResource() {
|
|
|
|
return this.jedisPooled;
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
2022-04-14 10:12:47 +00:00
|
|
|
|
2022-07-26 13:47:18 +00:00
|
|
|
public JedisPool getCompatibilityJedisPool() {
|
2022-07-16 05:18:33 +00:00
|
|
|
return this.jedisPool;
|
|
|
|
}
|
2022-07-15 22:58:48 +00:00
|
|
|
|
2022-07-16 05:18:33 +00:00
|
|
|
@Override
|
|
|
|
public void close() throws IOException {
|
|
|
|
this.jedisPool.close();
|
2022-07-26 13:47:18 +00:00
|
|
|
this.jedisPooled.close();
|
2022-07-16 05:18:33 +00:00
|
|
|
|
|
|
|
}
|
2022-04-14 10:12:47 +00:00
|
|
|
}
|