merge
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.xwbing.redis;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -18,7 +16,6 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||
@Configuration
|
||||
@PropertySource("classpath:redis.properties")
|
||||
public class RedisConfig {
|
||||
private final Logger logger = LoggerFactory.getLogger(RedisConfig.class);
|
||||
@Value("${maxTotal}")
|
||||
private Integer maxTotal;
|
||||
@Value("${maxIdle}")
|
||||
@@ -44,8 +41,6 @@ public class RedisConfig {
|
||||
@Bean
|
||||
public JedisPool jedisPool() {
|
||||
JedisPoolConfig config = jedisPoolConfig();
|
||||
JedisPool pool = new JedisPool(config, host, port, timeOut);
|
||||
logger.info("init jedisPool=================");
|
||||
return pool;
|
||||
return new JedisPool(config, host, port, timeOut);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.xwbing.redis;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -23,7 +26,7 @@ public class RedisService {
|
||||
private JedisPool jedisPool;
|
||||
@Value("${redisCode}")
|
||||
private String redisCode;
|
||||
|
||||
private final Logger logger= LoggerFactory.getLogger(RedisService.class);
|
||||
private RedisService() {
|
||||
|
||||
}
|
||||
@@ -373,7 +376,12 @@ public class RedisService {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = getJedis();
|
||||
return jedis.ping();
|
||||
String ping = jedis.ping();
|
||||
logger.error("redis连接成功");
|
||||
return ping;
|
||||
} catch (JedisConnectionException ex){
|
||||
logger.error("redis连接失败");
|
||||
return "";
|
||||
} finally {
|
||||
returnJedis(jedis);
|
||||
}
|
||||
|
||||
@@ -30,16 +30,18 @@ public class RedisStartupInit implements InitializingBean {
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
logger.info("redis启动===执行方法===刷新缓存==================");
|
||||
logger.info("redis启动===执行方法===刷新缓存==========================");
|
||||
redisService.ping();
|
||||
redisService.set("test", "成功");
|
||||
logger.info("redis获取测试数据:{}===============================",redisService.get("test"));
|
||||
logger.info("redis获取测试数据:{}",redisService.get("test"));
|
||||
redisService.del("xwb");
|
||||
boolean exists = redisService.exists("xwb");
|
||||
logger.info("redis删除测试数据:{}=================================",!exists);
|
||||
logger.info("redis删除测试数据:{}",!exists);
|
||||
Set<String> set = redisService.keys(redisCode + "*");
|
||||
set.forEach(keyStr -> {
|
||||
logger.info("删除缓存名称:{}===========================",keyStr);
|
||||
logger.info("删除缓存名称:{}",keyStr);
|
||||
redisService.delInit(keyStr);
|
||||
});
|
||||
logger.info("redis初始化成功=================================");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user