Commit b02c68ed authored by 黎博's avatar 黎博

新增redis工具类

parent 7b6dd538
package cn.qg.qaplatform.config;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
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.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* redis配置类
*/
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {
/**
* 配置自定义redisTemplate
*/
@Bean
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
// 设置值(value)的序列化采用Jackson2JsonRedisSerializer。
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
// 设置键(key)的序列化采用StringRedisSerializer。
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
This diff is collapsed.
package cn.qg.qaplatform.zdata.service.impl;
import cn.qg.qaplatform.config.WebSocketServer;
import cn.qg.qaplatform.utils.RedisUtil;
import cn.qg.qaplatform.zdata.domain.ApplyDataVo;
import cn.qg.qaplatform.zdata.domain.GenLoanUser;
import cn.qg.qaplatform.zdata.process.Xyqb;
import cn.qg.qaplatform.zdata.service.QueryBasicLoanStatusDataService;
import cn.qg.qaplatform.zdata.service.QueryInProcessStatusService;
import cn.qg.qaplatform.zdata.service.XyqbDataService;
import cn.qg.qaplatform.zdata.service.QueryBasicLoanStatusDataService;
import com.alibaba.fastjson.JSONException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.net.URISyntaxException;
import java.util.Map;
......@@ -22,15 +21,15 @@ import java.util.Map;
@Slf4j
public class XyqbDataServiceImpl implements XyqbDataService {
@Resource
RedisTemplate redisTemplate;
@Autowired
QueryBasicLoanStatusDataService queryBasicLoanStatusDataService;
@Autowired
QueryInProcessStatusService queryInProcessStatusService;
@Autowired
RedisUtil redisUtil;
/**
* 分配资产计划
* @param namespace
......@@ -241,7 +240,8 @@ public class XyqbDataServiceImpl implements XyqbDataService {
*/
public void setUserStatusRedisValue(String namespace, String phoneNo, Integer status) {
String redisKey = namespace + "_" + phoneNo;
redisTemplate.opsForValue().set(redisKey, status);
redisUtil.set(redisKey, status);
redisUtil.expire(redisKey, 300);
}
......@@ -366,7 +366,7 @@ public class XyqbDataServiceImpl implements XyqbDataService {
@Override
public GenLoanUser queryUserStatus(String namespace, String phoneNo) {
String redisResult = redisTemplate.opsForValue().get(namespace + "_" + phoneNo).toString();
String redisResult = redisUtil.get(namespace + "_" + phoneNo).toString();
log.info("获取redis key结果为:" + redisResult);
GenLoanUser genLoanUser = new GenLoanUser();
genLoanUser = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment