mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-18 02:56:30 +08:00
commit:1.6版本发布
This commit is contained in:
@@ -90,9 +90,6 @@
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: redis.clients:jedis:3.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.7.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.redisson:redisson:3.12.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.45.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.45.Final" level="project" />
|
||||
@@ -109,6 +106,7 @@
|
||||
<orderEntry type="library" name="Maven: de.ruedigermoeller:fst:2.57" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.25" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.10.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.2" level="project" />
|
||||
|
||||
@@ -20,11 +20,6 @@
|
||||
<artifactId>common-core</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.orange.demo.common.redis.cache;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache;
|
||||
@@ -73,30 +71,4 @@ public class SessionCacheHelper {
|
||||
cacheManager.getCache(c.name()).evict(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存放session的Token数据。仅仅单体服务使用。
|
||||
*
|
||||
* @param sessionId 当前会话的SessionId。
|
||||
* @param tokenData 当前会话的JWT Token对象。
|
||||
*/
|
||||
public void putTokenData(String sessionId, TokenData tokenData) {
|
||||
if (sessionId == null || tokenData == null) {
|
||||
return;
|
||||
}
|
||||
Cache cache = cacheManager.getCache(RedissonCacheConfig.CacheEnum.GLOBAL_CACHE.name());
|
||||
cache.put(sessionId, JSON.toJSONString(tokenData));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取session的JWT Token对象。
|
||||
*
|
||||
* @param sessionId 当前会话的SessionId。
|
||||
* @return 当前会话的JWT Token对象。
|
||||
*/
|
||||
public TokenData getTokenData(String sessionId) {
|
||||
Cache cache = cacheManager.getCache(RedissonCacheConfig.CacheEnum.GLOBAL_CACHE.name());
|
||||
String tokenString = cache.get(sessionId, String.class);
|
||||
return JSONObject.parseObject(tokenString, TokenData.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.orange.demo.common.redis.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* Redis配置类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(name = "redis.jedis.enabled", havingValue = "true")
|
||||
public class JedisConfig {
|
||||
|
||||
@Value("${redis.jedis.port}")
|
||||
private Integer port;
|
||||
|
||||
@Value("${redis.jedis.host}")
|
||||
private String redisHost;
|
||||
|
||||
@Value("${redis.jedis.timeout}")
|
||||
private int timeout;
|
||||
|
||||
@Value("${redis.jedis.pool.maxTotal}")
|
||||
private Integer maxTotal;
|
||||
|
||||
@Value("${redis.jedis.pool.maxIdle}")
|
||||
private Integer maxIdle;
|
||||
|
||||
@Value("${redis.jedis.pool.minIdle}")
|
||||
private Integer minIdle;
|
||||
|
||||
@Value("${redis.jedis.pool.maxWait}")
|
||||
private Integer maxWait;
|
||||
|
||||
@Bean
|
||||
public JedisPool getJedisPool() {
|
||||
// Jedis配置信息
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxTotal(maxTotal);
|
||||
jedisPoolConfig.setMaxIdle(maxIdle);
|
||||
jedisPoolConfig.setMinIdle(minIdle);
|
||||
jedisPoolConfig.setMaxWaitMillis(maxWait);
|
||||
jedisPoolConfig.setEvictorShutdownTimeoutMillis(2000);
|
||||
return new JedisPool(jedisPoolConfig, redisHost, port);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.orange.demo.common.redis.config;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.orange.demo.common.core.exception.InvalidRedisModeException;
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
@@ -9,8 +12,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Redisson配置类。和Jedis一样都是Redis客户端,但是Redisson提供了更多的数据结构抽象。
|
||||
* 这里我们只是使用了Redisson的分布式锁,以及map等数据结构作为字典缓存使用。更多用法请参考其文档。
|
||||
* Redisson配置类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
@@ -22,6 +24,15 @@ public class RedissonConfig {
|
||||
@Value("${redis.redisson.lockWatchdogTimeout}")
|
||||
private Integer lockWatchdogTimeout;
|
||||
|
||||
@Value("${redis.redisson.mode}")
|
||||
private String mode;
|
||||
|
||||
/**
|
||||
* 仅仅用于sentinel模式。
|
||||
*/
|
||||
@Value("${redis.redisson.masterName:}")
|
||||
private String masterName;
|
||||
|
||||
@Value("${redis.redisson.address}")
|
||||
private String address;
|
||||
|
||||
@@ -37,14 +48,45 @@ public class RedissonConfig {
|
||||
@Bean
|
||||
public RedissonClient redissonClient() {
|
||||
Config config = new Config();
|
||||
// 这里config还支持其他redis集群模式,可根据实际需求更换。
|
||||
// 比如useClusterServers()/useMasterSlaveServers()等。
|
||||
config.setLockWatchdogTimeout(lockWatchdogTimeout)
|
||||
.useSingleServer()
|
||||
.setAddress("redis://" + address)
|
||||
.setConnectionPoolSize(poolSize)
|
||||
.setConnectionMinimumIdleSize(minIdle)
|
||||
.setConnectTimeout(timeout);
|
||||
if ("single".equals(mode)) {
|
||||
config.setLockWatchdogTimeout(lockWatchdogTimeout)
|
||||
.useSingleServer()
|
||||
.setAddress(address)
|
||||
.setConnectionPoolSize(poolSize)
|
||||
.setConnectionMinimumIdleSize(minIdle)
|
||||
.setConnectTimeout(timeout);
|
||||
} else if ("cluster".equals(mode)) {
|
||||
String[] clusterAddresses = StrUtil.splitToArray(address, ',');
|
||||
config.setLockWatchdogTimeout(lockWatchdogTimeout)
|
||||
.useClusterServers()
|
||||
.addNodeAddress(clusterAddresses)
|
||||
.setConnectTimeout(timeout)
|
||||
.setMasterConnectionPoolSize(poolSize);
|
||||
} else if ("sentinel".equals(mode)) {
|
||||
String[] sentinelAddresses = StrUtil.splitToArray(address, ',');
|
||||
config.setLockWatchdogTimeout(lockWatchdogTimeout)
|
||||
.useSentinelServers()
|
||||
.setMasterName(masterName)
|
||||
.addSentinelAddress(sentinelAddresses)
|
||||
.setConnectTimeout(timeout)
|
||||
.setMasterConnectionPoolSize(poolSize);
|
||||
} else if ("master-slave".equals(mode)) {
|
||||
String[] masterSlaveAddresses = StrUtil.splitToArray(address, ',');
|
||||
if (masterSlaveAddresses.length == 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"redis.redisson.address MUST have multiple redis addresses for master-slave mode.");
|
||||
}
|
||||
String[] slaveAddresses = new String[masterSlaveAddresses.length - 1];
|
||||
ArrayUtil.copy(masterSlaveAddresses, 1, slaveAddresses, 0, slaveAddresses.length);
|
||||
config.setLockWatchdogTimeout(lockWatchdogTimeout)
|
||||
.useMasterSlaveServers()
|
||||
.setMasterAddress(masterSlaveAddresses[0])
|
||||
.addSlaveAddress(slaveAddresses)
|
||||
.setConnectTimeout(timeout)
|
||||
.setMasterConnectionPoolSize(poolSize);
|
||||
} else {
|
||||
throw new InvalidRedisModeException(mode);
|
||||
}
|
||||
return Redisson.create(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.orange.demo.common.redis.config.JedisConfig,\
|
||||
com.orange.demo.common.redis.config.RedissonConfig
|
||||
Reference in New Issue
Block a user