diff --git a/README.md b/README.md index d61ec766a..20c7d158d 100644 --- a/README.md +++ b/README.md @@ -68,14 +68,16 @@ Used by [![OptionsHouse](https://redisson.org/assets/logos/client9.png "OptionsHouse")](https://www.optionshouse.com/)     [![Invaluable](https://redisson.org/assets/logos/client13.png "Invaluable")](http://www.invaluable.com/) [![Ticketmaster](https://redisson.org/assets/logos/client14.png "Ticketmaster")](http://www.ticketmaster.com/)    -[![PANDORA](https://redisson.org/assets/logos/client15.png "PANDORA")](http://www.pandora.com/) +[![PANDORA](https://redisson.org/assets/logos/client15.png "PANDORA")](http://www.pandora.com/)    +[![ContaAzul](https://redisson.org/assets/logos/client18.png "ContaAzul")](https://contaazul.com/) [![SULAKE](https://redisson.org/assets/logos/client17.png "SULAKE")](http://www.sulake.com/) Success stories ================================ -[Moving from Hazelcast to Redis](https://engineering.datorama.com/moving-from-hazelcast-to-redis-b90a0769d1cb) +[Moving from Hazelcast to Redis / Datorama](https://engineering.datorama.com/moving-from-hazelcast-to-redis-b90a0769d1cb) +[Distributed Locking with Redis (Migration from Hazelcast) / ContaAzul](https://carlosbecker.com/posts/distributed-locks-redis/) Quick start =============================== diff --git a/redisson/src/main/java/org/redisson/RedissonMapCache.java b/redisson/src/main/java/org/redisson/RedissonMapCache.java index 2c01ae9fa..482769042 100644 --- a/redisson/src/main/java/org/redisson/RedissonMapCache.java +++ b/redisson/src/main/java/org/redisson/RedissonMapCache.java @@ -228,10 +228,11 @@ public class RedissonMapCache extends RedissonMap implements RMapCac "local expireHead = redis.call('zrange', KEYS[2], 0, 0, 'withscores'); " + "local currentTime = tonumber(table.remove(ARGV, 1)); " + // index is the first parameter "local hasExpire = #expireHead == 2 and tonumber(expireHead[2]) <= currentTime; " + - "local map = redis.call('hmget', KEYS[1], unpack(ARGV)); " + "local maxSize = tonumber(redis.call('hget', KEYS[5], 'max-size'));" + - "for i = #map, 1, -1 do " + - " local value = map[i]; " + + "local map = {}; " + + "for i = 1, #ARGV, 1 do " + + " local value = redis.call('hget', KEYS[1], ARGV[i]); " + + " map[i] = false;" + " if value ~= false then " + " local key = ARGV[i]; " + " local t, val = struct.unpack('dLc0', value); " + diff --git a/redisson/src/main/java/org/redisson/client/RedisClient.java b/redisson/src/main/java/org/redisson/client/RedisClient.java index ce0e0b9d8..f9fe56c2e 100644 --- a/redisson/src/main/java/org/redisson/client/RedisClient.java +++ b/redisson/src/main/java/org/redisson/client/RedisClient.java @@ -57,7 +57,7 @@ public class RedisClient { private final Bootstrap bootstrap; private final Bootstrap pubSubBootstrap; private final InetSocketAddress addr; - private final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); + private final ChannelGroup channels; private ExecutorService executor; private final long commandTimeout; @@ -81,6 +81,7 @@ public class RedisClient { bootstrap = createBootstrap(config, Type.PLAIN); pubSubBootstrap = createBootstrap(config, Type.PUBSUB); + channels = new DefaultChannelGroup(config.getGroup().next()); this.commandTimeout = config.getCommandTimeout(); } @@ -171,6 +172,7 @@ public class RedisClient { bootstrap = createBootstrap(config, Type.PLAIN); pubSubBootstrap = createBootstrap(config, Type.PUBSUB); + channels = new DefaultChannelGroup(config.getGroup().next()); this.commandTimeout = config.getCommandTimeout(); } diff --git a/redisson/src/main/java/org/redisson/client/protocol/decoder/TTLMapValueReplayDecoder.java b/redisson/src/main/java/org/redisson/client/protocol/decoder/TTLMapValueReplayDecoder.java deleted file mode 100644 index 038b28bf3..000000000 --- a/redisson/src/main/java/org/redisson/client/protocol/decoder/TTLMapValueReplayDecoder.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.client.protocol.decoder; - -import java.util.List; - -import org.redisson.client.handler.State; - -import io.netty.buffer.ByteBuf; -import io.netty.util.CharsetUtil; - -/** - * - * @author Nikita Koksharov - * - * @param type - */ -public class TTLMapValueReplayDecoder implements MultiDecoder> { - - @Override - public Object decode(ByteBuf buf, State state) { - return Long.valueOf(buf.toString(CharsetUtil.UTF_8)); - } - - @Override - public List decode(List parts, State state) { - return (List) parts; - } - - @Override - public boolean isApplicable(int paramNum, State state) { - return paramNum == 0; - } - -} diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index 4eb0a1977..7f529b3d9 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -56,7 +56,6 @@ import org.slf4j.LoggerFactory; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; -import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.ScheduledFuture; import io.netty.util.internal.PlatformDependent; @@ -298,7 +297,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } private void scheduleClusterChangeCheck(final ClusterServersConfig cfg, final Iterator iterator) { - monitorFuture = GlobalEventExecutor.INSTANCE.schedule(new Runnable() { + monitorFuture = group.schedule(new Runnable() { @Override public void run() { AtomicReference lastException = new AtomicReference(); diff --git a/redisson/src/main/java/org/redisson/connection/DNSMonitor.java b/redisson/src/main/java/org/redisson/connection/DNSMonitor.java index 6e513a0ed..b49665236 100644 --- a/redisson/src/main/java/org/redisson/connection/DNSMonitor.java +++ b/redisson/src/main/java/org/redisson/connection/DNSMonitor.java @@ -30,7 +30,6 @@ import org.redisson.misc.URIBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.ScheduledFuture; /** @@ -83,7 +82,7 @@ public class DNSMonitor { } private void monitorDnsChange() { - dnsMonitorFuture = GlobalEventExecutor.INSTANCE.schedule(new Runnable() { + dnsMonitorFuture = connectionManager.getGroup().schedule(new Runnable() { @Override public void run() { // As InetAddress.getByName call is blocking. Method should be run in dedicated thread diff --git a/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java b/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java index 8882f1df6..8358211df 100644 --- a/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java @@ -39,7 +39,6 @@ import org.slf4j.LoggerFactory; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; -import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.ScheduledFuture; /** @@ -145,7 +144,7 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager { } private void scheduleMasterChangeCheck(final ReplicatedServersConfig cfg) { - monitorFuture = GlobalEventExecutor.INSTANCE.schedule(new Runnable() { + monitorFuture = group.schedule(new Runnable() { @Override public void run() { final URI master = currentMaster.get(); diff --git a/redisson/src/main/java/org/redisson/connection/decoder/CacheGetAllDecoder.java b/redisson/src/main/java/org/redisson/connection/decoder/CacheGetAllDecoder.java deleted file mode 100644 index 996dc1f52..000000000 --- a/redisson/src/main/java/org/redisson/connection/decoder/CacheGetAllDecoder.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * 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.connection.decoder; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.redisson.client.codec.LongCodec; -import org.redisson.client.handler.State; -import org.redisson.client.protocol.decoder.MultiDecoder; - -import io.netty.buffer.ByteBuf; - -/** - * - * @author Nikita Koksharov - * - */ -public class CacheGetAllDecoder implements MultiDecoder> { - - private final List args; - - public CacheGetAllDecoder(List args) { - this.args = args; - } - - @Override - public Object decode(ByteBuf buf, State state) throws IOException { - return LongCodec.INSTANCE.getValueDecoder().decode(buf, state); - } - - @Override - public boolean isApplicable(int paramNum, State state) { - return paramNum == 0; - } - - @Override - public List decode(List parts, State state) { - List result = new ArrayList(); - Map map = new HashMap(parts.size()); - for (int index = 0; index < args.size()-1; index++) { - Object value = parts.get(index+1); - if (value == null) { - continue; - } - map.put(args.get(index+1), value); - } - result.add(parts.get(0)); - result.add(map); - return result; - } - -} diff --git a/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java b/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java index 5c3fc3191..36ab07e08 100644 --- a/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java +++ b/redisson/src/test/java/org/redisson/RedissonMapCacheTest.java @@ -403,6 +403,23 @@ public class RedissonMapCacheTest extends BaseMapTest { assertThat(map.values()).containsOnly("5678"); } + @Test + public void testGetAllBig() { + Map joinMap = new HashMap(); + for (int i = 0; i < 10000; i++) { + joinMap.put(i, "" + i); + } + + RMap map = redisson.getMapCache("simple"); + map.putAll(joinMap); + + Map s = map.getAll(joinMap.keySet()); + assertThat(s).isEqualTo(joinMap); + + assertThat(map.size()).isEqualTo(joinMap.size()); + } + + @Test public void testGetAll() throws InterruptedException { RMapCache map = redisson.getMapCache("getAll");