兴安访客小程序访客改造
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
package com.dcsoft.common.redis.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
@@ -13,18 +9,24 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* spring redis 工具类
|
||||
*
|
||||
*
|
||||
* @author dcsoft
|
||||
**/
|
||||
@SuppressWarnings(value = { "unchecked", "rawtypes" })
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisService
|
||||
{
|
||||
@Autowired
|
||||
public RedisTemplate redisTemplate;
|
||||
|
||||
private static final long DEFAULT_TIMEOUT = 60 * 60 * 24 * 7;
|
||||
|
||||
/**
|
||||
* 缓存基本的对象,Integer、String、实体类等
|
||||
*
|
||||
@@ -36,6 +38,43 @@ public class RedisService
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存是否存在,存在返回false,不存在返回true并存储缓存值
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public Boolean setIfAbsent(final String key, final String value, long timeout, TimeUnit timeUnit)
|
||||
{
|
||||
try {
|
||||
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
|
||||
} catch (Exception e) {
|
||||
log.error("redis error:{}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分布式加锁
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public Boolean lock(final String key, final String value, long timeout, TimeUnit timeUnit)
|
||||
{
|
||||
try {
|
||||
if (timeout <= 0) {
|
||||
timeout = DEFAULT_TIMEOUT;
|
||||
timeUnit = TimeUnit.SECONDS;
|
||||
}
|
||||
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
|
||||
} catch (Exception e) {
|
||||
log.error("redis error:{}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存基本的对象,Integer、String、实体类等
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user