Commit 2e351da5 by zhanghj

V1.1.0--把公用的redis相关类和获取配置类提取到common类中

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@19747 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent ff6c3009
Showing 27 changed files with 252 additions and 460 deletions
......@@ -31,6 +31,12 @@
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<!-- SpringBoot Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
......
package com.glsx.manager.config;
package com.glsx.common.config;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
......@@ -9,7 +9,6 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
*
* @Title RedisConfig.java
......
......@@ -92,4 +92,33 @@ public interface Constants {
public static final int USER_TYPE_MECHANIC = 3;
/**
* 缓存key
*/
public static final String WECHAT_TOKEN_KEY = "carservice:wechat:public:token";
public static final String WECHAT_TICKET_KEY = "carservice:wechat:public:ticket";
/**
* 微信公众号配置
*/
/**
* 包活干公众号appid
*/
public static final String WECHAT_BHG_PUBLIC_APPID = "wechat_bhg_public_appid";
/**
* 包活干公众号的appsecret
*/
public static final String WECHAT_BHG_PUBLIC_SECRET = "wechat_bhg_public_secret";
/**
* 微信小程序appid
*/
public static final String WECHAT_bhg_MINI_APPID = "wechat_bhg_mini_appid";
/**
* 微信跳转页面
*/
public static final String WECHAT_bhg_MINI_REPAY_PAGE_PATH = "wechat_bhg_mini_repay_page_path";
/**
* 微信推送还款公众号模板id
*/
public static final String WECHAT_bhg_REPAY_TEMPLATEID = "wechat_bhg_templateid";
}
......@@ -188,7 +188,7 @@ public class HttpUtils {
* @return
* @throws Exception
*/
public String get(String url, Map<String, String> params, int timeout, String charset) throws Exception {
public static String get(String url, Map<String, String> params, int timeout, String charset) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setIntParameter("http.socket.timeout", timeout * 1000);
httpclient.getParams().setBooleanParameter("http.protocol.expect-continue", false);
......@@ -275,8 +275,8 @@ public class HttpUtils {
* @throws Exception
*/
@SuppressWarnings("deprecation")
public String get(String url, Map<String, String> params) throws Exception {
return this.get(url, params, 10, HTTP.UTF_8);
public static String get(String url, Map<String, String> params) throws Exception {
return get(url, params, 10, HTTP.UTF_8);
}
/**
* get请求, 默认utf-8
......
package com.glsx.manager.utils;
package com.glsx.common.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
......
package com.glsx.publicservice.util;
package com.glsx.common.utils;
import java.util.ArrayList;
import java.util.Arrays;
......
/**
* Copyright (C), 2015-2018, 广联赛讯有限公司
* FileName: TemplateData
* Author: liuyf
* Date: 2018/5/15 23:13
* Description: 模板信息的每个属性信息
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.glsx.common.utils.wehcat;
/**
* 〈一句话功能简述〉<br>
* 〈模板信息的每个属性信息〉
*
* @author liuyf
* @create 2018/5/15
* @since 1.0.0
*/
public class TemplateData {
public TemplateData() {
}
public TemplateData(String value, String color) {
this.value = value;
this.color = color;
}
private String value;
private String color;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018, 广联赛讯有限公司
* FileName: UnifiedOrderModel
* Author: liuyf
* Date: 2018/5/17 13:59
* Description: 微信支付预订单Modle
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.glsx.common.utils.wehcat;
/**
* 〈一句话功能简述〉<br>
* 〈微信支付预订单Model〉
*
* @author liuyf
* @create 2018/5/17
* @since 1.0.0
*/
public class UnifiedOrderModel {
private String body;
private Integer totalFee;
private String loanNo;
private Integer repaymentPeriod;
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public Integer getTotalFee() {
return totalFee;
}
public void setTotalFee(Integer totalFee) {
this.totalFee = totalFee;
}
public String getLoanNo() {
return loanNo;
}
public void setLoanNo(String loanNo) {
this.loanNo = loanNo;
}
public Integer getRepaymentPeriod() {
return repaymentPeriod;
}
public void setRepaymentPeriod(Integer repaymentPeriod) {
this.repaymentPeriod = repaymentPeriod;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018, 广联赛讯有限公司
* FileName: WechatTemplate
* Author: liuyf
* Date: 2018/5/15 23:12
* Description: 模板消息Bean
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.glsx.common.utils.wehcat;
import java.util.Map;
/**
* 〈一句话功能简述〉<br>
* 〈模板消息Bean〉
*
* @author liuyf
* @create 2018/5/15
* @since 1.0.0
*/
public class WechatTemplate {
private String touser;
private String template_id;
private String url;
private String topcolor;
private Map<String, TemplateData> data;
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getTemplate_id() {
return template_id;
}
public void setTemplate_id(String template_id) {
this.template_id = template_id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTopcolor() {
return topcolor;
}
public void setTopcolor(String topcolor) {
this.topcolor = topcolor;
}
public Map<String, TemplateData> getData() {
return data;
}
public void setData(Map<String, TemplateData> data) {
this.data = data;
}
}
\ No newline at end of file
......@@ -38,10 +38,6 @@
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- EurekaClient -->
<dependency>
<groupId>org.springframework.cloud</groupId>
......
......@@ -21,11 +21,11 @@ import com.glsx.common.annotation.AuthCheck;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.MenuClient;
import com.glsx.common.utils.Page;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.common.utils.UserUtils;
import com.glsx.manager.constants.ResultCodeEnum;
import com.glsx.manager.pojo.Test;
import com.glsx.manager.service.TestService;
import com.glsx.manager.utils.PropertiesUtil;
@AuthCheck
@RestController
......
package com.glsx.ordercenter.config;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
*
* @Title RedisConfig.java
* @Package com.qurong.credit.sp.config
* @Description TODO 配置RedisTemplate的key,value的序列化策略,保持所有服务一直
* @author zhanghj
* @date 2018年8月20日 下午8:45:18
* @version
*/
@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedisConfig {
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
//设置redis,key,value序列化策略
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(redisSerializer);
//JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
redisTemplate.setValueSerializer(redisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
......@@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RestController;
import com.glsx.common.annotation.AuthCheck;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.Page;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.pojo.Test;
import com.glsx.ordercenter.service.TestService;
import com.glsx.ordercenter.utils.PropertiesUtil;
@AuthCheck
@RestController
......
package com.glsx.ordercenter.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.DateUtil;
import com.glsx.common.utils.HttpUtils;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.DeviceActiveModel;
import com.glsx.ordercenter.dto.DeviceInfo;
......@@ -12,16 +23,6 @@ import com.glsx.ordercenter.mapper.SysOrderMapper;
import com.glsx.ordercenter.pojo.SysOrder;
import com.glsx.ordercenter.pojo.SysOrderExample;
import com.glsx.ordercenter.service.StandardOrderService;
import com.glsx.ordercenter.utils.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @author duanht
......
package com.glsx.ordercenter.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
*
* @Title PropertiesUtil.java
* @Package com.glsx.manager.utils
* @Description TODO 读取配置文件属性值
* @author zhanghj
* @date 2018年12月24日 下午5:38:42
* @version 1.0.0
*/
@Component
public class PropertiesUtil {
private static Environment env;
@Autowired
public void setEnv(Environment env) {
PropertiesUtil.env = env;
}
public static String getProperty(String key){
return env.getProperty(key);
}
public static String getProperty(String key, String defaultVal){
return env.getProperty(key, defaultVal);
}
}
package com.glsx.publicservice.config;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
*
* @Title RedisConfig.java
* @Package com.qurong.credit.sp.config
* @Description TODO 配置RedisTemplate的key,value的序列化策略,保持所有服务一直
* @author zhanghj
* @date 2018年8月20日 下午8:45:18
* @version
*/
@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedisConfig {
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
//设置redis,key,value序列化策略
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(redisSerializer);
//JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
redisTemplate.setValueSerializer(redisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
......@@ -4,32 +4,29 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.HttpUtils;
import com.glsx.publicservice.constants.Constants;
import com.glsx.publicservice.util.PropertiesUtil;
import com.glsx.publicservice.util.RedisCacheUtil;
import com.glsx.publicservice.util.SmsUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.github.pagehelper.util.StringUtil;
import com.glsx.common.annotation.AuthCheck;
import com.glsx.common.constants.ResultCodeEnum;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.common.utils.RedisCacheUtil;
import com.glsx.publicservice.constants.Constants;
import com.glsx.publicservice.service.CommonService;
import com.glsx.publicservice.util.SmsUtil;
import com.glsx.publicservice.util.fastdfs.FastDFSClientWrapper;
/**
......
......@@ -4,18 +4,18 @@ import java.text.MessageFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import com.glsx.publicservice.util.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.common.utils.RedisCacheUtil;
import com.glsx.common.utils.StringUtils;
import com.glsx.publicservice.constants.Constants;
import com.glsx.publicservice.mapper.SMSLogMapper;
import com.glsx.publicservice.pojo.SMSLog;
import com.glsx.publicservice.service.CommonService;
import com.glsx.publicservice.util.RedisCacheUtil;
import com.glsx.publicservice.util.SmsUtil;
/**
*
......
package com.glsx.publicservice.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
*
* @Title PropertiesUtil.java
* @Package com.glsx.manager.utils
* @Description TODO 读取配置文件属性值
* @author zhanghj
* @date 2018年12月24日 下午5:38:42
* @version 1.0.0
*/
@Component
public class PropertiesUtil {
private static Environment env;
@Autowired
public void setEnv(Environment env) {
PropertiesUtil.env = env;
}
public static String getProperty(String key){
return env.getProperty(key);
}
public static String getProperty(String key, String defaultVal){
return env.getProperty(key, defaultVal);
}
}
......@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.HttpUtils;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.publicservice.constants.Constants;
/**
......
......@@ -14,8 +14,8 @@ import org.springframework.web.multipart.MultipartFile;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.exception.FdfsUnsupportStorePathException;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.common.utils.StringUtils;
import com.glsx.publicservice.util.PropertiesUtil;
/**
......
......@@ -37,11 +37,6 @@
<artifactId>spring-boot-devtools</artifactId>
<scope>test</scope>
</dependency>
<!-- SpringBoot Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- EurekaClient -->
<dependency>
<groupId>org.springframework.cloud</groupId>
......
package com.glsx.usercenter.config;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
*
* @Title RedisConfig.java
* @Package com.qurong.credit.sp.config
* @Description TODO 配置RedisTemplate的key,value的序列化策略,保持所有服务一直
* @author zhanghj
* @date 2018年8月20日 下午8:45:18
* @version
*/
@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedisConfig {
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
//设置redis,key,value序列化策略
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(redisSerializer);
//JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
redisTemplate.setValueSerializer(redisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
......@@ -14,10 +14,10 @@ import com.alibaba.fastjson.JSONObject;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.MenuClient;
import com.glsx.common.utils.Page;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.usercenter.constants.ResultCodeEnum;
import com.glsx.usercenter.pojo.Test;
import com.glsx.usercenter.service.TestService;
import com.glsx.usercenter.utils.PropertiesUtil;
import com.glsx.usercenter.utils.ShiroUtil;
@RestController
......
package com.glsx.usercenter.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
*
* @Title PropertiesUtil.java
* @Package com.glsx.manager.utils
* @Description TODO 读取配置文件属性值
* @author zhanghj
* @date 2018年12月24日 下午5:38:42
* @version 1.0.0
*/
@Component
public class PropertiesUtil {
private static Environment env;
@Autowired
public void setEnv(Environment env) {
PropertiesUtil.env = env;
}
public static String getProperty(String key){
return env.getProperty(key);
}
public static String getProperty(String key, String defaultVal){
return env.getProperty(key, defaultVal);
}
}
package com.glsx.usercenter.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
/**
* redis缓存帮助类
* Created by liumh on 2018/8/13
*/
@Component
public class RedisCacheUtil<T> {
@Autowired
public RedisTemplate redisTemplate;
/**
* 缓存基本的对象,Integer、String、实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
* @return 缓存的对象
*/
public <T> ValueOperations<String, T> setCacheObject(String key, T value, long timeout, TimeUnit unit) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
operation.set(key, value, timeout, unit);
return operation;
}
/**
* 获得缓存的基本对象。
*
* @param key 缓存键值
* @return 缓存键值对应的数据
*/
public <T> T getCacheObject(String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
}
/**
* 缓存List数据
*
* @param key 缓存的键值
* @param dataList 待缓存的List数据
* @return 缓存的对象
*/
public <T> ListOperations<String, T> setCacheList(String key, List<T> dataList) {
ListOperations listOperation = redisTemplate.opsForList();
if (null != dataList) {
int size = dataList.size();
for (int i = 0; i < size; i++) {
listOperation.leftPush(key, dataList.get(i));
}
}
return listOperation;
}
/**
* 获得缓存的list对象
*
* @param key 缓存的键值
* @return 缓存键值对应的数据
*/
public <T> List<T> getCacheList(String key) {
List<T> dataList = new ArrayList<T>();
ListOperations<String, T> listOperation = redisTemplate.opsForList();
Long size = listOperation.size(key);
for (int i = 0; i < size; i++) {
dataList.add(listOperation.index(key, i));
}
return dataList;
}
/**
* 缓存Set
*
* @param key 缓存键值
* @param dataSet 缓存的数据
* @return 缓存数据的对象
*/
public <T> BoundSetOperations<String, T> setCacheSet(String key, Set<T> dataSet) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
Iterator<T> it = dataSet.iterator();
while (it.hasNext()) {
setOperation.add(it.next());
}
return setOperation;
}
/**
* 获得缓存的set
*
* @param key
* @return
*/
public Set<T> getCacheSet(String key) {
Set<T> dataSet = new HashSet<T>();
BoundSetOperations<String, T> operation = redisTemplate.boundSetOps(key);
Long size = operation.size();
for (int i = 0; i < size; i++) {
dataSet.add(operation.pop());
}
return dataSet;
}
/**
* 缓存Map
*
* @param key
* @param dataMap
* @return
*/
public <T> HashOperations<String, String, T> setCacheMap(String key, Map<String, T> dataMap) {
HashOperations hashOperations = redisTemplate.opsForHash();
if (null != dataMap) {
for (Map.Entry<String, T> entry : dataMap.entrySet()) {
hashOperations.put(key, entry.getKey(), entry.getValue());
}
}
return hashOperations;
}
/**
* 获得缓存的Map
*
* @param key
* @return
*/
public <T> Map<String, T> getCacheMap(String key) {
Map<String, T> map = redisTemplate.opsForHash().entries(key);
return map;
}
/**
* 缓存Map
*
* @param key
* @param dataMap
* @return
*/
public <T> HashOperations<String, Integer, T> setCacheIntegerMap(String key, Map<Integer, T> dataMap) {
HashOperations hashOperations = redisTemplate.opsForHash();
if (null != dataMap) {
for (Map.Entry<Integer, T> entry : dataMap.entrySet()) {
hashOperations.put(key, entry.getKey(), entry.getValue());
}
}
return hashOperations;
}
/**
* 获得缓存的Map
*
* @param key
* @return
*/
public <T> Map<Integer, T> getCacheIntegerMap(String key) {
Map<Integer, T> map = redisTemplate.opsForHash().entries(key);
return map;
}
public void delete(String key) {
redisTemplate.delete(key);
}
public void deleteByPrex(String prex) {
Set<String> keys = redisTemplate.keys(prex + "*");
redisTemplate.delete(keys);
}
public void deleteBySuffix(String suffix) {
Set<String> keys = redisTemplate.keys("*" + suffix);
redisTemplate.delete(keys);
}
public void deleteByKeys(String... keys) {
redisTemplate.delete(Arrays.asList(keys));
}
public List getListByPrex(String prex) {
Set<String> keys = redisTemplate.keys(prex + "*");
return redisTemplate.opsForValue().multiGet(keys);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!