added redisson-1.1.xsd to support SSL related changes

changed the creation of RedisClient to use RedisClientConfig
updated test xml to use 1.1 xsd
updated wiki test xml to include SSL related configs in reflection to
changes made in wiki
pull/894/head
Rui Gu
parent 8477f15640
commit 1c7b2a251c

@ -16,6 +16,8 @@
package org.redisson.spring.support;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisClientConfig;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
@ -26,20 +28,21 @@ import org.w3c.dom.Element;
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public final class RedisDefinitionParser
public final class RedisDefinitionParser
extends AbstractSimpleBeanDefinitionParser {
private static final String ADDRESS_ATTRIBUTE = "address";
private static final String HOST_ATTRIBUTE = "host";
private static final String PORT_ATTRIBUTE = "port";
private static final String CONNECTION_TIMEOUT_ATTRIBUTE = "connectionTimeout";
private static final String COMMAND_TIMEOUT_ATTRIBUTE = "commandTimeout";
private final RedissonNamespaceParserSupport helper;
public RedisDefinitionParser(RedissonNamespaceParserSupport helper) {
this.helper = helper;
}
@Override
protected Class<RedisClient> getBeanClass(Element element) {
return RedisClient.class;
@ -48,14 +51,27 @@ public final class RedisDefinitionParser
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
builder.getRawBeanDefinition().setBeanClass(RedisClient.class);
helper.addConstructorArgs(element,
HOST_ATTRIBUTE, String.class, builder);
helper.addConstructorArgs(element,
PORT_ATTRIBUTE, int.class, builder);
helper.addConstructorArgs(element,
CONNECTION_TIMEOUT_ATTRIBUTE, int.class, builder);
helper.addConstructorArgs(element,
COMMAND_TIMEOUT_ATTRIBUTE, int.class, builder);
if (helper.hasAttribute(element, HOST_ATTRIBUTE)) {
helper.addConstructorArgs(element,
HOST_ATTRIBUTE, String.class, builder);
helper.addConstructorArgs(element,
PORT_ATTRIBUTE, int.class, builder);
helper.addConstructorArgs(element,
CONNECTION_TIMEOUT_ATTRIBUTE, int.class, builder);
helper.addConstructorArgs(element,
COMMAND_TIMEOUT_ATTRIBUTE, int.class, builder);
} else {
BeanDefinitionBuilder b
= helper.createBeanDefinitionBuilder(element,
parserContext,
RedisClientConfig.class);
String configId = helper.getId(null, b, parserContext);
helper.parseAttributes(element, parserContext, b);
BeanComponentDefinition def
= helper.registerBeanDefinition(b, configId,
null, parserContext);
helper.addConstructorArgs(def, RedisClientConfig.class, builder);
}
builder.setDestroyMethodName("shutdown");
parserContext.getDelegate().parseQualifierElements(element,
builder.getRawBeanDefinition());
@ -65,7 +81,7 @@ public final class RedisDefinitionParser
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected boolean isEligibleAttribute(String attributeName) {
return helper.isEligibleAttribute(attributeName);

@ -1,2 +1,3 @@
http\://redisson.org/schema/redisson/redisson.xsd=org/redisson/spring/support/redisson-1.0.xsd
http\://redisson.org/schema/redisson/redisson.xsd=org/redisson/spring/support/redisson-1.1.xsd
http\://redisson.org/schema/redisson/redisson-1.0.xsd=org/redisson/spring/support/redisson-1.0.xsd
http\://redisson.org/schema/redisson/redisson-1.1.xsd=org/redisson/spring/support/redisson-1.1.xsd

@ -61,7 +61,7 @@ public class SpringNamespaceTest extends BaseTest {
}
public static void startContext() throws Exception {
System.setProperty("redisAddress", RedisRunner.getDefaultRedisServerBindAddressAndPort());
System.setProperty("redisAddress", "redis://" + RedisRunner.getDefaultRedisServerBindAddressAndPort());
//Needs a instance running on the default port, launch it if there isn't one already
if (RedisRunner.isFreePort(6379)) {
@ -79,7 +79,7 @@ public class SpringNamespaceTest extends BaseTest {
RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(),
RedisRunner.getDefaultRedisServerInstance().getRedisServerPort())
.run();
System.setProperty("slave1Address", slave1.getRedisServerAddressAndPort());
System.setProperty("slave1Address", "redis://" + slave1.getRedisServerAddressAndPort());
RedisRunner.RedisProcess slave2 = new RedisRunner()
.nosave()
@ -89,7 +89,7 @@ public class SpringNamespaceTest extends BaseTest {
RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(),
RedisRunner.getDefaultRedisServerInstance().getRedisServerPort())
.run();
System.setProperty("slave2Address", slave2.getRedisServerAddressAndPort());
System.setProperty("slave2Address", "redis://" + slave2.getRedisServerAddressAndPort());
RedisRunner.RedisProcess sentinel1 = new RedisRunner()
.nosave()
@ -101,7 +101,7 @@ public class SpringNamespaceTest extends BaseTest {
RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(),
RedisRunner.getDefaultRedisServerInstance().getRedisServerPort(),
2).run();
System.setProperty("sentinel1Address", sentinel1.getRedisServerAddressAndPort());
System.setProperty("sentinel1Address", "redis://" + sentinel1.getRedisServerAddressAndPort());
RedisRunner.RedisProcess sentinel2 = new RedisRunner()
.nosave()
@ -113,7 +113,7 @@ public class SpringNamespaceTest extends BaseTest {
RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(),
RedisRunner.getDefaultRedisServerInstance().getRedisServerPort(),
2).run();
System.setProperty("sentinel2Address", sentinel2.getRedisServerAddressAndPort());
System.setProperty("sentinel2Address", "redis://" + sentinel2.getRedisServerAddressAndPort());
RedisRunner.RedisProcess sentinel3 = new RedisRunner()
.nosave()
@ -125,7 +125,7 @@ public class SpringNamespaceTest extends BaseTest {
RedisRunner.getDefaultRedisServerInstance().getRedisServerBindAddress(),
RedisRunner.getDefaultRedisServerInstance().getRedisServerPort(),
2).run();
System.setProperty("sentinel3Address", sentinel3.getRedisServerAddressAndPort());
System.setProperty("sentinel3Address", "redis://" + sentinel3.getRedisServerAddressAndPort());
RedisRunner slave = new RedisRunner().randomPort().randomDir().nosave();
ClusterRunner clusterRunner = new ClusterRunner()
.addNode(new RedisRunner().randomPort().randomDir().nosave(),//master1
@ -143,7 +143,7 @@ public class SpringNamespaceTest extends BaseTest {
new RedisRunner().randomPort().randomDir().nosave());//slave1-3-2
final AtomicLong index = new AtomicLong(0);
clusterRunner.run().getNodes().stream().forEach((node) -> {
System.setProperty("node" + (index.incrementAndGet()) + "Address", node.getRedisServerAddressAndPort());
System.setProperty("node" + (index.incrementAndGet()) + "Address", "redis://" + node.getRedisServerAddressAndPort());
});
context = new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace.xml");

@ -2,7 +2,9 @@ package org.redisson.spring.support;
import io.netty.channel.EventLoopGroup;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.Executor;
import static org.hamcrest.Matchers.*;
import org.junit.Test;
import org.redisson.ClusterRunner;
import org.redisson.RedisRunner;
@ -11,7 +13,10 @@ import org.redisson.config.Config;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.*;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.codec.CodecProvider;
import org.redisson.config.SingleServerConfig;
import org.redisson.liveobject.provider.ResolverProvider;
@ -38,6 +43,27 @@ public class SpringNamespaceWikiTest {
}
}
@Test
public void testRedisClient() throws Exception {
RedisRunner.RedisProcess run = new RedisRunner()
.requirepass("do_not_use_if_it_is_not_set")
.nosave()
.randomDir()
.run();
try {
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_redis_client.xml");
RedisClient redisClient = context.getBean(RedisClient.class);
RedisConnection connection = redisClient.connect();
Map<String, String> info = connection.sync(RedisCommands.INFO_ALL);
assertThat(info, notNullValue());
assertThat(info, not(info.isEmpty()));
((ConfigurableApplicationContext) context).close();
} finally {
run.stop();
}
}
@Test
public void testSingleWithPlaceholder() throws Exception {
RedisRunner.RedisProcess run = new RedisRunner()
@ -66,6 +92,12 @@ public class SpringNamespaceWikiTest {
System.setProperty("redisson.password", "do_not_use_if_it_is_not_set");
System.setProperty("redisson.subscriptionsPerConnection", "10");
System.setProperty("redisson.clientName", "client_name");
System.setProperty("redisson.sslEnableEndpointIdentification", "true");
System.setProperty("redisson.sslProvider", "JDK");
System.setProperty("redisson.sslTruststore", "/tmp/truststore.p12");
System.setProperty("redisson.sslTruststorePassword", "not_set");
System.setProperty("redisson.sslKeystore", "/tmp/keystore.p12");
System.setProperty("redisson.sslKeystorePassword", "not_set");
System.setProperty("redisson.subscriptionConnectionMinimumIdleSize", "11");
System.setProperty("redisson.subscriptionConnectionPoolSize", "12");
System.setProperty("redisson.connectionMinimumIdleSize", "13");

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<context:annotation-config />
<context:property-placeholder system-properties-mode="OVERRIDE"/>

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<bean id="myCodec" class="org.redisson.codec.MsgPackJacksonCodec"/>
<bean id="myCodecProvider" class="org.redisson.codec.DefaultCodecProvider"/>
@ -51,6 +51,12 @@
password="do_not_use_if_it_is_not_set"
subscriptions-per-connection="5"
client-name="none"
ssl-enable-endpoint-identification="true"
ssl-provider="JDK"
ssl-truststore="/tmp/truststore.p12"
ssl-truststore-password="no_pass"
ssl-keystore="/tmp/keystore.p12"
ssl-keystore-password="no_pass"
load-balancer-ref="myLoadBalancer"
subscription-connection-minimum-idle-size="1"
subscription-connection-pool-size="50"
@ -62,9 +68,9 @@
subscription-mode="SLAVE"
scan-interval="1000"
>
<redisson:node-address value="127.0.0.1:6379" />
<redisson:node-address value="127.0.0.1:6380" />
<redisson:node-address value="127.0.0.1:6381" />
<redisson:node-address value="redis://127.0.0.1:6379" />
<redisson:node-address value="redis://127.0.0.1:6380" />
<redisson:node-address value="redis://127.0.0.1:6381" />
</redisson:cluster-servers>
</redisson:client>
</beans>

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<bean id="myCodec" class="org.redisson.codec.MsgPackJacksonCodec"/>
<bean id="myCodecProvider" class="org.redisson.codec.DefaultCodecProvider"/>
@ -51,6 +51,12 @@
password="do_not_use_if_it_is_not_set"
subscriptions-per-connection="5"
client-name="none"
ssl-enable-endpoint-identification="true"
ssl-provider="JDK"
ssl-truststore="/tmp/truststore.p12"
ssl-truststore-password="no_pass"
ssl-keystore="/tmp/keystore.p12"
ssl-keystore-password="no_pass"
load-balancer-ref="myLoadBalancer"
subscription-connection-minimum-idle-size="1"
subscription-connection-pool-size="50"
@ -60,11 +66,11 @@
master-connection-pool-size="64"
read-mode="SLAVE"
subscription-mode="SLAVE"
master-address="127.0.0.1:6379"
master-address="redis://127.0.0.1:6379"
database="0"
>
<redisson:slave-address value="127.0.0.1:6380" />
<redisson:slave-address value="127.0.0.1:6381" />
<redisson:slave-address value="redis://127.0.0.1:6380" />
<redisson:slave-address value="redis://127.0.0.1:6381" />
</redisson:master-slave-servers>
</redisson:client>
</beans>

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:redisson="http://redisson.org/schema/redisson"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<bean id="myExecutor" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="java.util.concurrent.Executors.newFixedThreadPool"/>
<property name="arguments" value="8"/>
</bean>
<bean id="myEventLoopGroup" class="io.netty.channel.nio.NioEventLoopGroup"/>
<bean id="myTimer" class="io.netty.util.HashedWheelTimer"/>
<redisson:redis
id="redisClient"
name="redisClient1,redisClient2"
address="redis://127.0.0.1:6379"
timer-ref="myTimer"
executor-ref="myExecutor"
group-ref="myEventLoopGroup"
socket-channel-class="io.netty.channel.socket.nio.NioSocketChannel"
connect-timeout="2000"
command-timeout="10000"
ssl-enable-endpoint-identification="true"
ssl-provider="JDK"
ssl-truststore="/tmp/truststore.p12"
ssl-truststore-password="no_pass"
ssl-keystore="/tmp/keystore.p12"
ssl-keystore-password="no_pass"
password="do_not_use_if_it_is_not_set"
database="1"
client-name="myClient"
read-only="false"
>
<!--
You can't have both name attribute and qualifier element at
the same time.
Both id attribute and name attribute can be used as qualifier
candidates.
-->
<!--<qualifier value="redisClient3"/>-->
</redisson:redis>
</beans>

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<bean id="myCodec" class="org.redisson.codec.MsgPackJacksonCodec"/>
<bean id="myCodecProvider" class="org.redisson.codec.DefaultCodecProvider"/>
@ -51,6 +51,12 @@
password="do_not_use_if_it_is_not_set"
subscriptions-per-connection="5"
client-name="none"
ssl-enable-endpoint-identification="true"
ssl-provider="JDK"
ssl-truststore="/tmp/truststore.p12"
ssl-truststore-password="no_pass"
ssl-keystore="/tmp/keystore.p12"
ssl-keystore-password="no_pass"
load-balancer-ref="myLoadBalancer"
subscription-connection-minimum-idle-size="1"
subscription-connection-pool-size="50"
@ -63,9 +69,9 @@
scan-interval="1000"
database="0"
>
<redisson:node-address value="127.0.0.1:6379" />
<redisson:node-address value="127.0.0.1:6380" />
<redisson:node-address value="127.0.0.1:6381" />
<redisson:node-address value="redis://127.0.0.1:6379" />
<redisson:node-address value="redis://127.0.0.1:6380" />
<redisson:node-address value="redis://127.0.0.1:6381" />
</redisson:replicated-servers>
</redisson:client>
</beans>

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<bean id="myCodec" class="org.redisson.codec.MsgPackJacksonCodec"/>
<bean id="myCodecProvider" class="org.redisson.codec.DefaultCodecProvider"/>
@ -51,6 +51,12 @@
password="do_not_use_if_it_is_not_set"
subscriptions-per-connection="5"
client-name="none"
ssl-enable-endpoint-identification="true"
ssl-provider="JDK"
ssl-truststore="/tmp/truststore.p12"
ssl-truststore-password="no_pass"
ssl-keystore="/tmp/keystore.p12"
ssl-keystore-password="no_pass"
load-balancer-ref="myLoadBalancer"
subscription-connection-minimum-idle-size="1"
subscription-connection-pool-size="50"
@ -63,8 +69,8 @@
master-name="myMaster"
database="0"
>
<redisson:sentinel-address value="127.0.0.1:26379" />
<redisson:sentinel-address value="127.0.0.1:26380" />
<redisson:sentinel-address value="redis://127.0.0.1:26379" />
<redisson:sentinel-address value="redis://127.0.0.1:26380" />
</redisson:sentinel-servers>
</redisson:client>
</beans>

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<bean id="myCodec" class="org.redisson.codec.MsgPackJacksonCodec"/>
<bean id="myCodecProvider" class="org.redisson.codec.DefaultCodecProvider"/>
@ -49,8 +49,14 @@
failed-attempts="3"
password="do_not_use_if_it_is_not_set"
subscriptions-per-connection="5"
client-name="none"
address="127.0.0.1:6379"
client-name="none"
ssl-enable-endpoint-identification="true"
ssl-provider="JDK"
ssl-truststore="/tmp/truststore.p12"
ssl-truststore-password="no_pass"
ssl-keystore="/tmp/keystore.p12"
ssl-keystore-password="no_pass"
address="redis://127.0.0.1:6379"
subscription-connection-minimum-idle-size="1"
subscription-connection-pool-size="50"
connection-minimum-idle-size="10"

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<context:property-placeholder system-properties-mode="OVERRIDE"/>
@ -43,7 +43,13 @@
failed-attempts="${redisson.failedAttempts}"
password="${redisson.password}"
subscriptions-per-connection="${redisson.subscriptionsPerConnection}"
client-name="${redisson.clientName}"
client-name="${redisson.clientName}"
ssl-enable-endpoint-identification="${redisson.sslEnableEndpointIdentification}"
ssl-provider="${redisson.sslProvider}"
ssl-truststore="${redisson.sslTruststore}"
ssl-truststore-password="${redisson.sslTruststorePassword}"
ssl-keystore="${redisson.sslKeystore}"
ssl-keystore-password="${redisson.sslKeystorePassword}"
address="${redisson.redisAddress}"
subscription-connection-minimum-idle-size="${redisson.subscriptionConnectionMinimumIdleSize}"
subscription-connection-pool-size="${redisson.subscriptionConnectionPoolSize}"

@ -6,7 +6,7 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.0.xsd
http://redisson.org/schema/redisson classpath:org/redisson/spring/support/redisson-1.1.xsd
">
<context:annotation-config/>
<context:property-placeholder system-properties-mode="OVERRIDE"/>

Loading…
Cancel
Save