|
|
@ -15,20 +15,6 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.redisson;
|
|
|
|
package org.redisson;
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
import org.redisson.api.RScoredSortedSet;
|
|
|
|
import org.redisson.api.RScoredSortedSet;
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
@ -37,6 +23,7 @@ import org.redisson.api.mapreduce.RCollectionMapReduce;
|
|
|
|
import org.redisson.client.RedisClient;
|
|
|
|
import org.redisson.client.RedisClient;
|
|
|
|
import org.redisson.client.codec.Codec;
|
|
|
|
import org.redisson.client.codec.Codec;
|
|
|
|
import org.redisson.client.codec.DoubleCodec;
|
|
|
|
import org.redisson.client.codec.DoubleCodec;
|
|
|
|
|
|
|
|
import org.redisson.client.codec.IntegerCodec;
|
|
|
|
import org.redisson.client.codec.LongCodec;
|
|
|
|
import org.redisson.client.codec.LongCodec;
|
|
|
|
import org.redisson.client.codec.StringCodec;
|
|
|
|
import org.redisson.client.codec.StringCodec;
|
|
|
|
import org.redisson.client.protocol.RedisCommand;
|
|
|
|
import org.redisson.client.protocol.RedisCommand;
|
|
|
@ -48,6 +35,20 @@ import org.redisson.iterator.RedissonBaseIterator;
|
|
|
|
import org.redisson.mapreduce.RedissonCollectionMapReduce;
|
|
|
|
import org.redisson.mapreduce.RedissonCollectionMapReduce;
|
|
|
|
import org.redisson.misc.RedissonPromise;
|
|
|
|
import org.redisson.misc.RedissonPromise;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Nikita Koksharov
|
|
|
|
* @author Nikita Koksharov
|
|
|
@ -204,6 +205,11 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
|
|
|
|
return get(addAndGetRevRankAsync(score, object));
|
|
|
|
return get(addAndGetRevRankAsync(score, object));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Integer> addAndGetAllRevRank(Map<? extends V, Double> map) {
|
|
|
|
|
|
|
|
return get(addAndGetAllRevRankAsync(map));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public RFuture<Integer> addAndGetRevRankAsync(double score, V object) {
|
|
|
|
public RFuture<Integer> addAndGetRevRankAsync(double score, V object) {
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
|
|
|
@ -212,6 +218,36 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
|
|
|
|
Collections.<Object>singletonList(getName()), new BigDecimal(score).toPlainString(), encode(object));
|
|
|
|
Collections.<Object>singletonList(getName()), new BigDecimal(score).toPlainString(), encode(object));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public RFuture<List<Integer>> addAndGetAllRevRankAsync(Map<? extends V, Double> map) {
|
|
|
|
|
|
|
|
final List<Object> params = new ArrayList<Object>(map.size() * 2);
|
|
|
|
|
|
|
|
for (java.util.Map.Entry<? extends V, Double> t : map.entrySet()) {
|
|
|
|
|
|
|
|
if (t.getKey() == null) {
|
|
|
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t.getValue() == null) {
|
|
|
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
params.add(encode(t.getKey()));
|
|
|
|
|
|
|
|
params.add(BigDecimal.valueOf(t.getValue()).toPlainString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalReadAsync((String) null, IntegerCodec.INSTANCE, RedisCommands.EVAL_INT_LIST,
|
|
|
|
|
|
|
|
"local r = {} " +
|
|
|
|
|
|
|
|
"for i, v in ipairs(ARGV) do " +
|
|
|
|
|
|
|
|
"if i % 2 == 0 then " +
|
|
|
|
|
|
|
|
"redis.call('zadd', KEYS[1], ARGV[i], ARGV[i-1]); " +
|
|
|
|
|
|
|
|
"end; " +
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
|
|
|
"for i, v in ipairs(ARGV) do " +
|
|
|
|
|
|
|
|
"if i % 2 == 0 then " +
|
|
|
|
|
|
|
|
"r[#r+1] = redis.call('zrevrank', KEYS[1], ARGV[i-1]); " +
|
|
|
|
|
|
|
|
"end; " +
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
|
|
|
"return r;",
|
|
|
|
|
|
|
|
Collections.singletonList(getName()), params.toArray());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean tryAdd(double score, V object) {
|
|
|
|
public boolean tryAdd(double score, V object) {
|
|
|
|
return get(tryAddAsync(score, object));
|
|
|
|
return get(tryAddAsync(score, object));
|
|
|
@ -372,11 +408,27 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
|
|
|
|
return get(getScoreAsync(o));
|
|
|
|
return get(getScoreAsync(o));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Double> getAllScore(List<V> keys) {
|
|
|
|
|
|
|
|
return get(getAllScoreAsync(keys));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public RFuture<Double> getScoreAsync(V o) {
|
|
|
|
public RFuture<Double> getScoreAsync(V o) {
|
|
|
|
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZSCORE, getName(), encode(o));
|
|
|
|
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZSCORE, getName(), encode(o));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public RFuture<List<Double>> getAllScoreAsync(Collection<V> elements) {
|
|
|
|
|
|
|
|
return commandExecutor.evalReadAsync((String) null, DoubleCodec.INSTANCE, RedisCommands.EVAL_LIST,
|
|
|
|
|
|
|
|
"local r = {} " +
|
|
|
|
|
|
|
|
"for i, v in ipairs(ARGV) do " +
|
|
|
|
|
|
|
|
"r[#r+1] = redis.call('ZSCORE', KEYS[1], ARGV[i]); " +
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
|
|
|
"return r;",
|
|
|
|
|
|
|
|
Collections.singletonList(getName()), encode(elements).toArray());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Integer rank(V o) {
|
|
|
|
public Integer rank(V o) {
|
|
|
|
return get(rankAsync(o));
|
|
|
|
return get(rankAsync(o));
|
|
|
|