diff --git a/src/main/java/org/redisson/CommandExecutor.java b/src/main/java/org/redisson/CommandExecutor.java index 67bf29af0..a0c0da0af 100644 --- a/src/main/java/org/redisson/CommandExecutor.java +++ b/src/main/java/org/redisson/CommandExecutor.java @@ -33,6 +33,8 @@ import io.netty.util.concurrent.Future; //TODO ping support public interface CommandExecutor { + R read(RedisClient client, String key, Codec codec, RedisCommand command, Object ... params); + R read(RedisClient client, String key, RedisCommand command, Object ... params); Future evalWriteAllAsync(RedisCommand command, SlotCallback callback, String script, List keys, Object ... params); diff --git a/src/main/java/org/redisson/CommandExecutorService.java b/src/main/java/org/redisson/CommandExecutorService.java index d0929561f..85a0649e8 100644 --- a/src/main/java/org/redisson/CommandExecutorService.java +++ b/src/main/java/org/redisson/CommandExecutorService.java @@ -201,6 +201,12 @@ public class CommandExecutorService implements CommandExecutor { return get(res); } + public R read(RedisClient client, String key, Codec codec, RedisCommand command, Object ... params) { + Future res = readAsync(client, key, codec, command, params); + return get(res); + } + + public Future readAsync(RedisClient client, String key, Codec codec, RedisCommand command, Object ... params) { Promise mainPromise = connectionManager.newPromise(); int slot = connectionManager.calcSlot(key); diff --git a/src/main/java/org/redisson/Redisson.java b/src/main/java/org/redisson/Redisson.java index 7b78ac885..f97686a69 100755 --- a/src/main/java/org/redisson/Redisson.java +++ b/src/main/java/org/redisson/Redisson.java @@ -39,6 +39,7 @@ import org.redisson.core.RCountDownLatch; import org.redisson.core.RDeque; import org.redisson.core.RHyperLogLog; import org.redisson.core.RKeys; +import org.redisson.core.RLexSortedSet; import org.redisson.core.RList; import org.redisson.core.RLock; import org.redisson.core.RMap; @@ -221,6 +222,10 @@ public class Redisson implements RedissonClient { return new RedissonScoredSortedSet(commandExecutor, name); } + public RLexSortedSet getLexSortedSet(String name) { + return new RedissonLexSortedSet(commandExecutor, name); + } + /** * Returns topic instance by name. * diff --git a/src/main/java/org/redisson/RedissonClient.java b/src/main/java/org/redisson/RedissonClient.java index 3c3290d77..c8149529a 100755 --- a/src/main/java/org/redisson/RedissonClient.java +++ b/src/main/java/org/redisson/RedissonClient.java @@ -29,11 +29,13 @@ import org.redisson.core.RCountDownLatch; import org.redisson.core.RDeque; import org.redisson.core.RHyperLogLog; import org.redisson.core.RKeys; +import org.redisson.core.RLexSortedSet; import org.redisson.core.RList; import org.redisson.core.RLock; import org.redisson.core.RMap; import org.redisson.core.RPatternTopic; import org.redisson.core.RQueue; +import org.redisson.core.RScoredSortedSet; import org.redisson.core.RScript; import org.redisson.core.RSet; import org.redisson.core.RSortedSet; @@ -104,6 +106,10 @@ public interface RedissonClient { */ RSortedSet getSortedSet(String name); + RScoredSortedSet getScoredSortedSet(String name); + + RLexSortedSet getLexSortedSet(String name); + /** * Returns topic instance by name. * diff --git a/src/main/java/org/redisson/RedissonExpirable.java b/src/main/java/org/redisson/RedissonExpirable.java index 90b0ea801..d24a43649 100644 --- a/src/main/java/org/redisson/RedissonExpirable.java +++ b/src/main/java/org/redisson/RedissonExpirable.java @@ -18,6 +18,7 @@ package org.redisson; import java.util.Date; import java.util.concurrent.TimeUnit; +import org.redisson.client.codec.Codec; import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommands; import org.redisson.core.RExpirable; @@ -30,6 +31,10 @@ abstract class RedissonExpirable extends RedissonObject implements RExpirable { super(connectionManager, name); } + RedissonExpirable(Codec codec, CommandExecutor connectionManager, String name) { + super(codec, connectionManager, name); + } + @Override public boolean expire(long timeToLive, TimeUnit timeUnit) { return commandExecutor.get(expireAsync(timeToLive, timeUnit)); diff --git a/src/main/java/org/redisson/RedissonLexSortedSet.java b/src/main/java/org/redisson/RedissonLexSortedSet.java new file mode 100644 index 000000000..bfed02e91 --- /dev/null +++ b/src/main/java/org/redisson/RedissonLexSortedSet.java @@ -0,0 +1,142 @@ +/** + * Copyright 2014 Nikita Koksharov, Nickolay Borbit + * + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.redisson.client.codec.StringCodec; +import org.redisson.client.protocol.RedisCommands; +import org.redisson.core.RLexSortedSet; + +import io.netty.util.concurrent.Future; + +public class RedissonLexSortedSet extends RedissonScoredSortedSet implements RLexSortedSet { + + public RedissonLexSortedSet(CommandExecutor commandExecutor, String name) { + super(StringCodec.INSTANCE, commandExecutor, name); + } + + @Override + public Collection lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { + return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive)); + } + + @Override + public Collection lexRangeHead(String toElement, boolean toInclusive) { + return get(lexRangeHeadAsync(toElement, toInclusive)); + } + + @Override + public Future> lexRangeHeadAsync(String toElement, boolean toInclusive) { + String toValue = value(toElement, toInclusive); + return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue); + } + + @Override + public Collection lexRangeTail(String fromElement, boolean fromInclusive) { + return get(lexRangeTailAsync(fromElement, fromInclusive)); + } + + @Override + public Future> lexRangeTailAsync(String fromElement, boolean fromInclusive) { + String fromValue = value(fromElement, fromInclusive); + return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+"); + } + + + @Override + public Future> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { + String fromValue = value(fromElement, fromInclusive); + String toValue = value(toElement, toInclusive); + + return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue); + } + + @Override + public Integer lexCountTail(String fromElement, boolean fromInclusive) { + return get(lexCountTailAsync(fromElement, fromInclusive)); + } + + @Override + public Future lexCountTailAsync(String fromElement, boolean fromInclusive) { + String fromValue = value(fromElement, fromInclusive); + + return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), fromValue, "+"); + } + + @Override + public Integer lexCountHead(String toElement, boolean toInclusive) { + return get(lexCountHeadAsync(toElement, toInclusive)); + } + + @Override + public Future lexCountHeadAsync(String toElement, boolean toInclusive) { + String toValue = value(toElement, toInclusive); + + return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), "-", toValue); + } + + @Override + public Integer lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { + return get(lexCountAsync(fromElement, fromInclusive, toElement, toInclusive)); + } + + @Override + public Future lexCountAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { + String fromValue = value(fromElement, fromInclusive); + String toValue = value(toElement, toInclusive); + + return commandExecutor.readAsync(getName(), 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; + } + + @Override + public Future addAsync(String e) { + return addAsync(0, e); + } + + @Override + public Future addAllAsync(Collection c) { + List params = new ArrayList(2*c.size()); + for (Object param : c) { + params.add(0); + params.add(param); + } + return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZADD, getName(), params.toArray()); + } + + @Override + public boolean add(String e) { + return get(addAsync(e)); + } + + @Override + public boolean addAll(Collection c) { + return get(addAllAsync(c)); + } + +} diff --git a/src/main/java/org/redisson/RedissonList.java b/src/main/java/org/redisson/RedissonList.java index ab9385920..f4cd946c1 100644 --- a/src/main/java/org/redisson/RedissonList.java +++ b/src/main/java/org/redisson/RedissonList.java @@ -92,8 +92,7 @@ public class RedissonList extends RedissonExpirable implements RList { return (List) get(readAllAsync()); } - @Override - public Future> readAllAsync() { + private Future> readAllAsync() { return commandExecutor.readAsync(getName(), LRANGE, getName(), 0, -1); } diff --git a/src/main/java/org/redisson/RedissonObject.java b/src/main/java/org/redisson/RedissonObject.java index 23990c00e..bd661c1e1 100644 --- a/src/main/java/org/redisson/RedissonObject.java +++ b/src/main/java/org/redisson/RedissonObject.java @@ -15,6 +15,7 @@ */ package org.redisson; +import org.redisson.client.codec.Codec; import org.redisson.client.protocol.RedisCommands; import org.redisson.core.RObject; @@ -31,10 +32,16 @@ abstract class RedissonObject implements RObject { final CommandExecutor commandExecutor; private final String name; + final Codec codec; - public RedissonObject(CommandExecutor commandExecutor, String name) { - this.commandExecutor = commandExecutor; + public RedissonObject(Codec codec, CommandExecutor commandExecutor, String name) { + this.codec = codec; this.name = name; + this.commandExecutor = commandExecutor; + } + + public RedissonObject(CommandExecutor commandExecutor, String name) { + this(commandExecutor.getConnectionManager().getCodec(), commandExecutor, name); } protected V get(Future future) { diff --git a/src/main/java/org/redisson/RedissonScoredSortedSet.java b/src/main/java/org/redisson/RedissonScoredSortedSet.java index 106d4e16c..fbafd7478 100644 --- a/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.NoSuchElementException; import org.redisson.client.RedisClient; +import org.redisson.client.codec.Codec; import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommand; import org.redisson.client.protocol.RedisCommands; @@ -39,6 +40,10 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc super(commandExecutor, name); } + public RedissonScoredSortedSet(Codec codec, CommandExecutor commandExecutor, String name) { + super(codec, commandExecutor, name); + } + @Override public boolean add(double score, V object) { return get(addAsync(score, object)); @@ -46,11 +51,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future addAsync(double score, V object) { - // String should be encoded as String to let lex functions work properly - if (object instanceof String) { - return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZADD, getName(), BigDecimal.valueOf(score).toPlainString(), object); - } - return commandExecutor.writeAsync(getName(), RedisCommands.ZADD, getName(), BigDecimal.valueOf(score).toPlainString(), object); + return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZADD, getName(), BigDecimal.valueOf(score).toPlainString(), object); } @Override @@ -65,7 +66,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future removeAsync(Object object) { - return commandExecutor.writeAsync(getName(), RedisCommands.ZREM, getName(), object); + return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZREM, getName(), object); } @Override @@ -80,7 +81,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future sizeAsync() { - return commandExecutor.readAsync(getName(), RedisCommands.ZCARD, getName()); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZCARD, getName()); } @Override @@ -90,7 +91,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future containsAsync(Object o) { - return commandExecutor.readAsync(getName(), RedisCommands.ZSCORE_CONTAINS, getName(), o); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZSCORE_CONTAINS, getName(), o); } @Override @@ -100,7 +101,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future getScoreAsync(V o) { - return commandExecutor.readAsync(getName(), RedisCommands.ZSCORE, getName(), o); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZSCORE, getName(), o); } @Override @@ -110,11 +111,11 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future rankAsync(V o) { - return commandExecutor.readAsync(getName(), RedisCommands.ZRANK, getName(), o); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANK, getName(), o); } private ListScanResult scanIterator(RedisClient client, long startPos) { - return commandExecutor.read(client, getName(), RedisCommands.ZSCAN, getName(), startPos); + return commandExecutor.read(client, getName(), codec, RedisCommands.ZSCAN, getName(), startPos); } @Override @@ -187,7 +188,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future containsAllAsync(Collection c) { - return commandExecutor.evalReadAsync(getName(), new RedisCommand("EVAL", new BooleanReplayConvertor(), 4), + return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand("EVAL", new BooleanReplayConvertor(), 4), "local s = redis.call('zrange', KEYS[1], 0, -1);" + "for i = 0, table.getn(s), 1 do " + "for j = 0, table.getn(ARGV), 1 do " @@ -201,7 +202,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future removeAllAsync(Collection c) { - return commandExecutor.evalWriteAsync(getName(), new RedisCommand("EVAL", new BooleanReplayConvertor(), 4), + return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand("EVAL", new BooleanReplayConvertor(), 4), "local v = false " + "for i = 0, table.getn(ARGV), 1 do " + "if redis.call('zrem', KEYS[1], ARGV[i]) == 1 " @@ -223,7 +224,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future retainAllAsync(Collection c) { - return commandExecutor.evalWriteAsync(getName(), new RedisCommand("EVAL", new BooleanReplayConvertor(), 4), + return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand("EVAL", new BooleanReplayConvertor(), 4), "local changed = false " + "local s = redis.call('zrange', KEYS[1], 0, -1) " + "local i = 0 " @@ -264,7 +265,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future> valueRangeAsync(int startIndex, int endIndex) { - return commandExecutor.readAsync(getName(), RedisCommands.ZRANGE, getName(), startIndex, endIndex); + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGE, getName(), startIndex, endIndex); } @Override @@ -274,90 +275,7 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc @Override public Future>> entryRangeAsync(int startIndex, int endIndex) { - return commandExecutor.readAsync(getName(), RedisCommands.ZRANGE_ENTRY, getName(), startIndex, endIndex, "WITHSCORES"); - } - - @Override - public Collection lexRange(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive) { - return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive)); - } - - @Override - public Collection lexRangeHead(V toElement, boolean toInclusive) { - return get(lexRangeHeadAsync(toElement, toInclusive)); - } - - @Override - public Future> lexRangeHeadAsync(V toElement, boolean toInclusive) { - String toValue = value(toElement, toInclusive); - return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue); - } - - @Override - public Collection lexRangeTail(V fromElement, boolean fromInclusive) { - return get(lexRangeTailAsync(fromElement, fromInclusive)); - } - - @Override - public Future> lexRangeTailAsync(V fromElement, boolean fromInclusive) { - String fromValue = value(fromElement, fromInclusive); - return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+"); - } - - - @Override - public Future> lexRangeAsync(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive) { - String fromValue = value(fromElement, fromInclusive); - String toValue = value(toElement, toInclusive); - - return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue); - } - - @Override - public Integer lexCountTail(V fromElement, boolean fromInclusive) { - return get(lexCountTailAsync(fromElement, fromInclusive)); - } - - @Override - public Future lexCountTailAsync(V fromElement, boolean fromInclusive) { - String fromValue = value(fromElement, fromInclusive); - - return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), fromValue, "+"); - } - - @Override - public Integer lexCountHead(V toElement, boolean toInclusive) { - return get(lexCountHeadAsync(toElement, toInclusive)); - } - - @Override - public Future lexCountHeadAsync(V toElement, boolean toInclusive) { - String toValue = value(toElement, toInclusive); - - return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), "-", toValue); - } - - @Override - public Integer lexCount(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive) { - return get(lexCountAsync(fromElement, fromInclusive, toElement, toInclusive)); - } - - @Override - public Future lexCountAsync(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive) { - String fromValue = value(fromElement, fromInclusive); - String toValue = value(toElement, toInclusive); - - return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), fromValue, toValue); - } - - private String value(V fromElement, boolean fromInclusive) { - String fromValue = fromElement.toString(); - if (fromInclusive) { - fromValue = "[" + fromValue; - } else { - fromValue = "(" + fromValue; - } - return fromValue; + return commandExecutor.readAsync(getName(), codec, RedisCommands.ZRANGE_ENTRY, getName(), startIndex, endIndex, "WITHSCORES"); } } diff --git a/src/main/java/org/redisson/RedissonSet.java b/src/main/java/org/redisson/RedissonSet.java index 6e2a94400..7a38567e0 100644 --- a/src/main/java/org/redisson/RedissonSet.java +++ b/src/main/java/org/redisson/RedissonSet.java @@ -127,8 +127,7 @@ public class RedissonSet extends RedissonExpirable implements RSet { }; } - @Override - public Future> readAllAsync() { + private Future> readAllAsync() { return commandExecutor.readAsync(getName(), RedisCommands.SMEMBERS, getName()); } diff --git a/src/main/java/org/redisson/client/protocol/RedisCommands.java b/src/main/java/org/redisson/client/protocol/RedisCommands.java index 0fc389ce5..177933b9d 100644 --- a/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -54,7 +54,7 @@ public interface RedisCommands { RedisStrictCommand ZLEXCOUNT = new RedisStrictCommand("ZLEXCOUNT", new IntegerReplayConvertor()); RedisCommand ZSCORE_CONTAINS = new RedisCommand("ZSCORE", new BooleanNotNullReplayConvertor(), 2); RedisStrictCommand ZSCORE = new RedisStrictCommand("ZSCORE", new DoubleReplayConvertor()); - RedisStrictCommand ZRANK = new RedisStrictCommand("ZRANK", new IntegerReplayConvertor()); + RedisCommand ZRANK = new RedisCommand("ZRANK", new IntegerReplayConvertor(), 2); RedisCommand> ZRANGE = new RedisCommand>("ZRANGE", new ObjectListReplayDecoder()); RedisCommand> ZRANGEBYLEX = new RedisCommand>("ZRANGEBYLEX", new ObjectListReplayDecoder()); RedisCommand>> ZRANGE_ENTRY = new RedisCommand>>("ZRANGE", new ScoredSortedSetReplayDecoder()); diff --git a/src/main/java/org/redisson/client/protocol/convertor/IntegerReplayConvertor.java b/src/main/java/org/redisson/client/protocol/convertor/IntegerReplayConvertor.java index 647f3aaf3..11529a0be 100644 --- a/src/main/java/org/redisson/client/protocol/convertor/IntegerReplayConvertor.java +++ b/src/main/java/org/redisson/client/protocol/convertor/IntegerReplayConvertor.java @@ -19,6 +19,9 @@ public class IntegerReplayConvertor extends SingleConvertor { @Override public Integer convert(Object obj) { + if (obj == null) { + return null; + } return ((Long) obj).intValue(); } diff --git a/src/main/java/org/redisson/core/RCollectionAsync.java b/src/main/java/org/redisson/core/RCollectionAsync.java index e1fe641d2..239f8dbae 100644 --- a/src/main/java/org/redisson/core/RCollectionAsync.java +++ b/src/main/java/org/redisson/core/RCollectionAsync.java @@ -31,8 +31,6 @@ public interface RCollectionAsync extends RExpirableAsync { Future removeAsync(Object o); - Future> readAllAsync(); - Future sizeAsync(); Future addAsync(V e); diff --git a/src/main/java/org/redisson/core/RLexSortedSet.java b/src/main/java/org/redisson/core/RLexSortedSet.java new file mode 100644 index 000000000..2a02eec3b --- /dev/null +++ b/src/main/java/org/redisson/core/RLexSortedSet.java @@ -0,0 +1,39 @@ +/** + * Copyright 2014 Nikita Koksharov, Nickolay Borbit + * + * 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.core; + +import java.util.Collection; +import java.util.Set; + +public interface RLexSortedSet extends RLexSortedSetAsync, Set, RExpirable { + + Integer lexCountTail(String fromElement, boolean fromInclusive); + + Integer lexCountHead(String toElement, boolean toInclusive); + + Collection lexRangeTail(String fromElement, boolean fromInclusive); + + Collection lexRangeHead(String toElement, boolean toInclusive); + + Collection lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + + Integer lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + + Integer rank(String o); + + Collection valueRange(int startIndex, int endIndex); + +} diff --git a/src/main/java/org/redisson/core/RLexSortedSetAsync.java b/src/main/java/org/redisson/core/RLexSortedSetAsync.java new file mode 100644 index 000000000..9e705caa1 --- /dev/null +++ b/src/main/java/org/redisson/core/RLexSortedSetAsync.java @@ -0,0 +1,40 @@ +/** + * Copyright 2014 Nikita Koksharov, Nickolay Borbit + * + * 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.core; + +import java.util.Collection; + +import io.netty.util.concurrent.Future; + +public interface RLexSortedSetAsync extends RCollectionAsync { + + Future lexCountTailAsync(String fromElement, boolean fromInclusive); + + Future lexCountHeadAsync(String toElement, boolean toInclusive); + + Future> lexRangeTailAsync(String fromElement, boolean fromInclusive); + + Future> lexRangeHeadAsync(String toElement, boolean toInclusive); + + Future> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + + Future lexCountAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive); + + Future rankAsync(String o); + + Future> valueRangeAsync(int startIndex, int endIndex); + +} diff --git a/src/main/java/org/redisson/core/RScoredSortedSet.java b/src/main/java/org/redisson/core/RScoredSortedSet.java index 6b48b816c..c000b362a 100644 --- a/src/main/java/org/redisson/core/RScoredSortedSet.java +++ b/src/main/java/org/redisson/core/RScoredSortedSet.java @@ -21,18 +21,6 @@ import org.redisson.client.protocol.ScoredEntry; public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable, RExpirable { - Integer lexCountTail(V fromElement, boolean fromInclusive); - - Integer lexCountHead(V toElement, boolean toInclusive); - - Collection lexRangeTail(V fromElement, boolean fromInclusive); - - Collection lexRangeHead(V toElement, boolean toInclusive); - - Collection lexRange(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive); - - Integer lexCount(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive); - Integer rank(V o); Double getScore(V o); diff --git a/src/main/java/org/redisson/core/RScoredSortedSetAsync.java b/src/main/java/org/redisson/core/RScoredSortedSetAsync.java index 9af7b60d5..644eb7c53 100644 --- a/src/main/java/org/redisson/core/RScoredSortedSetAsync.java +++ b/src/main/java/org/redisson/core/RScoredSortedSetAsync.java @@ -23,18 +23,6 @@ import io.netty.util.concurrent.Future; public interface RScoredSortedSetAsync extends RExpirableAsync { - Future lexCountTailAsync(V fromElement, boolean fromInclusive); - - Future lexCountHeadAsync(V toElement, boolean toInclusive); - - Future> lexRangeTailAsync(V fromElement, boolean fromInclusive); - - Future> lexRangeHeadAsync(V toElement, boolean toInclusive); - - Future> lexRangeAsync(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive); - - Future lexCountAsync(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive); - Future rankAsync(V o); Future getScoreAsync(V o); diff --git a/src/test/java/org/redisson/RedissonScoredSortedSetTest.java b/src/test/java/org/redisson/RedissonScoredSortedSetTest.java index 33319a425..0a8d14134 100644 --- a/src/test/java/org/redisson/RedissonScoredSortedSetTest.java +++ b/src/test/java/org/redisson/RedissonScoredSortedSetTest.java @@ -21,52 +21,6 @@ import io.netty.util.concurrent.Future; public class RedissonScoredSortedSetTest extends BaseTest { - @Test - public void testLexRangeTail() { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); - set.add(0, "a"); - set.add(0, "b"); - set.add(0, "c"); - set.add(0, "d"); - set.add(0, "e"); - set.add(0, "f"); - set.add(0, "g"); - - MatcherAssert.assertThat(set.lexRangeTail("c", false), Matchers.contains("d", "e", "f", "g")); - MatcherAssert.assertThat(set.lexRangeTail("c", true), Matchers.contains("c", "d", "e", "f", "g")); - } - - - @Test - public void testLexRangeHead() { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); - set.add(0, "a"); - set.add(0, "b"); - set.add(0, "c"); - set.add(0, "d"); - set.add(0, "e"); - set.add(0, "f"); - set.add(0, "g"); - - MatcherAssert.assertThat(set.lexRangeHead("c", false), Matchers.contains("a", "b")); - MatcherAssert.assertThat(set.lexRangeHead("c", true), Matchers.contains("a", "b", "c")); - } - - - @Test - public void testLexRange() { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); - set.add(0, "a"); - set.add(0, "b"); - set.add(0, "c"); - set.add(0, "d"); - set.add(0, "e"); - set.add(0, "f"); - set.add(0, "g"); - - MatcherAssert.assertThat(set.lexRange("aaa", true, "g", false), Matchers.contains("b", "c", "d", "e", "f")); - } - @Test public void testRank() { RScoredSortedSet set = redisson.getScoredSortedSet("simple"); @@ -81,21 +35,6 @@ public class RedissonScoredSortedSetTest extends BaseTest { Assert.assertEquals(3, (int)set.rank("d")); } - @Test - public void testLexCount() { - RScoredSortedSet set = redisson.getScoredSortedSet("simple"); - set.add(0, "a"); - set.add(0, "b"); - set.add(0, "c"); - set.add(0, "d"); - set.add(0, "e"); - set.add(0, "f"); - set.add(0, "g"); - - Assert.assertEquals(5, (int)set.lexCount("b", true, "f", true)); - Assert.assertEquals(3, (int)set.lexCount("b", false, "f", false)); - } - @Test public void testAddAsync() throws InterruptedException, ExecutionException { RScoredSortedSet set = redisson.getScoredSortedSet("simple");