diff --git a/redisson/src/main/java/org/redisson/RedisNodes.java b/redisson/src/main/java/org/redisson/RedisNodes.java index e94bffdb0..10a5861a3 100644 --- a/redisson/src/main/java/org/redisson/RedisNodes.java +++ b/redisson/src/main/java/org/redisson/RedisNodes.java @@ -37,6 +37,7 @@ import org.redisson.connection.RedisClientEntry; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; +import org.redisson.misc.URIBuilder; /** * @@ -55,7 +56,7 @@ public class RedisNodes implements NodesGroup { @Override public N getNode(String address) { Collection clients = (Collection) connectionManager.getClients(); - URI uri = URI.create(address); + URI uri = URIBuilder.create(address); InetSocketAddress addr = new InetSocketAddress(uri.getHost(), uri.getPort()); for (N node : clients) { if (node.getAddr().equals(addr)) { diff --git a/redisson/src/main/java/org/redisson/client/RedisClient.java b/redisson/src/main/java/org/redisson/client/RedisClient.java index 077183eb1..e7e8a35ff 100644 --- a/redisson/src/main/java/org/redisson/client/RedisClient.java +++ b/redisson/src/main/java/org/redisson/client/RedisClient.java @@ -44,6 +44,7 @@ import io.netty.util.Timer; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.GlobalEventExecutor; +import org.redisson.misc.URIBuilder; /** * Low-level Redis client @@ -101,7 +102,7 @@ public class RedisClient { */ @Deprecated public RedisClient(String address) { - this(URI.create(address)); + this(URIBuilder.create(address)); } /* diff --git a/redisson/src/main/java/org/redisson/client/RedisClientConfig.java b/redisson/src/main/java/org/redisson/client/RedisClientConfig.java index aaf8c29b1..957cc909f 100644 --- a/redisson/src/main/java/org/redisson/client/RedisClientConfig.java +++ b/redisson/src/main/java/org/redisson/client/RedisClientConfig.java @@ -26,6 +26,7 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.Timer; +import org.redisson.misc.URIBuilder; /** * @@ -56,11 +57,11 @@ public class RedisClientConfig { private String sslKeystorePassword; public RedisClientConfig setAddress(String host, int port) { - this.address = URI.create("redis://" + host + ":" + port); + this.address = URIBuilder.create("redis://" + host + ":" + port); return this; } public RedisClientConfig setAddress(String address) { - this.address = URI.create(address); + this.address = URIBuilder.create(address); return this; } public RedisClientConfig setAddress(URI address) { diff --git a/redisson/src/main/java/org/redisson/client/RedisRedirectException.java b/redisson/src/main/java/org/redisson/client/RedisRedirectException.java index 8042950f8..5f9f0d872 100644 --- a/redisson/src/main/java/org/redisson/client/RedisRedirectException.java +++ b/redisson/src/main/java/org/redisson/client/RedisRedirectException.java @@ -17,6 +17,7 @@ package org.redisson.client; import java.net.InetSocketAddress; import java.net.URI; +import org.redisson.misc.URIBuilder; /** * @@ -27,12 +28,12 @@ public class RedisRedirectException extends RedisException { private static final long serialVersionUID = 181505625075250011L; - private int slot; - private URI url; + private final int slot; + private final URI url; public RedisRedirectException(int slot, String url) { this.slot = slot; - this.url = URI.create("//" + url); + this.url = URIBuilder.create("//" + url); } public int getSlot() { diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterNodeInfo.java b/redisson/src/main/java/org/redisson/cluster/ClusterNodeInfo.java index c98e23845..8019329d8 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterNodeInfo.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterNodeInfo.java @@ -18,6 +18,7 @@ package org.redisson.cluster; import java.net.URI; import java.util.HashSet; import java.util.Set; +import org.redisson.misc.URIBuilder; /** * @@ -52,7 +53,7 @@ public class ClusterNodeInfo { return address; } public void setAddress(String address) { - this.address = URI.create(address); + this.address = URIBuilder.create(address); } public void addSlotRange(ClusterSlotRange range) { diff --git a/redisson/src/main/java/org/redisson/config/ClusterServersConfig.java b/redisson/src/main/java/org/redisson/config/ClusterServersConfig.java index 6a9476ce6..2ba803f6a 100644 --- a/redisson/src/main/java/org/redisson/config/ClusterServersConfig.java +++ b/redisson/src/main/java/org/redisson/config/ClusterServersConfig.java @@ -18,6 +18,7 @@ package org.redisson.config; import java.net.URI; import java.util.ArrayList; import java.util.List; +import org.redisson.misc.URIBuilder; /** * @@ -53,7 +54,7 @@ public class ClusterServersConfig extends BaseMasterSlaveServersConfig { */ public SingleServerConfig setAddress(String address) { if (address != null) { - this.address = URI.create(address); + this.address = URIBuilder.create(address); } return this; } diff --git a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java index 30bba5b01..bd13f9462 100755 --- a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java @@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; import io.netty.util.internal.PlatformDependent; +import org.redisson.misc.URIBuilder; /** * @@ -104,7 +105,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { log.info("slave: {} added", host); if (flags.contains("s_down") || flags.contains("disconnected")) { - URI uri = URI.create(host); + URI uri = URIBuilder.create(host); disconnectedSlaves.add(uri); log.warn("slave: {} is down", host); } @@ -215,7 +216,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { String port = parts[3]; String addr = createAddress(ip, port); - URI uri = URI.create(addr); + URI uri = URIBuilder.create(addr); registerSentinel(cfg, uri, c); } } @@ -237,7 +238,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { // to avoid addition twice if (slaves.putIfAbsent(slaveAddr, true) == null) { final MasterSlaveEntry entry = getEntry(singleSlotRange.getStartSlot()); - RFuture future = entry.addSlave(URI.create(slaveAddr)); + RFuture future = entry.addSlave(URIBuilder.create(slaveAddr)); future.addListener(new FutureListener() { @Override public void operationComplete(Future future) throws Exception { @@ -379,7 +380,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { String newMaster = createAddress(ip, port); if (!newMaster.equals(current) && currentMaster.compareAndSet(current, newMaster)) { - changeMaster(singleSlotRange.getStartSlot(), URI.create(newMaster)); + changeMaster(singleSlotRange.getStartSlot(), URIBuilder.create(newMaster)); log.info("master {} changed to {}", current, newMaster); } } diff --git a/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java b/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java index 3ad542023..76661abdb 100644 --- a/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java +++ b/redisson/src/main/java/org/redisson/connection/balancer/WeightedRoundRobinBalancer.java @@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.redisson.connection.ClientConnectionsEntry; import io.netty.util.internal.PlatformDependent; +import org.redisson.misc.URIBuilder; /** * Weighted Round Robin balancer. @@ -77,7 +78,7 @@ public class WeightedRoundRobinBalancer implements LoadBalancer { */ public WeightedRoundRobinBalancer(Map weights, int defaultWeight) { for (Entry entry : weights.entrySet()) { - URI uri = URI.create(entry.getKey()); + URI uri = URIBuilder.create(entry.getKey()); InetSocketAddress addr = new InetSocketAddress(uri.getHost(), uri.getPort()); if (entry.getValue() <= 0) { throw new IllegalArgumentException("Weight can't be less than or equal zero"); diff --git a/redisson/src/main/java/org/redisson/misc/URIBuilder.java b/redisson/src/main/java/org/redisson/misc/URIBuilder.java new file mode 100644 index 000000000..1d952b476 --- /dev/null +++ b/redisson/src/main/java/org/redisson/misc/URIBuilder.java @@ -0,0 +1,40 @@ +/** + * Copyright 2016 Nikita Koksharov + * + * 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.redisson.misc; + +import java.net.URI; + +/** + * + * @author Rui Gu (https://github.com/jackygurui) + */ +public class URIBuilder { + + public static URI create(String uri) { + URI u = URI.create(uri); + //Let's assuming most of the time it is OK. + if (u.getHost() != null) { + return u; + } + String s = uri.substring(0, uri.lastIndexOf(":")) + .replaceFirst("redis://", "") + .replaceFirst("rediss://", ""); + //Assuming this is an IPv6 format, other situations will be handled by + //Netty at a later stage. + return URI.create(uri.replace(s, "[" + s + "]")); + } + +} diff --git a/redisson/src/main/java/org/redisson/spring/support/RedisDefinitionParser.java b/redisson/src/main/java/org/redisson/spring/support/RedisDefinitionParser.java index 6c02eee29..ee164ee5d 100644 --- a/redisson/src/main/java/org/redisson/spring/support/RedisDefinitionParser.java +++ b/redisson/src/main/java/org/redisson/spring/support/RedisDefinitionParser.java @@ -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 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); diff --git a/redisson/src/main/java/org/redisson/spring/support/RedissonDefinitionParser.java b/redisson/src/main/java/org/redisson/spring/support/RedissonDefinitionParser.java index 911574b96..6fa573d11 100644 --- a/redisson/src/main/java/org/redisson/spring/support/RedissonDefinitionParser.java +++ b/redisson/src/main/java/org/redisson/spring/support/RedissonDefinitionParser.java @@ -15,7 +15,6 @@ */ package org.redisson.spring.support; -import java.net.URI; import java.util.List; import org.redisson.Redisson; @@ -124,7 +123,7 @@ public final class RedissonDefinitionParser String id = parserContext.getReaderContext().generateBeanName(bd); helper.registerBeanDefinition(builder, id, helper.parseAliase(element), parserContext); - parseAttributes(element, parserContext, builder); + helper.parseAttributes(element, parserContext, builder); redissonDef.addDependsOn(id); parseChildElements(element, id, null, redissonDef, parserContext); parserContext.getDelegate().parseQualifierElements(element, bd); @@ -140,45 +139,6 @@ public final class RedissonDefinitionParser redissonDef.addDependsOn(id); } - private void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - NamedNodeMap attributes = element.getAttributes(); - for (int x = 0; x < attributes.getLength(); x++) { - Attr attribute = (Attr) attributes.item(x); - if (helper.isEligibleAttribute(attribute)) { - String propertyName - = attribute.getLocalName().endsWith(REF_SUFFIX) - ? attribute.getLocalName() - .substring(0, attribute.getLocalName() - .length() - REF_SUFFIX.length()) - : attribute.getLocalName(); - propertyName = Conventions - .attributeNameToPropertyName(propertyName); - Assert.state(StringUtils.hasText(propertyName), - "Illegal property name returned from" - + " 'extractPropertyName(String)': cannot be" - + " null or empty."); - if (attribute.getLocalName().endsWith(REF_SUFFIX)) { - builder.addPropertyReference(propertyName, - attribute.getValue()); - } else { - Object value = attribute.getValue(); - String localName = helper.getName(element); - if ("masterAddress".equals(propertyName) - && ConfigType.masterSlaveServers.name() - .equals(localName)) { - try { - value = URI.create((String) value); - } catch (Exception e) { - //value may be a placeholder - value = "redis://" + value; - } - } - builder.addPropertyValue(propertyName, value); - } - } - } - } - @Override public BeanDefinition parse(Element element, ParserContext parserContext) { //Sort out the Config Class @@ -186,7 +146,7 @@ public final class RedissonDefinitionParser = helper.createBeanDefinitionBuilder(element, parserContext, Config.class); String configId = helper.getId(null, configBuilder, parserContext); - parseAttributes(element, parserContext, configBuilder); + helper.parseAttributes(element, parserContext, configBuilder); helper.registerBeanDefinition(configBuilder, configId, null, parserContext); @@ -200,7 +160,7 @@ public final class RedissonDefinitionParser parserContext.getDelegate().parseQualifierElements(element, builder.getRawBeanDefinition()); String id = helper.getId(element, builder, parserContext); - parseAttributes(element, parserContext, configBuilder); + helper.parseAttributes(element, parserContext, configBuilder); //Sort out all the nested elements parseChildElements(element, configId, id, builder, parserContext); diff --git a/redisson/src/main/java/org/redisson/spring/support/RedissonNamespaceParserSupport.java b/redisson/src/main/java/org/redisson/spring/support/RedissonNamespaceParserSupport.java index d7b2804aa..be259aeb0 100644 --- a/redisson/src/main/java/org/redisson/spring/support/RedissonNamespaceParserSupport.java +++ b/redisson/src/main/java/org/redisson/spring/support/RedissonNamespaceParserSupport.java @@ -25,9 +25,11 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.Conventions; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.w3c.dom.Attr; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** @@ -39,6 +41,7 @@ public class RedissonNamespaceParserSupport { public final static String REDISSON_NAMESPACE = "http://redisson.org/schema/redisson"; + static final String REF_SUFFIX = "-ref"; static final String API_CLASS_PATH_PREFIX = "org.redisson.api.R"; static final String IMPL_CLASS_PATH_PREFIX = "org.redisson.Redisson"; @@ -93,6 +96,33 @@ public class RedissonNamespaceParserSupport { return aliases; } + public void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + NamedNodeMap attributes = element.getAttributes(); + for (int x = 0; x < attributes.getLength(); x++) { + Attr attribute = (Attr) attributes.item(x); + if (isEligibleAttribute(attribute)) { + String propertyName + = attribute.getLocalName().endsWith(REF_SUFFIX) + ? attribute.getLocalName() + .substring(0, attribute.getLocalName() + .length() - REF_SUFFIX.length()) + : attribute.getLocalName(); + propertyName = Conventions + .attributeNameToPropertyName(propertyName); + Assert.state(StringUtils.hasText(propertyName), + "Illegal property name returned from" + + " 'extractPropertyName(String)': cannot be" + + " null or empty."); + if (attribute.getLocalName().endsWith(REF_SUFFIX)) { + builder.addPropertyReference(propertyName, + attribute.getValue()); + } else { + builder.addPropertyValue(propertyName, attribute.getValue()); + } + } + } + } + public BeanDefinitionBuilder createBeanDefinitionBuilder(Element element, ParserContext parserContext, Class cls) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); diff --git a/redisson/src/main/resources/META-INF/spring.schemas b/redisson/src/main/resources/META-INF/spring.schemas index 274331f67..f5503f254 100644 --- a/redisson/src/main/resources/META-INF/spring.schemas +++ b/redisson/src/main/resources/META-INF/spring.schemas @@ -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 diff --git a/redisson/src/main/resources/org/redisson/spring/support/redisson-1.1.xsd b/redisson/src/main/resources/org/redisson/spring/support/redisson-1.1.xsd new file mode 100644 index 000000000..6cadaa351 --- /dev/null +++ b/redisson/src/main/resources/org/redisson/spring/support/redisson-1.1.xsd @@ -0,0 +1,2429 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + netty-tcnative lib is required to be in classpath. + ]]> + + + + + + + + + + + + + + + <qualifier> is not used. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + timeout time + and current connections amount bigger than minimum idle connections pool + size, then it will closed and removed from pool. + Value in milliseconds. + + Default: 10000 + ]]> + + + + + Node.ping and Node.pingAll + operation. Value in milliseconds. + + Default: 1000 + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + failedAttempts. + + Default: 3 + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + each slave + node. + + Default: 10 + ]]> + + + + + each slave + node. + + Default: 64 + ]]> + + + + + each slave + node. + + Default: 10 + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NB: applications must ensure the JVM DNS cache TTL is low enough to + support this. e.g., http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-jvm-ttl.html + + Default: false + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true then invalidation + message which removes corresponding entry from cache will be sent to all + other RLocalCachedMap instances on each entry update/remove operation. + if false then invalidation message won't be sent. + ]]> + + + + + LRU - uses cache with LRU (least recently used) eviction + policy. +

LFU - uses cache with LFU (least frequently used) + eviction policy. +

SOFT - uses cache with soft references. The garbage + collector will evict items from the cache when the JVM is + running out of memory. JVM flag -XX:SoftRefLRUPolicyMSPerMB=??? + is required to function. +

NONE - doesn't use eviction policy, but timeToLive and + maxIdleTime params are still working. + ]]> + + + + + 0 then local cache is unbounded. + ]]> + + + + + 0 then timeout is not applied. + + Default unit is MILLISECONDS + ]]> + + + + + + + + + + 0 then timeout is not applied. + + Default unit is MILLISECONDS + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOT mandatory + since the class will also be registered lazily when it is first used. + + All classed registered with the service is stored in a class cache. + + The cache is independent between different RedissonClient instances. When + a class is registered in one RLiveObjectService instance it is also + accessible in another RLiveObjectService instance so long as they are + created by the same RedissonClient instance. + ]]> + + + + + + + + + + + + + + + + + + NOT mandatory + since the class will also be registered lazily when it is first used. + + All classed registered with the service is stored in a class cache. + + The cache is independent between different RedissonClient instances. When + a class is registered in one RLiveObjectService instance it is also + accessible in another RLiveObjectService instance so long as they are + created by the same RedissonClient instance. + + One of "object-id" or "object-id-ref" attribute is required. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Set eviction + + Redisson distributed Set for Java with eviction support implemented by + separate RSetCache object which extends RSet interface. It also + implements java.util.Set interface. + + Current redis implementation doesn't has set value eviction + functionality. Therefore expired values are cleaned by + org.redisson.EvictionScheduler. It removes 100 expired values at once. + Task launch time tuned automatically and depends on expired entries + amount deleted in previous time and varies between 1 second to 2 hours. + Thus if clean task deletes 100 values each time it will be executed + every second (minimum execution delay). But if current expired values + amount is lower than previous one then execution delay will be increased + by 1.5 times. + ]]> + + + + + + + + + + + Map eviction + + Redisson distributed Map for Java with eviction support implemented by + separate RMapCache object which extends RMap interface. It keeps + elements in insertion order and implements + java.util.concurrent.ConcurrentMap and java.util.Map interfaces. + Redisson has a Spring Cache integration which based on Map and MapCache + objects. + + Current redis implementation doesn't has map entry eviction + functionality. Therefore expired entries are cleaned by + org.redisson.EvictionScheduler. It removes 100 expired entries at once. + Task launch time tuned automatically and depends on expired entries + amount deleted in previous time and varies between 1 second to 2 hours. + Thus if clean task deletes 100 entries each time it will be executed + every second (minimum execution delay). But if current expired entries + amount is lower than previous one then execution delay will be increased + by 1.5 times. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Map local cache + + In case when a Map is used mostly for read operations and/or network + roundtrips are undesirable. Redisson offers RLocalCachedMap object which + caches Map entries on Redisson side. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + interface. + Keeps elements uniqueness via element state comparison. + ]]> + + + + + + + + + + + interface. + Keeps elements uniqueness via element state comparison. + ]]> + + + + + + + + + + + + + + + + + interface. + Keeps elements uniqueness via element state comparison. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Live distributed object (also abbreviated as live object) refers to a + running instance of a distributed multi-party (or peer-to-peer) protocol, + viewed from the object-oriented perspective, as an entity that has a + distinct identity, may encapsulate internal state and threads of + execution, and that exhibits a well-defined externally visible behavior. + + + Redisson Live Object (RLO) realised this idea by mapping all the fields + inside a Java class to a redis hash through a runtime-constructed proxy + class. All the get/set methods of each field are translated to hget/hset + commands operated on the redis hash, making it accessable to/from any + clients connected to the same redis server. As we all know, the field + values of an object represent its state; having them stored in a remote + repository, redis, makes it a distributed object. This object is a + Redisson Live Object. + + By using RLO, sharing an object between applications and/or servers is + the same as sharing one in a standalone application. This removes the + need for serialization and deserialization, and at the same time reduces + the complexity of the programming model: Changes made to one field + is (almost^) immediately accessable to other processes, applications and + servers. (^Redis' eventual consistant replication rule still applies + when connected to slave nodes) + + Since the redis server is a single-threaded application, all field + access to the live object is automatically executed in atomic fashion: a + value will not be changed when you are reading it. + + With RLO, you can treat the redis server as a shared Heap space for all + connected JVMs. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Define and create a Redisson instance. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Define and create a RedisClient instance. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceTest.java b/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceTest.java index 588dbbf24..c4e9d7ca0 100644 --- a/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceTest.java +++ b/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceTest.java @@ -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"); diff --git a/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceWikiTest.java b/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceWikiTest.java index 861955096..2d4c07f61 100644 --- a/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceWikiTest.java +++ b/redisson/src/test/java/org/redisson/spring/support/SpringNamespaceWikiTest.java @@ -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 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"); diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace.xml index 928ee1847..33e544be3 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace.xml @@ -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 "> diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_cluster.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_cluster.xml index 1689951e5..dd9957da7 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_cluster.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_cluster.xml @@ -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 "> @@ -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" > - - - + + + diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_master_slave.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_master_slave.xml index 12003cbe3..857cafea3 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_master_slave.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_master_slave.xml @@ -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 "> @@ -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" > - - + + diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_redis_client.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_redis_client.xml new file mode 100644 index 000000000..738fe02e0 --- /dev/null +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_redis_client.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_replicated.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_replicated.xml index 450ea9d98..bd8cbaa5b 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_replicated.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_replicated.xml @@ -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 "> @@ -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" > - - - + + + diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_sentinel.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_sentinel.xml index 49d188775..3389317f2 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_sentinel.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_sentinel.xml @@ -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 "> @@ -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" > - - + + diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single.xml index 4c49a82fe..a532b149d 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single.xml @@ -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 "> @@ -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" diff --git a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single_with_placeholder.xml b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single_with_placeholder.xml index 01962d373..fb73fcb7d 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single_with_placeholder.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/namespace_wiki_single_with_placeholder.xml @@ -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 "> @@ -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}" diff --git a/redisson/src/test/resources/org/redisson/spring/support/redisson_objects.xml b/redisson/src/test/resources/org/redisson/spring/support/redisson_objects.xml index 3e3b64504..925eccf26 100644 --- a/redisson/src/test/resources/org/redisson/spring/support/redisson_objects.xml +++ b/redisson/src/test/resources/org/redisson/spring/support/redisson_objects.xml @@ -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 ">