|
@@ -17,12 +17,16 @@
|
|
|
|
|
|
package org.maxkey.persistence.redis;
|
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
import redis.clients.jedis.JedisPool;
|
|
|
import redis.clients.jedis.JedisPoolConfig;
|
|
|
|
|
|
public class RedisConnectionFactory {
|
|
|
-
|
|
|
+ private static final Logger _logger = LoggerFactory.getLogger(RedisConnectionFactory.class);
|
|
|
+
|
|
|
public static class DEFAULT_CONFIG {
|
|
|
/**
|
|
|
* Redis默认服务器IP
|
|
@@ -79,6 +83,7 @@ public class RedisConnectionFactory {
|
|
|
|
|
|
public void initConnectionFactory() {
|
|
|
if (jedisPool == null) {
|
|
|
+ _logger.debug("init Jedis Pool .");
|
|
|
try {
|
|
|
if (this.hostName == null || hostName.equals("")) {
|
|
|
hostName = DEFAULT_CONFIG.DEFAULT_ADDRESS;
|
|
@@ -94,26 +99,35 @@ public class RedisConnectionFactory {
|
|
|
this.password = null;
|
|
|
}
|
|
|
jedisPool = new JedisPool(poolConfig, hostName, port, timeOut, password);
|
|
|
-
|
|
|
+ _logger.debug("init Jedis Pool successful .");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ _logger.error("Exception", e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public synchronized RedisConnection getConnection() {
|
|
|
initConnectionFactory();
|
|
|
+ _logger.trace("get connection .");
|
|
|
RedisConnection redisConnection = new RedisConnection(this);
|
|
|
+ _logger.trace("return connection .");
|
|
|
return redisConnection;
|
|
|
}
|
|
|
|
|
|
public Jedis open() {
|
|
|
- return jedisPool.getResource();
|
|
|
+ _logger.trace("get jedisPool Resource ...");
|
|
|
+ Jedis jedis = jedisPool.getResource();
|
|
|
+ _logger.trace("return jedisPool Resource .");
|
|
|
+ return jedis;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void close(Jedis conn) {
|
|
|
// jedisPool.returnResource(conn);
|
|
|
+ _logger.trace("close conn .");
|
|
|
conn.close();
|
|
|
+ _logger.trace("closed conn .");
|
|
|
}
|
|
|
|
|
|
|