diff --git a/zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java b/zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java index 97cfe0b9..8bb9cf2e 100644 --- a/zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java +++ b/zheng-common/src/main/java/com/zheng/common/util/RedisUtil.java @@ -107,18 +107,13 @@ public class RedisUtil { * @param value */ public synchronized static void set(String key, String value) { - Jedis jedis = null; try { value = StringUtils.isBlank(value) ? "" : value; - jedis = getJedis(); + Jedis jedis = getJedis(); jedis.set(key, value); - + jedis.close(); } catch (Exception e) { _log.error("Set key error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } } } @@ -128,17 +123,12 @@ public class RedisUtil { * @param value */ public synchronized static void set(byte[] key, byte[] value) { - Jedis jedis = null; try { - jedis = getJedis(); + Jedis jedis = getJedis(); jedis.set(key, value); - + jedis.close(); } catch (Exception e) { _log.error("Set key error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } } } @@ -149,18 +139,13 @@ public class RedisUtil { * @param seconds 以秒为单位 */ public synchronized static void set(String key, String value, int seconds) { - Jedis jedis = null; try { value = StringUtils.isBlank(value) ? "" : value; - jedis = getJedis(); + Jedis jedis = getJedis(); jedis.setex(key, seconds, value); - + jedis.close(); } catch (Exception e) { _log.error("Set keyex error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } } } @@ -171,18 +156,13 @@ public class RedisUtil { * @param seconds 以秒为单位 */ public synchronized static void set(byte[] key, byte[] value, int seconds) { - Jedis jedis = null; try { - jedis = getJedis(); + Jedis jedis = getJedis(); jedis.set(key, value); jedis.expire(key, seconds); - + jedis.close(); } catch (Exception e) { _log.error("Set key error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } } } @@ -192,22 +172,12 @@ public class RedisUtil { * @return value */ public synchronized static String get(String key) { - Jedis jedis = null; - String value = null; - try { - jedis = getJedis(); - if (null == jedis) { - return null; - } - value = jedis.get(key); - - } catch (Exception e) { - _log.error("Get value error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } + Jedis jedis = getJedis(); + if (null == jedis) { + return null; } + String value = jedis.get(key); + jedis.close(); return value; } @@ -217,24 +187,12 @@ public class RedisUtil { * @return value */ public synchronized static byte[] get(byte[] key) { - Jedis jedis = null; - byte[] value = null; - - try { - jedis = getJedis(); - if (null == jedis) { - return null; - } - value = jedis.get(key); - - } catch (Exception e) { - _log.error("Get byte value error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } + Jedis jedis = getJedis(); + if (null == jedis) { + return null; } - + byte[] value = jedis.get(key); + jedis.close(); return value; } @@ -243,17 +201,12 @@ public class RedisUtil { * @param key */ public synchronized static void remove(String key) { - Jedis jedis = null; try { - jedis = getJedis(); + Jedis jedis = getJedis(); jedis.del(key); - + jedis.close(); } catch (Exception e) { - _log.error("Remove string key error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } + _log.error("Remove keyex error : " + e); } } @@ -262,17 +215,12 @@ public class RedisUtil { * @param key */ public synchronized static void remove(byte[] key) { - Jedis jedis = null; try { - jedis = getJedis(); + Jedis jedis = getJedis(); jedis.del(key); - + jedis.close(); } catch (Exception e) { - _log.error("Remove byte[] key error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } + _log.error("Remove keyex error : " + e); } } @@ -282,17 +230,12 @@ public class RedisUtil { * @param key */ public synchronized static void lpush(String key, String... strings) { - Jedis jedis = null; try { - jedis = RedisUtil.getJedis(); + Jedis jedis = RedisUtil.getJedis(); jedis.lpush(key, strings); - + jedis.close(); } catch (Exception e) { _log.error("lpush error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } } } @@ -303,17 +246,12 @@ public class RedisUtil { * @param value */ public synchronized static void lrem(String key, long count, String value) { - Jedis jedis = null; try { - jedis = RedisUtil.getJedis(); + Jedis jedis = RedisUtil.getJedis(); jedis.lrem(key, count, value); - + jedis.close(); } catch (Exception e) { - _log.error("lrem error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } + _log.error("lpush error : " + e); } } @@ -324,19 +262,14 @@ public class RedisUtil { * @param seconds */ public synchronized static void sadd(String key, String value, int seconds) { - Jedis jedis = null; try { - jedis = RedisUtil.getJedis(); + Jedis jedis = RedisUtil.getJedis(); jedis.sadd(key, value); jedis.expire(key, seconds); jedis.close(); } catch (Exception e) { _log.error("sadd error : " + e); - } finally { - if(jedis != null) { - jedis.close(); - } } } -} +} \ No newline at end of file