🔨 无 redis 测试配置.
This commit is contained in:
@@ -36,6 +36,12 @@
|
|||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-all</artifactId>
|
<artifactId>netty-all</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test redis noRedis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.fppt</groupId>
|
||||||
|
<artifactId>jedis-mock</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||||
|
*
|
||||||
|
* https://visor.dromara.org
|
||||||
|
* https://visor.dromara.org.cn
|
||||||
|
* https://visor.orionsec.cn
|
||||||
|
*
|
||||||
|
* Members:
|
||||||
|
* Jiahang Li - ljh1553488six@139.com - author
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.dromara.visor.framework.redis.configuration;
|
||||||
|
|
||||||
|
import com.github.fppt.jedismock.RedisServer;
|
||||||
|
import org.dromara.visor.common.constant.AutoConfigureOrderConst;
|
||||||
|
import org.dromara.visor.common.interfaces.Locker;
|
||||||
|
import org.dromara.visor.common.utils.LockerUtils;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* noRedis 配置
|
||||||
|
* 仅用于本地调试无 redis 的情况
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2024/12/26 10:02
|
||||||
|
*/
|
||||||
|
@ConditionalOnProperty(value = "no.redis", havingValue = "true")
|
||||||
|
@AutoConfiguration
|
||||||
|
@AutoConfigureOrder(AutoConfigureOrderConst.FRAMEWORK_REDIS - 10)
|
||||||
|
public class OrionNoRedisAutoConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mocked redis server
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public RedisServer redisServer(RedisProperties properties) {
|
||||||
|
RedisServer server = new RedisServer(properties.getPort(), InetAddress.getLoopbackAddress());
|
||||||
|
try {
|
||||||
|
server.start();
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mocked jedis factory
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public JedisConnectionFactory jedisConnectionFactory(RedisServer redisServer) {
|
||||||
|
JedisConnectionFactory factory = new JedisConnectionFactory();
|
||||||
|
factory.setHostName(redisServer.getHost());
|
||||||
|
factory.setPort(redisServer.getBindPort());
|
||||||
|
factory.setUsePool(true);
|
||||||
|
factory.setPoolConfig(new JedisPoolConfig());
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mocked redis locker
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Locker redisLocker() {
|
||||||
|
Locker locker = new Locker() {
|
||||||
|
@Override
|
||||||
|
public boolean tryLock(String key, Runnable run) {
|
||||||
|
run.run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T tryLock(String key, Supplier<T> call) {
|
||||||
|
return call.get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
LockerUtils.setDelegate(locker);
|
||||||
|
return locker;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,6 +24,12 @@
|
|||||||
"type": "java.lang.Integer",
|
"type": "java.lang.Integer",
|
||||||
"description": "最小空闲连接数.",
|
"description": "最小空闲连接数.",
|
||||||
"defaultValue": "16"
|
"defaultValue": "16"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "no.redis",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "是否无 redis.",
|
||||||
|
"defaultValue": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
org.dromara.visor.framework.redis.configuration.OrionNoRedisAutoConfiguration
|
||||||
org.dromara.visor.framework.redis.configuration.OrionRedisAutoConfiguration
|
org.dromara.visor.framework.redis.configuration.OrionRedisAutoConfiguration
|
||||||
org.dromara.visor.framework.redis.configuration.OrionCacheAutoConfiguration
|
org.dromara.visor.framework.redis.configuration.OrionCacheAutoConfiguration
|
||||||
@@ -35,3 +35,6 @@ mybatis-plus:
|
|||||||
configuration:
|
configuration:
|
||||||
# sql 日志打印
|
# sql 日志打印
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
|
||||||
|
no:
|
||||||
|
redis: false
|
||||||
|
|||||||
Reference in New Issue
Block a user