This commit is contained in:
shuzheng 2017-05-28 23:55:41 +08:00
parent bebee52316
commit 99eb0a690b
1 changed files with 31 additions and 98 deletions

View File

@ -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,18 +262,13 @@ 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();
}
}
}