log trace
This commit is contained in:
@@ -79,11 +79,13 @@ public class RedisConnection {
|
||||
* @param value
|
||||
*/
|
||||
public void setex(String key,long seconds, String value){
|
||||
_logger.trace("setex key {} ..." , key);
|
||||
if(seconds==0){
|
||||
conn.setex(key, RedisConnectionFactory.DEFAULT_CONFIG.DEFAULT_LIFETIME, value);
|
||||
}else{
|
||||
conn.setex(key, seconds, value);
|
||||
}
|
||||
_logger.trace("setex successful .");
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +94,7 @@ public class RedisConnection {
|
||||
* @return String
|
||||
*/
|
||||
public String get(String key){
|
||||
_logger.trace("get key {} ..." , key);
|
||||
String value = null;
|
||||
if(key != null){
|
||||
value = conn.get(key);
|
||||
@@ -115,16 +118,19 @@ public class RedisConnection {
|
||||
}
|
||||
|
||||
public void expire(String key,long seconds){
|
||||
_logger.trace("expire key {} , {}" , key , seconds);
|
||||
conn.expire(key, seconds);
|
||||
}
|
||||
|
||||
public void delete(String key){
|
||||
_logger.trace("del key {}" , key);
|
||||
conn.del(key);
|
||||
}
|
||||
|
||||
public void rPush(String key, Serializable object){
|
||||
conn.rpush(key, ObjectTransformer.serialize(object));
|
||||
}
|
||||
|
||||
public long lRem(String key,int count,String value){
|
||||
return conn.lrem(key, count, value);
|
||||
}
|
||||
|
||||
@@ -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 .");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user