add 增加 RedisUtils 操作原子值方法

This commit is contained in:
疯狂的狮子li 2022-05-05 15:07:23 +08:00
parent 4941aaa5c1
commit b01d45cf5c

View File

@ -364,6 +364,50 @@ public class RedisUtils {
return rMap.getAll(hKeys); return rMap.getAll(hKeys);
} }
/**
* 设置原子值
*
* @param key Redis键
* @param value
*/
public static void setAtomicValue(String key, long value) {
RAtomicLong atomic = CLIENT.getAtomicLong(key);
atomic.set(value);
}
/**
* 获取原子值
*
* @param key Redis键
* @return 当前值
*/
public static long getAtomicValue(String key) {
RAtomicLong atomic = CLIENT.getAtomicLong(key);
return atomic.get();
}
/**
* 递增原子值
*
* @param key Redis键
* @return 当前值
*/
public static long incrAtomicValue(String key) {
RAtomicLong atomic = CLIENT.getAtomicLong(key);
return atomic.incrementAndGet();
}
/**
* 递减原子值
*
* @param key Redis键
* @return 当前值
*/
public static long decrAtomicValue(String key) {
RAtomicLong atomic = CLIENT.getAtomicLong(key);
return atomic.decrementAndGet();
}
/** /**
* 获得缓存的基本对象列表 * 获得缓存的基本对象列表
* *