com.github.ciweigg.operation.RedissonObject Maven / Gradle / Ivy
package com.github.ciweigg.operation;
import com.github.ciweigg.properties.RedissonProperties;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* 操作对象
*/
public class RedissonObject {
@Resource
private RedissonClient redissonClient;
@Resource
private RedissonProperties redissonProperties;
/**
* 获取对象值
*
* @param name 缓存名
* @return T
*/
public T getValue(String name) {
RBucket bucket = redissonClient.getBucket(name);
return bucket.get();
}
/**
* 获取对象空间
*
* @param name 缓存名
* @return RBucket
*/
public RBucket getBucket(String name) {
return redissonClient.getBucket(name);
}
/**
* 设置对象的值
*
* @param name 键
* @param value 值
*/
public void setValue(String name, T value) {
setValue(name,value,redissonProperties.getDataValidTime());
}
/**
* 设置对象的值
*
* @param name 键
* @param value 值
* @param time 缓存时间 单位毫秒 -1 永久缓存
*/
public void setValue(String name, T value, Long time) {
RBucket
© 2015 - 2025 Weber Informatics LLC | Privacy Policy