From 4e7907983a99e695f2acba4dec8bd73b7dbe6b2b Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 29 六月 2023 14:41:33 +0800
Subject: [PATCH] optimize
---
java110-core/src/main/java/com/java110/core/cache/Java110RedisConfig.java | 75 +++++++++++++++++++++++++++++++++++--
1 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/java110-core/src/main/java/com/java110/core/cache/Java110RedisConfig.java b/java110-core/src/main/java/com/java110/core/cache/Java110RedisConfig.java
old mode 100644
new mode 100755
index a02bf8c..397398d
--- a/java110-core/src/main/java/com/java110/core/cache/Java110RedisConfig.java
+++ b/java110-core/src/main/java/com/java110/core/cache/Java110RedisConfig.java
@@ -1,7 +1,8 @@
package com.java110.core.cache;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
@@ -13,12 +14,21 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
+import org.springframework.util.StringUtils;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
import java.time.Duration;
+import java.util.HashSet;
+import java.util.Set;
+/**
+ * Created by wuxw on 2017/7/23.
+ */
@Configuration
-@EnableCaching //寮�鍚紦瀛橈紝榛樿鏄痳endis缂撳瓨锛岀户鎵緾achingConfigurerSupport 锛岀洿鎺ラ噸鍐欓噷闈㈢殑鏂规硶
-@ConditionalOnBean(Java110RedisCacheWriter.class)
+@EnableCaching
public class Java110RedisConfig extends CachingConfigurerSupport {
public final static String REDIS_EXPIRE_TIME_KEY = "#key_expire_time";
@@ -30,12 +40,67 @@
@Autowired
private RedisTemplate redisTemplate;
+ //@Bean(name = "jedisPool")
+ //@Autowired
+ public JedisPool jedisPool(@Qualifier("jedis.pool.config") JedisPoolConfig config,
+ @Value("${jedis.pool.host}") String host,
+ @Value("${jedis.pool.port}") int port,
+ @Value("${jedis.pool.timeout}") int timeout,
+ @Value("${jedis.pool.password}") String password) {
+ //娌℃湁閰嶇疆鏀逛负榛樿鍊�
+ if (timeout == 0) {
+ timeout = 2000;
+ }
+
+ if (StringUtils.isEmpty(password)) {
+ return new JedisPool(config, host, port, timeout);
+ } else {
+ return new JedisPool(config, host, port, timeout, password);
+ }
+ }
+
+
+// @Bean(name = "jedisCluster")
+// @Autowired
+ public JedisCluster jedisCluster(@Qualifier("jedis.pool.config") JedisPoolConfig config,
+ @Value("${jedis.pool.host}") String host,
+ @Value("${jedis.pool.port}") int port,
+ @Value("${jedis.pool.timeout}") int timeout,
+ @Value("${jedis.pool.password}") String password) {
+ //娌℃湁閰嶇疆鏀逛负榛樿鍊�
+ if (timeout == 0) {
+ timeout = 2000;
+ }
+ String[] hosts = host.split(",");
+ Set<HostAndPort> nodes = new HashSet<>();
+ String[] tmpHosts = null;
+ for (String tmpHost : hosts) {
+ tmpHosts = tmpHost.split(":");
+ nodes.add(new HostAndPort(tmpHosts[0], Integer.parseInt(tmpHosts[1])));
+ }
+ JedisCluster cluster = new JedisCluster(nodes);
+ return cluster;
+ }
+
+ //@Bean(name = "jedis.pool.config")
+ public JedisPoolConfig jedisPoolConfig(@Value("${jedis.pool.config.maxTotal}") int maxTotal,
+ @Value("${jedis.pool.config.maxIdle}") int maxIdle,
+ @Value("${jedis.pool.config.maxWaitMillis}") int maxWaitMillis) {
+ JedisPoolConfig config = new JedisPoolConfig();
+ config.setMaxTotal(maxTotal);
+ config.setMaxIdle(maxIdle);
+ config.setMaxWaitMillis(maxWaitMillis);
+
+
+ return config;
+ }
+
+
@Override
@Bean
public CacheManager cacheManager() {
RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();
- System.out.printf("123123");
//涓婇潰瀹炵幇鐨勭紦瀛樿鍐�
Java110RedisCacheWriter java110RedisCacheWriter
= new Java110RedisCacheWriter(connectionFactory);
@@ -55,4 +120,6 @@
return configuration;
}
+
+
}
--
Gitblit v1.8.0