Browse Source

redis demo

chenweida 7 years ago
parent
commit
5b9246f770

+ 57 - 0
patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/config/RedisConfig.java

@ -0,0 +1,57 @@
//package com.yihu.wlyy.statistics.config;
//
//import com.yihu.wlyy.statistics.controller.KeyExpiredListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.data.redis.listener.PatternTopic;
//import org.springframework.data.redis.listener.RedisMessageListenerContainer;
//import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
//import redis.clients.jedis.Jedis;
//import redis.clients.jedis.JedisPool;
//import redis.clients.jedis.JedisPoolConfig;
//
//import javax.annotation.PostConstruct;
//
///**
// * Created by chenweida on 2017/7/31.
// */
//@Configuration
//public class RedisConfig {
//    @Value("${spring.redis.host}")
//    private String host;
//    @Value("${spring.redis.port}")
//    private Integer port;
//    @Value("${spring.redis.password}")
//    private String password;
//    @Bean
//    @ConfigurationProperties(prefix = "spring.redis.pool")
//    JedisPoolConfig jedisPoolConfig() {
//        return new JedisPoolConfig();
//    }
//
//    @Bean
//    JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {
//        System.out.println(jedisPoolConfig);
//        JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
//        jedisConnectionFactory.setPoolConfig(jedisPoolConfig);
//        jedisConnectionFactory.setPort(port);
//        jedisConnectionFactory.setHostName(host);
//        jedisConnectionFactory.setPassword(password);
//        return jedisConnectionFactory;
//    }
//
//    @Bean
//    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
//        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
//        container.setConnectionFactory(connectionFactory);
//        //监听redis过期的生命周期
//        container.addMessageListener(new KeyExpiredListener(connectionFactory), new PatternTopic("__key*__:*"));
//        return container;
//    }
//}

+ 1 - 1
patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/config/WebSecurityConfig.java

@ -21,7 +21,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    String password;
    String password;
    protected void configure(HttpSecurity http) throws Exception {
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
        http.csrf().disable().authorizeRequests()
                .anyRequest().authenticated()
                .anyRequest().authenticated()
                .and()
                .and()
                .formLogin().defaultSuccessUrl("/swagger-ui.html").failureUrl("/login") //登录成功之后的跳转
                .formLogin().defaultSuccessUrl("/swagger-ui.html").failureUrl("/login") //登录成功之后的跳转

+ 68 - 30
patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/controller/JobController.java

@ -6,12 +6,16 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestController;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
/**
 * 任务启动
 * 任务启动
@ -23,9 +27,9 @@ import org.springframework.web.bind.annotation.RestController;
@Api(description = "后台-任务控制")
@Api(description = "后台-任务控制")
public class JobController extends BaseController {
public class JobController extends BaseController {
    @Autowired
    @Autowired
    private  JobService jobService;
    private JobService jobService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
    /**
     * 启动任务
     * 启动任务
@ -36,7 +40,7 @@ public class JobController extends BaseController {
    @ApiOperation(value = "根据ID立即单个任务")
    @ApiOperation(value = "根据ID立即单个任务")
    @RequestMapping(value = "startNowById", method = RequestMethod.GET)
    @RequestMapping(value = "startNowById", method = RequestMethod.GET)
    public String startNowById(
    public String startNowById(
            @ApiParam(name = "id", value = "任务ID", required = true)@RequestParam(value = "id", required = true) String id) {
            @ApiParam(name = "id", value = "任务ID", required = true) @RequestParam(value = "id", required = true) String id) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.startNowById(id);
            jobService.startNowById(id);
@ -55,7 +59,7 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "生成过去几天的数据")
    @ApiOperation(value = "生成过去几天的数据")
    @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
    @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
    public String productDataByDay(  @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day) {
    public String productDataByDay(@ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)") @RequestParam(value = "day", required = true) int day) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.productDataByDay(day);
            jobService.productDataByDay(day);
@ -74,7 +78,7 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "生成过去某一天的全部的数据")
    @ApiOperation(value = "生成过去某一天的全部的数据")
    @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
    @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
    public String productDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day) {
    public String productDataByOneDay(@ApiParam(name = "day", value = "yyyy-MM-dd") @RequestParam(value = "day", required = true) String day) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.productDataByOneDay(day);
            jobService.productDataByOneDay(day);
@ -84,6 +88,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天到某一天的全部的数据
     * 生成过去某一天到某一天的全部的数据
     *
     *
@ -93,17 +98,18 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "生成过去某一天到某一天的全部的数据(包含头尾)")
    @ApiOperation(value = "生成过去某一天到某一天的全部的数据(包含头尾)")
    @RequestMapping(value = "productDataByDayToDay", method = RequestMethod.GET)
    @RequestMapping(value = "productDataByDayToDay", method = RequestMethod.GET)
    public String productDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd", required = true)@RequestParam(value = "start", required = true)String start,
                                         @ApiParam(name = "end", value = "yyyy-MM-dd", required = true)@RequestParam(value = "end", required = true)String end) {
    public String productDataByDayToDay(@ApiParam(name = "start", value = "yyyy-MM-dd", required = true) @RequestParam(value = "start", required = true) String start,
                                        @ApiParam(name = "end", value = "yyyy-MM-dd", required = true) @RequestParam(value = "end", required = true) String end) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.productDataByDayToDay(start,end);
            jobService.productDataByDayToDay(start, end);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天到某一天的某个指标的数据
     * 生成过去某一天到某一天的某个指标的数据
     *
     *
@ -113,18 +119,19 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "生成过去某一天到某一天的某个指标的数据(包含头尾)")
    @ApiOperation(value = "生成过去某一天到某一天的某个指标的数据(包含头尾)")
    @RequestMapping(value = "productDataByDayToDayAndId", method = RequestMethod.GET)
    @RequestMapping(value = "productDataByDayToDayAndId", method = RequestMethod.GET)
    public String productDataByDayToDayAndId( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
                                         @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end,
                                              @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
    public String productDataByDayToDayAndId(@ApiParam(name = "start", value = "yyyy-MM-dd") @RequestParam(value = "start", required = true) String start,
                                             @ApiParam(name = "end", value = "yyyy-MM-dd") @RequestParam(value = "end", required = true) String end,
                                             @ApiParam(name = "id", value = "任务id") @RequestParam(value = "id", required = true) String id) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.productDataByDayToDayAndId(start,end,id);
            jobService.productDataByDayToDayAndId(start, end, id);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天的某一个指标的数据
     * 生成过去某一天的某一个指标的数据
     *
     *
@ -134,8 +141,8 @@ public class JobController extends BaseController {
    @ApiOperation(value = "生成过去某一天的全部的数据")
    @ApiOperation(value = "生成过去某一天的全部的数据")
    @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
    @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
    public String productDataByOneDayWithId(
    public String productDataByOneDayWithId(
            @ApiParam(name = "day", value = "yyyy-MM-dd")@RequestParam(value = "day", required = true)String day,
            @ApiParam(name = "id", value = "任务id")@RequestParam(value = "id", required = true)String id) {
            @ApiParam(name = "day", value = "yyyy-MM-dd") @RequestParam(value = "day", required = true) String day,
            @ApiParam(name = "id", value = "任务id") @RequestParam(value = "id", required = true) String id) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.productDataByOneDayWithId(day, id);
            jobService.productDataByOneDayWithId(day, id);
@ -145,6 +152,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去到现在的全部的数据
     * 生成过去到现在的全部的数据
     *
     *
@ -154,8 +162,8 @@ public class JobController extends BaseController {
    @ApiOperation(value = "生成过去到现在的全部的数据")
    @ApiOperation(value = "生成过去到现在的全部的数据")
    @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
    @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
    public String productDataByDayAndId(
    public String productDataByDayAndId(
            @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)")@RequestParam(value = "day", required = true) int day,
            @ApiParam(name="id",required=true)@RequestParam(value = "id", required = true) String id) {
            @ApiParam(name = "day", value = "距离今天的天数(如果是要生成昨天的数据,day=1)") @RequestParam(value = "day", required = true) int day,
            @ApiParam(name = "id", required = true) @RequestParam(value = "id", required = true) String id) {
        try {
        try {
            jobService.cleanCache();
            jobService.cleanCache();
            jobService.productDataByDayAndId(day, id);
            jobService.productDataByDayAndId(day, id);
@ -171,11 +179,11 @@ public class JobController extends BaseController {
     *
     *
     * @param id id
     * @param id id
     * @return
     * @return
    */
     */
    @ApiOperation(value = "启动单个任务")
    @ApiOperation(value = "启动单个任务")
    @RequestMapping(value = "startById", method = RequestMethod.GET)
    @RequestMapping(value = "startById", method = RequestMethod.GET)
    public String startById(
    public String startById(
            @ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true) String id) {
            @ApiParam(name = "id", value = "任务id", required = true) @RequestParam(value = "id", required = true) String id) {
        try {
        try {
            jobService.startById(id);
            jobService.startById(id);
            return success("启动成功!");
            return success("启动成功!");
@ -193,7 +201,7 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "停止单个任务")
    @ApiOperation(value = "停止单个任务")
    @RequestMapping(value = "stopById", method = RequestMethod.GET)
    @RequestMapping(value = "stopById", method = RequestMethod.GET)
    public String stopById(@ApiParam(name="id",value="任务id",required=true)@RequestParam(value = "id", required = true)String id) {
    public String stopById(@ApiParam(name = "id", value = "任务id", required = true) @RequestParam(value = "id", required = true) String id) {
        try {
        try {
            jobService.stopById(id);
            jobService.stopById(id);
            return success("停止成功!");
            return success("停止成功!");
@ -219,6 +227,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动判断的任务
     * 启动判断的任务
     *
     *
@ -235,6 +244,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 停止判断的任务
     * 停止判断的任务
     *
     *
@ -251,6 +261,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动判断的任务
     * 启动判断的任务
     *
     *
@ -267,6 +278,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 停止判断的任务
     * 停止判断的任务
     *
     *
@ -283,6 +295,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动所有任务
     * 启动所有任务
     *
     *
@ -299,6 +312,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    @ApiOperation(value = "清除緩存")
    @ApiOperation(value = "清除緩存")
    @RequestMapping(value = "cleanCache", method = RequestMethod.GET)
    @RequestMapping(value = "cleanCache", method = RequestMethod.GET)
    public String cleanCache() {
    public String cleanCache() {
@ -310,17 +324,19 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    @ApiOperation(value = "查看緩存情况")
    @ApiOperation(value = "查看緩存情况")
    @RequestMapping(value = "seeCache", method = RequestMethod.GET)
    @RequestMapping(value = "seeCache", method = RequestMethod.GET)
    public String seeCache() {
    public String seeCache() {
        try {
        try {
            String message=jobService.seeCache();
            return write(200,message);
            String message = jobService.seeCache();
            return write(200, message);
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动健康信息生成的任务
     * 启动健康信息生成的任务
     *
     *
@ -337,6 +353,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    @ApiOperation(value = "立即启动健康信息生成的任务")
    @ApiOperation(value = "立即启动健康信息生成的任务")
    @RequestMapping(value = "startHealthMessageJobNow", method = RequestMethod.GET)
    @RequestMapping(value = "startHealthMessageJobNow", method = RequestMethod.GET)
    public String startHealthMessageJobNow() {
    public String startHealthMessageJobNow() {
@ -348,6 +365,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 停止判断的任务
     * 停止判断的任务
     *
     *
@ -365,7 +383,7 @@ public class JobController extends BaseController {
        }
        }
    }
    }
  //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
    //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
    public String startaaaa() {
    public String startaaaa() {
        try {
        try {
            jobService.startaaaa();
            jobService.startaaaa();
@ -375,6 +393,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天的健康消息
     * 生成过去某一天的健康消息
     *
     *
@ -383,8 +402,8 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "生成过去某一天的健康消息")
    @ApiOperation(value = "生成过去某一天的健康消息")
    @RequestMapping(value = "productHealthDataByOneDay", method = RequestMethod.GET)
    @RequestMapping(value = "productHealthDataByOneDay", method = RequestMethod.GET)
    public String productHealthDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")
                                           @RequestParam(value = "day", required = true)String day) {
    public String productHealthDataByOneDay(@ApiParam(name = "day", value = "yyyy-MM-dd")
                                            @RequestParam(value = "day", required = true) String day) {
        try {
        try {
            jobService.productHealthDataByOneDay(day);
            jobService.productHealthDataByOneDay(day);
            return success("启动成功!");
            return success("启动成功!");
@ -393,6 +412,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天到某一天的某个指标的数据
     * 生成过去某一天到某一天的某个指标的数据
     *
     *
@ -402,11 +422,11 @@ public class JobController extends BaseController {
     */
     */
    @ApiOperation(value = "生成过去某一天到某一天的健康消息(包含头尾)")
    @ApiOperation(value = "生成过去某一天到某一天的健康消息(包含头尾)")
    @RequestMapping(value = "productHealthDataByDayToDay", method = RequestMethod.GET)
    @RequestMapping(value = "productHealthDataByDayToDay", method = RequestMethod.GET)
    public String productHealthDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
                                              @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end
                                             ) {
    public String productHealthDataByDayToDay(@ApiParam(name = "start", value = "yyyy-MM-dd") @RequestParam(value = "start", required = true) String start,
                                              @ApiParam(name = "end", value = "yyyy-MM-dd") @RequestParam(value = "end", required = true) String end
    ) {
        try {
        try {
            jobService.productHealthDataByDayToDay(start,end);
            jobService.productHealthDataByDayToDay(start, end);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
@ -430,6 +450,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 停止每天的统计报表任务
     * 停止每天的统计报表任务
     *
     *
@ -446,6 +467,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动通知任务
     * 启动通知任务
     *
     *
@ -462,6 +484,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动通知任务
     * 启动通知任务
     *
     *
@ -478,6 +501,7 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 启动通知任务
     * 启动通知任务
     *
     *
@ -495,7 +519,9 @@ public class JobController extends BaseController {
        }
        }
    }
    }
    /******************************** 随访计划消息 ****************************************************/
    /********************************
     * 随访计划消息
     ****************************************************/
    @ApiOperation(value = "启动随访计划消息任务")
    @ApiOperation(value = "启动随访计划消息任务")
    @RequestMapping(value = "startFollowupPlantJob", method = RequestMethod.GET)
    @RequestMapping(value = "startFollowupPlantJob", method = RequestMethod.GET)
@ -520,4 +546,16 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    @RequestMapping(value = "addRedisKey", method = RequestMethod.POST)
    public void addRedisKey() {
        try {
            String key="cwd:"+new Random().toString();
            redisTemplate.opsForValue().set(key,"123");
            redisTemplate.expire(key,10, TimeUnit.SECONDS);
        } catch (Exception e) {
            error(e);
        }
    }
}
}

+ 36 - 0
patient-co/patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/controller/KeyExpiredListener.java

@ -0,0 +1,36 @@
//package com.yihu.wlyy.statistics.controller;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.connection.Message;
//import org.springframework.data.redis.connection.MessageListener;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//import redis.clients.jedis.JedisPubSub;
//
//import java.util.concurrent.CountDownLatch;
//
///**
// * Created by chenweida on 2017/7/31.
// */
//public class KeyExpiredListener implements MessageListener {
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(KeyExpiredListener.class);
//    private StringRedisTemplate redisTemplate;
//
//    public KeyExpiredListener(RedisConnectionFactory connectionFactory) {
//        redisTemplate = new StringRedisTemplate();
//        redisTemplate.setConnectionFactory(connectionFactory);
//        redisTemplate.afterPropertiesSet();
//    }
//
//    public void onMessage(Message message, byte[] pattern) {
//        String key = message.toString();
//        if (key.contains("cwd")) {
//            LOGGER.info("Received <" + message + ">");
//            LOGGER.info(redisTemplate.getExpire(message.toString()) + "");
//        }
//    }
//}