RLexSortedSet object introduced. #135
parent
3ab7e1afc8
commit
1bfc3a7a13
@ -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<String> implements RLexSortedSet {
|
||||
|
||||
public RedissonLexSortedSet(CommandExecutor commandExecutor, String name) {
|
||||
super(StringCodec.INSTANCE, commandExecutor, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
|
||||
return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> lexRangeHead(String toElement, boolean toInclusive) {
|
||||
return get(lexRangeHeadAsync(toElement, toInclusive));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive) {
|
||||
String toValue = value(toElement, toInclusive);
|
||||
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> lexRangeTail(String fromElement, boolean fromInclusive) {
|
||||
return get(lexRangeTailAsync(fromElement, fromInclusive));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive) {
|
||||
String fromValue = value(fromElement, fromInclusive);
|
||||
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Future<Collection<String>> 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<Integer> 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<Integer> 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<Integer> 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<Boolean> addAsync(String e) {
|
||||
return addAsync(0, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Boolean> addAllAsync(Collection<? extends String> c) {
|
||||
List<Object> params = new ArrayList<Object>(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<? extends String> c) {
|
||||
return get(addAllAsync(c));
|
||||
}
|
||||
|
||||
}
|
@ -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<String>, RExpirable {
|
||||
|
||||
Integer lexCountTail(String fromElement, boolean fromInclusive);
|
||||
|
||||
Integer lexCountHead(String toElement, boolean toInclusive);
|
||||
|
||||
Collection<String> lexRangeTail(String fromElement, boolean fromInclusive);
|
||||
|
||||
Collection<String> lexRangeHead(String toElement, boolean toInclusive);
|
||||
|
||||
Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
|
||||
|
||||
Integer lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
|
||||
|
||||
Integer rank(String o);
|
||||
|
||||
Collection<String> valueRange(int startIndex, int endIndex);
|
||||
|
||||
}
|
@ -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<String> {
|
||||
|
||||
Future<Integer> lexCountTailAsync(String fromElement, boolean fromInclusive);
|
||||
|
||||
Future<Integer> lexCountHeadAsync(String toElement, boolean toInclusive);
|
||||
|
||||
Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive);
|
||||
|
||||
Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive);
|
||||
|
||||
Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
|
||||
|
||||
Future<Integer> lexCountAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
|
||||
|
||||
Future<Integer> rankAsync(String o);
|
||||
|
||||
Future<Collection<String>> valueRangeAsync(int startIndex, int endIndex);
|
||||
|
||||
}
|
Loading…
Reference in New Issue