com.gc.easy.redis.util.RedisUtil Maven / Gradle / Ivy
The newest version!
package com.gc.easy.redis.util;
import org.redisson.api.*;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@Component
public class RedisUtil {
private final RedissonClient redissonClient;
public RedisUtil(RedissonClient redissonClient) {
this.redissonClient = redissonClient;
}
public Long increment(String key) {
RAtomicLong atomicLong = redissonClient.getAtomicLong(key);
return atomicLong.incrementAndGet();
}
public Long decrement(String key) {
RAtomicLong atomicLong = redissonClient.getAtomicLong(key);
return atomicLong.decrementAndGet();
}
/**
* 发布订阅的消息
* @param topic
* @param message
*/
public void pushSubscriberMessage(String topic,String message) {
RTopic rtopic = redissonClient.getTopic(topic);
rtopic.publish(message);
}
/**
* 发布消息队列
* @param topic
* @param message
*/
public void pushQueueMessage(String topic,String message) {
RBlockingQueue queue = redissonClient.getBlockingQueue(topic);
queue.offer(message);
}
public T get(String key, Class clazz) {
RBucket bucket = redissonClient.getBucket(key);
return bucket.get();
}
public boolean set(String key, Object value) {
RBucket
© 2015 - 2025 Weber Informatics LLC | Privacy Policy