update 更新 RedisUtils 增加 注册监听器方法

master
疯狂的狮子li 4 years ago
parent 1445d6d24a
commit bcbc7c1d47

@ -94,8 +94,8 @@ public class RedisUtils {
/** /**
* TTL * TTL
* *
* @param key * @param key
* @param value * @param value
* @param isSaveTtl TTL(: setttl90 set90) * @param isSaveTtl TTL(: setttl90 set90)
* @since Redis 6.X 使 setAndKeepTTL 5.X * @since Redis 6.X 使 setAndKeepTTL 5.X
*/ */
@ -128,6 +128,19 @@ public class RedisUtils {
result.expire(timeout, timeUnit); result.expire(timeout, timeUnit);
} }
/**
*
*
* key `notify-keyspace-events` redis
*
* @param key
* @param listener
*/
public static <T> void addObjectListener(final String key, final ObjectListener listener) {
RBucket<T> result = CLIENT.getBucket(key);
result.addListener(listener);
}
/** /**
* *
* *
@ -177,19 +190,16 @@ public class RedisUtils {
/** /**
* *
* *
* @param key * @param key
*/ */
public static boolean deleteObject(final String key) { public static boolean deleteObject(final String key) {
return CLIENT.getBucket(key).delete(); return CLIENT.getBucket(key).delete();
} }
/* */
/** /**
* *
* *
* @param collection * @param collection
* @return
*/ */
public static void deleteObject(final Collection collection) { public static void deleteObject(final Collection collection) {
RBatch batch = CLIENT.createBatch(); RBatch batch = CLIENT.createBatch();
@ -211,6 +221,19 @@ public class RedisUtils {
return rList.addAll(dataList); return rList.addAll(dataList);
} }
/**
* List
*
* key `notify-keyspace-events` redis
*
* @param key
* @param listener
*/
public static <T> void addListListener(final String key, final ObjectListener listener) {
RList<T> rList = CLIENT.getList(key);
rList.addListener(listener);
}
/** /**
* list * list
* *
@ -234,11 +257,24 @@ public class RedisUtils {
return rSet.addAll(dataSet); return rSet.addAll(dataSet);
} }
/**
* Set
*
* key `notify-keyspace-events` redis
*
* @param key
* @param listener
*/
public static <T> void addSetListener(final String key, final ObjectListener listener) {
RSet<T> rSet = CLIENT.getSet(key);
rSet.addListener(listener);
}
/** /**
* set * set
* *
* @param key * @param key key
* @return * @return set
*/ */
public static <T> Set<T> getCacheSet(final String key) { public static <T> Set<T> getCacheSet(final String key) {
RSet<T> rSet = CLIENT.getSet(key); RSet<T> rSet = CLIENT.getSet(key);
@ -248,8 +284,8 @@ public class RedisUtils {
/** /**
* Map * Map
* *
* @param key * @param key
* @param dataMap * @param dataMap
*/ */
public static <T> void setCacheMap(final String key, final Map<String, T> dataMap) { public static <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
if (dataMap != null) { if (dataMap != null) {
@ -258,11 +294,24 @@ public class RedisUtils {
} }
} }
/**
* Map
*
* key `notify-keyspace-events` redis
*
* @param key
* @param listener
*/
public static <T> void addMapListener(final String key, final ObjectListener listener) {
RMap<String, T> rMap = CLIENT.getMap(key);
rMap.addListener(listener);
}
/** /**
* Map * Map
* *
* @param key * @param key
* @return * @return map
*/ */
public static <T> Map<String, T> getCacheMap(final String key) { public static <T> Map<String, T> getCacheMap(final String key) {
RMap<String, T> rMap = CLIENT.getMap(key); RMap<String, T> rMap = CLIENT.getMap(key);

Loading…
Cancel
Save