diff --git a/redisson-all/pom.xml b/redisson-all/pom.xml index aed907188..062db09a2 100644 --- a/redisson-all/pom.xml +++ b/redisson-all/pom.xml @@ -87,7 +87,7 @@ io.netty netty-transport-native-epoll linux-x86_64 - 4.1.12.Final + 4.1.13.Final com.esotericsoftware @@ -103,19 +103,19 @@ com.fasterxml.jackson.dataformat jackson-dataformat-cbor - 2.7.6 + 2.7.9 provided com.fasterxml.jackson.dataformat jackson-dataformat-smile - 2.7.6 + 2.7.9 provided com.fasterxml.jackson.dataformat jackson-dataformat-avro - 2.7.6 + 2.7.9 provided diff --git a/redisson/pom.xml b/redisson/pom.xml index 3c1e473bc..9c9659de0 100644 --- a/redisson/pom.xml +++ b/redisson/pom.xml @@ -34,33 +34,33 @@ io.netty netty-transport-native-epoll - 4.1.12.Final + 4.1.13.Final provided io.netty netty-common - 4.1.12.Final + 4.1.13.Final io.netty netty-codec - 4.1.12.Final + 4.1.13.Final io.netty netty-buffer - 4.1.12.Final + 4.1.13.Final io.netty netty-transport - 4.1.12.Final + 4.1.13.Final io.netty netty-handler - 4.1.12.Final + 4.1.13.Final @@ -186,17 +186,17 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml - 2.7.6 + 2.7.9 com.fasterxml.jackson.core jackson-core - 2.7.6 + 2.7.9 com.fasterxml.jackson.core jackson-databind - 2.7.6 + 2.7.9 @@ -209,21 +209,21 @@ com.fasterxml.jackson.dataformat jackson-dataformat-cbor - 2.7.6 + 2.7.9 provided true com.fasterxml.jackson.dataformat jackson-dataformat-smile - 2.7.6 + 2.7.9 provided true com.fasterxml.jackson.dataformat jackson-dataformat-avro - 2.7.6 + 2.7.9 provided true @@ -235,7 +235,7 @@ net.bytebuddy byte-buddy - 1.6.8 + 1.6.14 org.jodd diff --git a/redisson/src/main/java/org/redisson/api/RLexSortedSetReactive.java b/redisson/src/main/java/org/redisson/api/RLexSortedSetReactive.java index 749b7d9e4..6a80b296b 100644 --- a/redisson/src/main/java/org/redisson/api/RLexSortedSetReactive.java +++ b/redisson/src/main/java/org/redisson/api/RLexSortedSetReactive.java @@ -19,34 +19,32 @@ import java.util.Collection; import org.reactivestreams.Publisher; -public interface RLexSortedSetReactive extends RCollectionReactive { +public interface RLexSortedSetReactive extends RScoredSortedSetReactive, RCollectionReactive { - Publisher removeRangeByLex(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + Publisher removeRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); - Publisher removeRangeTailByLex(String fromElement, boolean fromInclusive); + Publisher removeRangeTail(String fromElement, boolean fromInclusive); - Publisher removeRangeHeadByLex(String toElement, boolean toInclusive); + Publisher removeRangeHead(String toElement, boolean toInclusive); - Publisher lexCountTail(String fromElement, boolean fromInclusive); + Publisher countTail(String fromElement, boolean fromInclusive); - Publisher lexCountHead(String toElement, boolean toInclusive); + Publisher countHead(String toElement, boolean toInclusive); - Publisher> lexRangeTail(String fromElement, boolean fromInclusive); + Publisher> rangeTail(String fromElement, boolean fromInclusive); - Publisher> lexRangeHead(String toElement, boolean toInclusive); + Publisher> rangeHead(String toElement, boolean toInclusive); - Publisher> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + Publisher> range(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); - Publisher> lexRangeTail(String fromElement, boolean fromInclusive, int offset, int count); + Publisher> rangeTail(String fromElement, boolean fromInclusive, int offset, int count); - Publisher> lexRangeHead(String toElement, boolean toInclusive, int offset, int count); + Publisher> rangeHead(String toElement, boolean toInclusive, int offset, int count); - Publisher> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count); + Publisher> range(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count); - Publisher lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + Publisher count(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); - Publisher rank(String o); - - Publisher> valueRange(int startIndex, int endIndex); + Publisher> range(int startIndex, int endIndex); } diff --git a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java index be3dbfc2a..85c569237 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -103,6 +103,7 @@ public interface RedisCommands { RedisCommand ZADD_NX_BOOL = new RedisCommand("ZADD", new BooleanAmountReplayConvertor(), 4); RedisCommand ZADD_BOOL_RAW = new RedisCommand("ZADD", new BooleanAmountReplayConvertor()); RedisCommand ZADD_RAW = new RedisCommand("ZADD"); + RedisStrictCommand ZADD_INT = new RedisStrictCommand("ZADD", new IntegerReplayConvertor()); RedisCommand ZADD = new RedisCommand("ZADD"); RedisCommand ZREM = new RedisCommand("ZREM", new BooleanAmountReplayConvertor(), 2, ValueType.OBJECTS); RedisStrictCommand ZCARD_INT = new RedisStrictCommand("ZCARD", new IntegerReplayConvertor()); diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonLexSortedSetReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonLexSortedSetReactive.java index 32492d561..6ae236ffc 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonLexSortedSetReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonLexSortedSetReactive.java @@ -20,11 +20,16 @@ import java.util.Collection; import java.util.List; import org.reactivestreams.Publisher; +import org.redisson.RedissonLexSortedSet; +import org.redisson.api.RFuture; +import org.redisson.api.RLexSortedSetAsync; import org.redisson.api.RLexSortedSetReactive; import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommands; import org.redisson.command.CommandReactiveExecutor; +import reactor.fn.Supplier; + /** * * @author Nikita Koksharov @@ -32,8 +37,11 @@ import org.redisson.command.CommandReactiveExecutor; */ public class RedissonLexSortedSetReactive extends RedissonScoredSortedSetReactive implements RLexSortedSetReactive { + private final RLexSortedSetAsync instance; + public RedissonLexSortedSetReactive(CommandReactiveExecutor commandExecutor, String name) { super(StringCodec.INSTANCE, commandExecutor, name); + instance = new RedissonLexSortedSet(commandExecutor, name, null); } @Override @@ -42,101 +50,128 @@ public class RedissonLexSortedSetReactive extends RedissonScoredSortedSetReactiv } @Override - public Publisher removeRangeHeadByLex(String toElement, boolean toInclusive) { - String toValue = value(toElement, toInclusive); - return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), "-", toValue); + public Publisher removeRangeHead(final String toElement, final boolean toInclusive) { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.removeRangeHeadAsync(toElement, toInclusive); + } + }); } @Override - public Publisher removeRangeTailByLex(String fromElement, boolean fromInclusive) { - String fromValue = value(fromElement, fromInclusive); - return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, "+"); + public Publisher removeRangeTail(final String fromElement, final boolean fromInclusive) { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.removeRangeTailAsync(fromElement, fromInclusive); + } + }); } @Override - public Publisher removeRangeByLex(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { - String fromValue = value(fromElement, fromInclusive); - String toValue = value(toElement, toInclusive); - - return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, toValue); + public Publisher removeRange(final String fromElement, final boolean fromInclusive, final String toElement, final boolean toInclusive) { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.removeRangeAsync(fromElement, fromInclusive, toElement, toInclusive); + } + }); } @Override - public Publisher> lexRangeHead(String toElement, boolean toInclusive) { - String toValue = value(toElement, toInclusive); - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue); + public Publisher> rangeHead(final String toElement, final boolean toInclusive) { + return reactive(new Supplier>>() { + @Override + public RFuture> get() { + return instance.rangeHeadAsync(toElement, toInclusive); + } + }); } @Override - public Publisher> lexRangeTail(String fromElement, boolean fromInclusive) { - String fromValue = value(fromElement, fromInclusive); - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+"); + public Publisher> rangeTail(final String fromElement, final boolean fromInclusive) { + return reactive(new Supplier>>() { + @Override + public RFuture> get() { + return instance.rangeTailAsync(fromElement, fromInclusive); + } + }); } - @Override - public Publisher> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { - String fromValue = value(fromElement, fromInclusive); - String toValue = value(toElement, toInclusive); - - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue); + public Publisher> range(final String fromElement, final boolean fromInclusive, final String toElement, final boolean toInclusive) { + return reactive(new Supplier>>() { + @Override + public RFuture> get() { + return instance.rangeAsync(fromElement, fromInclusive, toElement, toInclusive); + } + }); } @Override - public Publisher> lexRangeHead(String toElement, boolean toInclusive, int offset, int count) { - String toValue = value(toElement, toInclusive); - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue, "LIMIT", offset, count); + public Publisher> rangeHead(final String toElement, final boolean toInclusive, final int offset, final int count) { + return reactive(new Supplier>>() { + @Override + public RFuture> get() { + return instance.rangeHeadAsync(toElement, toInclusive, offset, count); + } + }); } @Override - public Publisher> lexRangeTail(String fromElement, boolean fromInclusive, int offset, int count) { - String fromValue = value(fromElement, fromInclusive); - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+", "LIMIT", offset, count); + public Publisher> rangeTail(final String fromElement, final boolean fromInclusive, final int offset, final int count) { + return reactive(new Supplier>>() { + @Override + public RFuture> get() { + return instance.rangeTailAsync(fromElement, fromInclusive, offset, count); + } + }); } @Override - public Publisher> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count) { - String fromValue = value(fromElement, fromInclusive); - String toValue = value(toElement, toInclusive); - - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue, "LIMIT", offset, count); + public Publisher> range(final String fromElement, final boolean fromInclusive, final String toElement, final boolean toInclusive, final int offset, final int count) { + return reactive(new Supplier>>() { + @Override + public RFuture> get() { + return instance.rangeAsync(fromElement, fromInclusive, toElement, toInclusive, offset, count); + } + }); } @Override - public Publisher lexCountTail(String fromElement, boolean fromInclusive) { - String fromValue = value(fromElement, fromInclusive); - - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZLEXCOUNT, getName(), fromValue, "+"); + public Publisher countTail(final String fromElement, final boolean fromInclusive) { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.countTailAsync(fromElement, fromInclusive); + } + }); } @Override - public Publisher lexCountHead(String toElement, boolean toInclusive) { - String toValue = value(toElement, toInclusive); - - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZLEXCOUNT, getName(), "-", toValue); + public Publisher countHead(final String toElement, final boolean toInclusive) { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.countHeadAsync(toElement, toInclusive); + } + }); } @Override - public Publisher lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { - String fromValue = value(fromElement, fromInclusive); - String toValue = value(toElement, toInclusive); - - return commandExecutor.readReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZLEXCOUNT, getName(), fromValue, toValue); - } - - private String value(String fromElement, boolean fromInclusive) { - String fromValue = fromElement.toString(); - if (fromInclusive) { - fromValue = "[" + fromValue; - } else { - fromValue = "(" + fromValue; - } - return fromValue; + public Publisher count(final String fromElement, final boolean fromInclusive, final String toElement, final boolean toInclusive) { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.countAsync(fromElement, fromInclusive, toElement, toInclusive); + } + }); } @Override - public Publisher add(String e) { - return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZADD_RAW, getName(), 0, e); + public Publisher add(final String e) { + return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZADD_INT, getName(), 0, e); } @Override @@ -146,7 +181,12 @@ public class RedissonLexSortedSetReactive extends RedissonScoredSortedSetReactiv params.add(0); params.add(param); } - return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZADD_RAW, getName(), params.toArray()); + return commandExecutor.writeReactive(getName(), StringCodec.INSTANCE, RedisCommands.ZADD_INT, getName(), params.toArray()); + } + + @Override + public Publisher> range(int startIndex, int endIndex) { + return valueRange(startIndex, endIndex); } } diff --git a/redisson/src/test/java/org/redisson/RedissonLexSortedSetReactiveTest.java b/redisson/src/test/java/org/redisson/RedissonLexSortedSetReactiveTest.java index 20255ebe1..250d4f36d 100644 --- a/redisson/src/test/java/org/redisson/RedissonLexSortedSetReactiveTest.java +++ b/redisson/src/test/java/org/redisson/RedissonLexSortedSetReactiveTest.java @@ -1,12 +1,20 @@ package org.redisson; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Assert; import org.junit.Test; import org.redisson.api.RLexSortedSetReactive; +import reactor.rx.Streams; + public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { + public static Iterable sync(RLexSortedSetReactive list) { + return (Iterable) Streams.create(list.iterator()).toList().poll(); + } + + @Test public void testAddAllReactive() { RLexSortedSetReactive list = redisson.getLexSortedSet("set"); @@ -33,11 +41,11 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { Assert.assertTrue(sync(set.add("f")) == 1); Assert.assertTrue(sync(set.add("g")) == 1); - Assert.assertEquals(0, sync(set.removeRangeTailByLex("z", false)).intValue()); + Assert.assertEquals(0, sync(set.removeRangeTail("z", false)).intValue()); - Assert.assertEquals(4, sync(set.removeRangeTailByLex("c", false)).intValue()); + Assert.assertEquals(4, sync(set.removeRangeTail("c", false)).intValue()); assertThat(sync(set)).containsExactly("a", "b", "c"); - Assert.assertEquals(1, sync(set.removeRangeTailByLex("c", true)).intValue()); + Assert.assertEquals(1, sync(set.removeRangeTail("c", true)).intValue()); assertThat(sync(set)).containsExactly("a", "b"); } @@ -53,9 +61,9 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { sync(set.add("f")); sync(set.add("g")); - Assert.assertEquals(2, sync(set.removeRangeHeadByLex("c", false)).intValue()); + Assert.assertEquals(2, sync(set.removeRangeHead("c", false)).intValue()); assertThat(sync(set)).containsExactly("c", "d", "e", "f", "g"); - Assert.assertEquals(1, (int)sync(set.removeRangeHeadByLex("c", true))); + Assert.assertEquals(1, (int)sync(set.removeRangeHead("c", true))); assertThat(sync(set)).containsExactly("d", "e", "f", "g"); } @@ -70,7 +78,7 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { sync(set.add("f")); sync(set.add("g")); - Assert.assertEquals(5, sync(set.removeRangeByLex("aaa", true, "g", false)).intValue()); + Assert.assertEquals(5, sync(set.removeRange("aaa", true, "g", false)).intValue()); assertThat(sync(set)).containsExactly("a", "g"); } @@ -87,8 +95,8 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { Assert.assertTrue(sync(set.add("f")) == 1); Assert.assertTrue(sync(set.add("g")) == 1); - assertThat(sync(set.lexRangeTail("c", false))).containsExactly("d", "e", "f", "g"); - assertThat(sync(set.lexRangeTail("c", true))).containsExactly("c", "d", "e", "f", "g"); + assertThat(sync(set.rangeTail("c", false))).containsExactly("d", "e", "f", "g"); + assertThat(sync(set.rangeTail("c", true))).containsExactly("c", "d", "e", "f", "g"); } @@ -103,8 +111,8 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { sync(set.add("f")); sync(set.add("g")); - assertThat(sync(set.lexRangeHead("c", false))).containsExactly("a", "b"); - assertThat(sync(set.lexRangeHead("c", true))).containsExactly("a", "b", "c"); + assertThat(sync(set.rangeHead("c", false))).containsExactly("a", "b"); + assertThat(sync(set.rangeHead("c", true))).containsExactly("a", "b", "c"); } @@ -119,7 +127,7 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { sync(set.add("f")); sync(set.add("g")); - assertThat(sync(set.lexRange("aaa", true, "g", false))).contains("b", "c", "d", "e", "f"); + assertThat(sync(set.range("aaa", true, "g", false))).contains("b", "c", "d", "e", "f"); } @Test @@ -133,8 +141,8 @@ public class RedissonLexSortedSetReactiveTest extends BaseReactiveTest { sync(set.add("f")); sync(set.add("g")); - Assert.assertEquals(5, (int)sync(set.lexCount("b", true, "f", true))); - Assert.assertEquals(3, (int)sync(set.lexCount("b", false, "f", false))); + Assert.assertEquals(5, (int)sync(set.count("b", true, "f", true))); + Assert.assertEquals(3, (int)sync(set.count("b", false, "f", false))); } }