diff --git a/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java b/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java index 6e536cc67..cbe0027db 100644 --- a/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java +++ b/eladmin-common/src/main/java/me/zhengjie/redis/RedisConfig.java @@ -35,40 +35,6 @@ @EnableConfigurationProperties(RedisProperties.class) public class RedisConfig extends CachingConfigurerSupport { - @Value("${spring.redis.host}") - private String host; - - @Value("${spring.redis.port}") - private int port; - - @Value("${spring.redis.timeout}") - private int timeout; - - @Value("${spring.redis.jedis.pool.max-idle}") - private int maxIdle; - - @Value("${spring.redis.jedis.pool.max-wait}") - private long maxWaitMillis; - - @Value("${spring.redis.password}") - private String password; - - @Value("${spring.redis.database}") - private int database; - - /** - * 配置 redis 连接池 - * @return - */ - @Bean - public JedisPool redisPoolFactory(){ - JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - jedisPoolConfig.setMaxIdle(maxIdle); - jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); - String pwd = StringUtils.isBlank(password) ? null : password; - return new JedisPool(jedisPoolConfig, host, port, timeout, pwd, database); - } - /** * 设置 redis 数据默认过期时间,默认1天 * 设置@cacheable 序列化方式 @@ -127,4 +93,4 @@ public KeyGenerator keyGenerator() { return sb.toString(); }; } -} \ No newline at end of file +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/RedisServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/RedisServiceImpl.java index 77d4d1128..72e0c6fe0 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/RedisServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/monitor/service/impl/RedisServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; @@ -21,72 +22,38 @@ public class RedisServiceImpl implements RedisService { @Autowired - JedisPool pool; + RedisTemplate redisTemplate; @Override public Page findByKey(String key, Pageable pageable){ - Jedis jedis = null; - try{ - jedis = pool.getResource(); - List redisVos = new ArrayList<>(); - - if(!key.equals("*")){ - key = "*" + key + "*"; - } - for (String s : jedis.keys(key)) { - RedisVo redisVo = new RedisVo(s,jedis.get(s)); - redisVos.add(redisVo); - } - Page page = new PageImpl( - PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(),redisVos), - pageable, - redisVos.size()); - return page; - }finally{ - if(null != jedis){ - jedis.close(); // 释放资源还给连接池 - } + List redisVos = new ArrayList<>(); + if(!key.equals("*")){ + key = "*" + key + "*"; } - + for (Object s : redisTemplate.keys(key)) { + RedisVo redisVo = new RedisVo(s.toString(),redisTemplate.opsForValue().get(s.toString()).toString()); + redisVos.add(redisVo); + } + Page page = new PageImpl( + PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(),redisVos), + pageable, + redisVos.size()); + return page; } @Override public void save(RedisVo redisVo) { - Jedis jedis = null; - try{ - jedis = pool.getResource(); - jedis.set(redisVo.getKey(),redisVo.getValue()); - }finally{ - if(null != jedis){ - jedis.close(); // 释放资源还给连接池 - } - } + redisTemplate.opsForValue().set(redisVo.getKey(),redisVo.getValue()); } @Override public void delete(String key) { - Jedis jedis = null; - try{ - jedis = pool.getResource(); - jedis.del(key); - }finally{ - if(null != jedis){ - jedis.close(); // 释放资源还给连接池 - } - } + redisTemplate.delete(key); } @Override public void flushdb() { - Jedis jedis = null; - try{ - jedis = pool.getResource(); - jedis.flushAll(); - }finally{ - if(null != jedis){ - jedis.close(); // 释放资源还给连接池 - } - } + redisTemplate.getConnectionFactory().getConnection().flushDb(); } } diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index b7f2136a2..8c98a9bee 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -24,16 +24,6 @@ spring: host: 127.0.0.1 port: 6379 password: - jedis: - pool: - #最大连接数 - max-active: 100 - #最大阻塞等待时间(负数表示没限制) - max-wait: 2000 - #最大空闲 - max-idle: 500 - #最小空闲 - min-idle: 8 #连接超时时间 timeout: 5000 diff --git a/pom.xml b/pom.xml index df7e0e9a3..b275494a9 100644 --- a/pom.xml +++ b/pom.xml @@ -70,12 +70,6 @@ org.springframework.boot spring-boot-starter-data-redis - - - io.lettuce - lettuce-core - - @@ -231,4 +225,4 @@ - \ No newline at end of file +