|
|
|
@ -15,21 +15,24 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
//@Component
|
|
|
|
|
public class RedisDemoService implements ApplicationListener<ContextRefreshedEvent> {
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
public class RedisDemoService {
|
|
|
|
|
|
|
|
|
|
private static final String DEBUG_KEY = "ContextRefreshedEventTime";
|
|
|
|
|
|
|
|
|
|
public void setKey() {
|
|
|
|
|
redisTemplate.opsForValue().set(DEBUG_KEY, String.valueOf(System.currentTimeMillis()), 1, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
String value = redisTemplate.opsForValue().get(DEBUG_KEY);
|
|
|
|
|
log.info("RedisDemoService get value:" + value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
|
|
|
|
setKey();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//public class RedisDemoService implements ApplicationListener<ContextRefreshedEvent> {
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
//
|
|
|
|
|
// private static final String DEBUG_KEY = "ContextRefreshedEventTime";
|
|
|
|
|
//
|
|
|
|
|
// public void setKey() {
|
|
|
|
|
// redisTemplate.opsForValue().set(DEBUG_KEY, String.valueOf(System.currentTimeMillis()), 1, TimeUnit.MINUTES);
|
|
|
|
|
//
|
|
|
|
|
// String value = redisTemplate.opsForValue().get(DEBUG_KEY);
|
|
|
|
|
// log.info("RedisDemoService get value:" + value);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onApplicationEvent(ContextRefreshedEvent event) {
|
|
|
|
|
// setKey();
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|