Move Tuple, Limit, and Weights to top-level types.
See: #2273 Original Pull Request: #2276
This commit is contained in:
committed by
Christoph Strobl
parent
91cfbf5470
commit
b45d358abf
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011-2022 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.data.redis;
|
||||
|
||||
/**
|
||||
* A {@link Comparable} software version
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Christoph Strobl
|
||||
* @deprecated since 2.0, use {@link org.springframework.data.util.Version}.
|
||||
*/
|
||||
public class Version implements Comparable<Version> {
|
||||
|
||||
public static final Version UNKNOWN = new Version(0, 0, 0);
|
||||
|
||||
Integer major;
|
||||
Integer minor;
|
||||
Integer patch;
|
||||
|
||||
public Version(int major, int minor, int patch) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
}
|
||||
|
||||
public int compareTo(Version o) {
|
||||
if (this.major != o.major) {
|
||||
return this.major.compareTo(o.major);
|
||||
}
|
||||
if (this.minor != o.minor) {
|
||||
return this.minor.compareTo(o.minor);
|
||||
}
|
||||
if (this.patch != o.patch) {
|
||||
return this.patch.compareTo(o.patch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + major + "." + minor + "." + patch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((major == null) ? 0 : major.hashCode());
|
||||
result = prime * result + ((minor == null) ? 0 : minor.hashCode());
|
||||
result = prime * result + ((patch == null) ? 0 : patch.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Version)) {
|
||||
return false;
|
||||
}
|
||||
Version other = (Version) obj;
|
||||
if (major == null) {
|
||||
if (other.major != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!major.equals(other.major)) {
|
||||
return false;
|
||||
}
|
||||
if (minor == null) {
|
||||
if (other.minor != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!minor.equals(other.minor)) {
|
||||
return false;
|
||||
}
|
||||
if (patch == null) {
|
||||
if (other.patch != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!patch.equals(other.patch)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.data.redis;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Central class for reading version string (eg. {@literal 1.3.1}) into {@link Version}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
* @deprecated since 2.0, use {@link org.springframework.data.util.Version}.
|
||||
*/
|
||||
public class VersionParser {
|
||||
|
||||
private static final Pattern VERSION_MATCHER = Pattern.compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?(.*)");
|
||||
|
||||
/**
|
||||
* Parse version string {@literal eg. 1.1.1} to {@link Version}.
|
||||
*
|
||||
* @param version can be {@literal null}.
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public static Version parseVersion(@Nullable String version) {
|
||||
|
||||
if (version == null) {
|
||||
return Version.UNKNOWN;
|
||||
}
|
||||
|
||||
Matcher matcher = VERSION_MATCHER.matcher(version);
|
||||
if (matcher.matches()) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(4);
|
||||
return new Version(Integer.parseInt(major), minor != null ? Integer.parseInt(minor) : 0,
|
||||
patch != null ? Integer.parseInt(patch) : 0);
|
||||
}
|
||||
|
||||
return Version.UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,6 +48,9 @@ import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.stream.StringRecord;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.ConvertingCursor;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
@@ -1042,7 +1045,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRangeByScore(key, range, limit), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@@ -1063,7 +1066,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRangeByScoreWithScores(key, range, limit), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@@ -1093,7 +1097,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRevRangeByScore(key, range, limit), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@@ -1109,7 +1113,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRevRangeByScoreWithScores(key, range, limit), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@@ -2589,7 +2594,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRangeByLex(key, range, limit), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@@ -2600,21 +2605,21 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
|
||||
@Override
|
||||
public Set<String> zRangeByLex(String key, Range range) {
|
||||
return zRangeByLex(key, range, Limit.unlimited());
|
||||
return zRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zRangeByLex(String key, Range range, Limit limit) {
|
||||
public Set<String> zRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRangeByLex(serialize(key), range, limit), byteSetToStringSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRevRangeByLex(key, range, limit), Converters.identityConverter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zRevRangeByLex(String key, Range range, Limit limit) {
|
||||
public Set<String> zRevRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.zRevRangeByLex(serialize(key), range, limit), byteSetToStringSet);
|
||||
}
|
||||
|
||||
@@ -2720,7 +2725,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StringRecord> xRange(String key, org.springframework.data.domain.Range<String> range, Limit limit) {
|
||||
public List<StringRecord> xRange(String key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return convertAndReturn(delegate.xRange(serialize(key), range, limit), listByteMapRecordToStringMapRecordConverter);
|
||||
}
|
||||
|
||||
@@ -2739,7 +2745,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StringRecord> xRevRange(String key, org.springframework.data.domain.Range<String> range, Limit limit) {
|
||||
public List<StringRecord> xRevRange(String key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
return convertAndReturn(delegate.xRevRange(serialize(key), range, limit),
|
||||
listByteMapRecordToStringMapRecordConverter);
|
||||
@@ -2831,7 +2838,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteRecord> xRange(byte[] key, org.springframework.data.domain.Range<String> range, Limit limit) {
|
||||
public List<ByteRecord> xRange(byte[] key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return delegate.xRange(key, range, limit);
|
||||
}
|
||||
|
||||
@@ -2847,7 +2855,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteRecord> xRevRange(byte[] key, org.springframework.data.domain.Range<String> range, Limit limit) {
|
||||
public List<ByteRecord> xRevRange(byte[] key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return delegate.xRevRange(key, range, limit);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ package org.springframework.data.redis.connection;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,8 @@ import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroups;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
@@ -585,7 +587,8 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
/** @deprecated in favor of {@link RedisConnection#streamCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default List<ByteRecord> xRange(byte[] key, org.springframework.data.domain.Range<String> range, Limit limit) {
|
||||
default List<ByteRecord> xRange(byte[] key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return streamCommands().xRange(key, range, limit);
|
||||
}
|
||||
|
||||
@@ -628,7 +631,8 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
/** @deprecated in favor of {@link RedisConnection#streamCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default List<ByteRecord> xRevRange(byte[] key, org.springframework.data.domain.Range<String> range, Limit limit) {
|
||||
default List<ByteRecord> xRevRange(byte[] key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return streamCommands().xRevRange(key, range, limit);
|
||||
}
|
||||
|
||||
@@ -1137,28 +1141,29 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
default Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return zSetCommands().zRangeByLex(key, range, limit);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
default Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return zSetCommands().zRevRangeByLex(key, range, limit);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
default Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return zSetCommands().zRangeByScore(key, range, limit);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
default Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return zSetCommands().zRangeByScoreWithScores(key, range, limit);
|
||||
}
|
||||
|
||||
@@ -1172,14 +1177,15 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
default Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
return zSetCommands().zRevRangeByScore(key, range, limit);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
return zSetCommands().zRevRangeByScoreWithScores(key, range, limit);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.data.redis.connection;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 1.6
|
||||
*/
|
||||
public class Limit {
|
||||
|
||||
private static final Limit UNLIMITED = new Limit() {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return super.getOffset();
|
||||
}
|
||||
};
|
||||
|
||||
int offset;
|
||||
int count;
|
||||
|
||||
public static Limit limit() {
|
||||
return new Limit();
|
||||
}
|
||||
|
||||
public Limit offset(int offset) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Limit count(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public boolean isUnlimited() {
|
||||
return this.equals(UNLIMITED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return new {@link Limit} indicating no limit;
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Limit unlimited() {
|
||||
return UNLIMITED;
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,6 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyComm
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands.XPendingOptions;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.stream.ByteBufferRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessage;
|
||||
|
||||
@@ -34,9 +34,9 @@ import org.reactivestreams.Publisher;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.stream.*;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoConsumers;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroups;
|
||||
|
||||
@@ -15,18 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -52,160 +47,6 @@ public interface RedisZSetCommands {
|
||||
SUM, MIN, MAX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value object encapsulating a multiplication factor for each input sorted set. This means that the score of every
|
||||
* element in every input sorted set is multiplied by this factor before being passed to the aggregation function.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
class Weights {
|
||||
|
||||
private final List<Double> weights;
|
||||
|
||||
private Weights(List<Double> weights) {
|
||||
this.weights = weights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link Weights} given {@code weights} as {@code int}.
|
||||
*
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return the {@link Weights} for {@code weights}.
|
||||
*/
|
||||
public static Weights of(int... weights) {
|
||||
|
||||
Assert.notNull(weights, "Weights must not be null!");
|
||||
return new Weights(Arrays.stream(weights).mapToDouble(value -> value).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link Weights} given {@code weights} as {@code double}.
|
||||
*
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return the {@link Weights} for {@code weights}.
|
||||
*/
|
||||
public static Weights of(double... weights) {
|
||||
|
||||
Assert.notNull(weights, "Weights must not be null!");
|
||||
|
||||
return new Weights(DoubleStream.of(weights).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates equal {@link Weights} for a number of input sets {@code count} with a weight of one.
|
||||
*
|
||||
* @param count number of input sets. Must be greater or equal to zero.
|
||||
* @return equal {@link Weights} for a number of input sets with a weight of one.
|
||||
*/
|
||||
public static Weights fromSetCount(int count) {
|
||||
|
||||
Assert.isTrue(count >= 0, "Count of input sorted sets must be greater or equal to zero!");
|
||||
|
||||
return new Weights(IntStream.range(0, count).mapToDouble(value -> 1).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weights} object that contains all weights multiplied by {@code multiplier}
|
||||
*
|
||||
* @param multiplier multiplier used to multiply each weight with.
|
||||
* @return equal {@link Weights} for a number of input sets with a weight of one.
|
||||
*/
|
||||
public Weights multiply(int multiplier) {
|
||||
return apply(it -> it * multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weights} object that contains all weights multiplied by {@code multiplier}
|
||||
*
|
||||
* @param multiplier multiplier used to multiply each weight with.
|
||||
* @return equal {@link Weights} for a number of input sets with a weight of one.
|
||||
*/
|
||||
public Weights multiply(double multiplier) {
|
||||
return apply(it -> it * multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weights} object that contains all weights with {@link Function} applied.
|
||||
*
|
||||
* @param operator operator function.
|
||||
* @return the new {@link Weights} with {@link DoubleUnaryOperator} applied.
|
||||
*/
|
||||
public Weights apply(Function<Double, Double> operator) {
|
||||
return new Weights(weights.stream().map(operator).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the weight at {@code index}.
|
||||
*
|
||||
* @param index the weight index.
|
||||
* @return the weight at {@code index}.
|
||||
* @throws IndexOutOfBoundsException if the index is out of range
|
||||
*/
|
||||
public double getWeight(int index) {
|
||||
return weights.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of weights.
|
||||
*/
|
||||
public int size() {
|
||||
return weights.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array containing all of the weights in this list in proper sequence (from first to last element).
|
||||
*/
|
||||
public double[] toArray() {
|
||||
return weights.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link List} containing all of the weights in this list in proper sequence (from first to last
|
||||
* element).
|
||||
*/
|
||||
public List<Double> toList() {
|
||||
return Collections.unmodifiableList(weights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Weights)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Weights that = (Weights) o;
|
||||
return ObjectUtils.nullSafeEquals(this.weights, that.weights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectUtils.nullSafeHashCode(weights);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ZSet tuple.
|
||||
*/
|
||||
interface Tuple extends Comparable<Double> {
|
||||
|
||||
/**
|
||||
* @return the raw value of the member.
|
||||
*/
|
||||
byte[] getValue();
|
||||
|
||||
/**
|
||||
* @return the member score value used for sorting.
|
||||
*/
|
||||
Double getScore();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Range} defines {@literal min} and {@literal max} values to retrieve from a {@literal ZSET}.
|
||||
*
|
||||
@@ -336,58 +177,11 @@ public interface RedisZSetCommands {
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @since 1.6
|
||||
* @deprecated since 3.0, use {@link org.springframework.data.redis.connection.Limit} instead.
|
||||
*/
|
||||
class Limit {
|
||||
@Deprecated
|
||||
class Limit extends org.springframework.data.redis.connection.Limit {
|
||||
|
||||
private static final Limit UNLIMITED = new Limit() {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return super.getOffset();
|
||||
}
|
||||
};
|
||||
|
||||
int offset;
|
||||
int count;
|
||||
|
||||
public static Limit limit() {
|
||||
return new Limit();
|
||||
}
|
||||
|
||||
public Limit offset(int offset) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Limit count(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public boolean isUnlimited() {
|
||||
return this.equals(UNLIMITED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return new {@link Limit} indicating no limit;
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Limit unlimited() {
|
||||
return UNLIMITED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -787,7 +581,8 @@ public interface RedisZSetCommands {
|
||||
@Nullable
|
||||
default Set<byte[]> zRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
||||
return zRangeByScore(key, new Range().gte(min).lte(max),
|
||||
new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue()));
|
||||
new org.springframework.data.redis.connection.Limit().offset(Long.valueOf(offset).intValue())
|
||||
.count(Long.valueOf(count).intValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -806,7 +601,8 @@ public interface RedisZSetCommands {
|
||||
@Nullable
|
||||
default Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
return zRangeByScoreWithScores(key, new Range().gte(min).lte(max),
|
||||
new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue()));
|
||||
new org.springframework.data.redis.connection.Limit().offset(Long.valueOf(offset).intValue())
|
||||
.count(Long.valueOf(count).intValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -822,7 +618,7 @@ public interface RedisZSetCommands {
|
||||
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit);
|
||||
Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Get elements in range from {@code start} to {@code end} from sorted set ordered from high to low.
|
||||
@@ -928,7 +724,7 @@ public interface RedisZSetCommands {
|
||||
* @see <a href="https://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit);
|
||||
Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Get set of {@link Tuple} in range from {@code start} to {@code end} where score is between {@code min} and
|
||||
@@ -946,7 +742,8 @@ public interface RedisZSetCommands {
|
||||
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
|
||||
return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max),
|
||||
new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue()));
|
||||
new org.springframework.data.redis.connection.Limit().offset(Long.valueOf(offset).intValue())
|
||||
.count(Long.valueOf(count).intValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -976,7 +773,7 @@ public interface RedisZSetCommands {
|
||||
* @see <a href="https://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit);
|
||||
Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with scores between {@code min} and {@code max}.
|
||||
@@ -1454,7 +1251,7 @@ public interface RedisZSetCommands {
|
||||
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit);
|
||||
Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Get all the elements in the sorted set at {@literal key} in lexicographical ordering.
|
||||
@@ -1495,7 +1292,7 @@ public interface RedisZSetCommands {
|
||||
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit);
|
||||
Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Get all the elements in the sorted set at {@literal key} in reversed lexicographical ordering.
|
||||
@@ -1521,7 +1318,7 @@ public interface RedisZSetCommands {
|
||||
*/
|
||||
@Nullable
|
||||
default Set<byte[]> zRevRangeByLex(byte[] key, Range range) {
|
||||
return zRevRangeByLex(key, range, Limit.unlimited());
|
||||
return zRevRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1536,6 +1333,6 @@ public interface RedisZSetCommands {
|
||||
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit);
|
||||
Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.stream.StreamRecords;
|
||||
import org.springframework.data.redis.connection.stream.StringRecord;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
@@ -1929,7 +1931,7 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
|
||||
/**
|
||||
* Get all the elements in {@link Range} from the sorted set at {@literal key} in lexicographical ordering. Result is
|
||||
* limited via {@link Limit}.
|
||||
* limited via {@link org.springframework.data.redis.connection.Limit}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
@@ -1939,7 +1941,7 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
|
||||
* @see RedisZSetCommands#zRangeByLex(byte[], Range, Limit)
|
||||
*/
|
||||
Set<String> zRangeByLex(String key, Range range, Limit limit);
|
||||
Set<String> zRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Get all the elements in the sorted set at {@literal key} in reversed lexicographical ordering.
|
||||
@@ -1965,12 +1967,12 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see RedisZSetCommands#zRevRangeByLex(byte[], Range)
|
||||
*/
|
||||
default Set<String> zRevRangeByLex(String key, Range range) {
|
||||
return zRevRangeByLex(key, range, Limit.unlimited());
|
||||
return zRevRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the elements in {@link Range} from the sorted set at {@literal key} in reversed lexicographical ordering.
|
||||
* Result is limited via {@link Limit}.
|
||||
* Result is limited via {@link org.springframework.data.redis.connection.Limit}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
@@ -1980,7 +1982,7 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
|
||||
* @see RedisZSetCommands#zRevRangeByLex(byte[], Range, Limit)
|
||||
*/
|
||||
Set<String> zRevRangeByLex(String key, Range range, Limit limit);
|
||||
Set<String> zRevRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods dealing with Redis Hashes
|
||||
@@ -2866,11 +2868,12 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
*/
|
||||
@Nullable
|
||||
default List<StringRecord> xRange(String key, org.springframework.data.domain.Range<String> range) {
|
||||
return xRange(key, range, Limit.unlimited());
|
||||
return xRange(key, range, org.springframework.data.redis.connection.Limit.unlimited());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read records from a stream within a specific {@link Range} applying a {@link Limit}.
|
||||
* Read records from a stream within a specific {@link Range} applying a
|
||||
* {@link org.springframework.data.redis.connection.Limit}.
|
||||
*
|
||||
* @param key the stream key.
|
||||
* @param range must not be {@literal null}.
|
||||
@@ -2880,7 +2883,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="https://redis.io/commands/xrange">Redis Documentation: XRANGE</a>
|
||||
*/
|
||||
@Nullable
|
||||
List<StringRecord> xRange(String key, org.springframework.data.domain.Range<String> range, Limit limit);
|
||||
List<StringRecord> xRange(String key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Read records from one or more {@link StreamOffset}s.
|
||||
@@ -3007,7 +3011,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read records from a stream within a specific {@link Range} applying a {@link Limit} in reverse order.
|
||||
* Read records from a stream within a specific {@link Range} applying a
|
||||
* {@link org.springframework.data.redis.connection.Limit} in reverse order.
|
||||
*
|
||||
* @param key the stream key.
|
||||
* @param range must not be {@literal null}.
|
||||
@@ -3017,7 +3022,8 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @see <a href="https://redis.io/commands/xrevrange">Redis Documentation: XREVRANGE</a>
|
||||
*/
|
||||
@Nullable
|
||||
List<StringRecord> xRevRange(String key, org.springframework.data.domain.Range<String> range, Limit limit);
|
||||
List<StringRecord> xRevRange(String key, org.springframework.data.domain.Range<String> range,
|
||||
org.springframework.data.redis.connection.Limit limit);
|
||||
|
||||
/**
|
||||
* Trims the stream to {@code count} elements.
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||
import org.springframework.data.redis.connection.RedisNode.NodeType;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands;
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
@@ -223,7 +223,7 @@ class JedisClusterStreamCommands implements RedisStreamCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteRecord> xRange(byte[] key, Range<String> range, RedisZSetCommands.Limit limit) {
|
||||
public List<ByteRecord> xRange(byte[] key, Range<String> range, Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
@@ -289,7 +289,7 @@ class JedisClusterStreamCommands implements RedisStreamCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteRecord> xRevRange(byte[] key, Range<String> range, RedisZSetCommands.Limit limit) {
|
||||
public List<ByteRecord> xRevRange(byte[] key, Range<String> range, Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
@@ -27,9 +27,11 @@ import java.util.stream.Collectors;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands;
|
||||
import org.springframework.data.redis.connection.convert.SetConverter;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanCursor;
|
||||
import org.springframework.data.redis.core.ScanIteration;
|
||||
@@ -201,7 +203,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range cannot be null for ZRANGEBYSCOREWITHSCORES.");
|
||||
@@ -221,7 +224,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCORE.");
|
||||
@@ -240,7 +243,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCOREWITHSCORES.");
|
||||
@@ -391,7 +395,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range cannot be null for ZRANGEBYSCORE.");
|
||||
@@ -410,7 +414,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null for ZRANGEBYLEX!");
|
||||
@@ -446,7 +450,7 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null for ZREVRANGEBYLEX!");
|
||||
|
||||
@@ -52,7 +52,6 @@ import org.springframework.data.redis.connection.BitFieldSubCommands;
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldIncrBy;
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldSet;
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldSubCommand;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||
@@ -64,7 +63,6 @@ import org.springframework.data.redis.connection.RedisServerCommands;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
@@ -75,6 +73,8 @@ import org.springframework.data.redis.connection.convert.ListConverter;
|
||||
import org.springframework.data.redis.connection.convert.MapConverter;
|
||||
import org.springframework.data.redis.connection.convert.SetConverter;
|
||||
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||
|
||||
@@ -28,8 +28,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands;
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
@@ -236,7 +236,7 @@ class JedisStreamCommands implements RedisStreamCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteRecord> xRange(byte[] key, Range<String> range, RedisZSetCommands.Limit limit) {
|
||||
public List<ByteRecord> xRange(byte[] key, Range<String> range, Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
@@ -293,7 +293,7 @@ class JedisStreamCommands implements RedisStreamCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ByteRecord> xRevRange(byte[] key, Range<String> range, RedisZSetCommands.Limit limit) {
|
||||
public List<ByteRecord> xRevRange(byte[] key, Range<String> range, Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
@@ -41,14 +41,14 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.SortParameters.Range;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,8 +28,10 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.KeyBoundCursor;
|
||||
import org.springframework.data.redis.core.ScanIteration;
|
||||
@@ -171,7 +173,8 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!");
|
||||
@@ -210,7 +213,7 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZREVRANGEBYSCORE must not be null!");
|
||||
@@ -229,7 +232,8 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZREVRANGEBYSCOREWITHSCORES must not be null!");
|
||||
@@ -611,7 +615,7 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
|
||||
@@ -629,7 +633,7 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
|
||||
@@ -647,7 +651,7 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZREVRANGEBYLEX must not be null!");
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldInc
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldIncrBy.Overflow;
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldSet;
|
||||
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldSubCommand;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
||||
@@ -48,11 +49,12 @@ import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.RedisNode.NodeType;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.convert.LongToBooleanConverter;
|
||||
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.core.KeyScanOptions;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
@@ -266,15 +268,15 @@ public abstract class LettuceConverters extends Converters {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link org.springframework.data.redis.connection.RedisZSetCommands.Limit} to a Lettuce
|
||||
* {@link io.lettuce.core.Limit}.
|
||||
* Convert a {@link Limit} to a Lettuce {@link io.lettuce.core.Limit}.
|
||||
*
|
||||
* @param limit
|
||||
* @return a lettuce {@link io.lettuce.core.Limit}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static io.lettuce.core.Limit toLimit(RedisZSetCommands.Limit limit) {
|
||||
return limit.isUnlimited() ? Limit.unlimited() : Limit.create(limit.getOffset(), limit.getCount());
|
||||
public static io.lettuce.core.Limit toLimit(Limit limit) {
|
||||
return limit.isUnlimited() ? io.lettuce.core.Limit.unlimited()
|
||||
: io.lettuce.core.Limit.create(limit.getOffset(), limit.getCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@ import io.lettuce.core.ScoredValue;
|
||||
import io.lettuce.core.Value;
|
||||
import io.lettuce.core.ZAddArgs;
|
||||
import io.lettuce.core.ZStoreArgs;
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -32,7 +31,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyScanCommand;
|
||||
@@ -40,7 +38,9 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiVa
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
|
||||
import org.springframework.data.redis.connection.ReactiveZSetCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -28,8 +28,8 @@ import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs.Flag;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.KeyBoundCursor;
|
||||
import org.springframework.data.redis.core.ScanIteration;
|
||||
@@ -161,7 +163,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!");
|
||||
@@ -198,7 +201,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZREVRANGEBYSCORE must not be null!");
|
||||
@@ -217,7 +220,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) {
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
|
||||
org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZREVRANGEBYSCOREWITHSCORES must not be null!");
|
||||
@@ -584,7 +588,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
|
||||
@@ -600,7 +604,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
|
||||
@@ -617,7 +621,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit) {
|
||||
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range for ZREVRANGEBYLEX must not be null!");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2022 the original author or authors.
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,12 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection;
|
||||
package org.springframework.data.redis.connection.zset;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link Tuple} interface.
|
||||
*
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.data.redis.connection.zset;
|
||||
|
||||
/**
|
||||
* ZSet tuple.
|
||||
*/
|
||||
public interface Tuple extends Comparable<Double> {
|
||||
|
||||
/**
|
||||
* @return the raw value of the member.
|
||||
*/
|
||||
byte[] getValue();
|
||||
|
||||
/**
|
||||
* @return the member score value used for sorting.
|
||||
*/
|
||||
Double getScore();
|
||||
|
||||
/**
|
||||
* Create a new {@link Tuple}.
|
||||
*
|
||||
* @param value
|
||||
* @param score
|
||||
* @return
|
||||
*/
|
||||
static Tuple of(byte[] value, Double score) {
|
||||
return new DefaultTuple(value, score);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.springframework.data.redis.connection.zset;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Value object encapsulating a multiplication factor for each input sorted set. This means that the score of every
|
||||
* element in every input sorted set is multiplied by this factor before being passed to the aggregation function.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
public class Weights {
|
||||
|
||||
private final List<Double> weights;
|
||||
|
||||
private Weights(List<Double> weights) {
|
||||
this.weights = weights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link Weights} given {@code weights} as {@code int}.
|
||||
*
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return the {@link Weights} for {@code weights}.
|
||||
*/
|
||||
public static Weights of(int... weights) {
|
||||
|
||||
Assert.notNull(weights, "Weights must not be null!");
|
||||
return new Weights(Arrays.stream(weights).mapToDouble(value -> value).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link Weights} given {@code weights} as {@code double}.
|
||||
*
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return the {@link Weights} for {@code weights}.
|
||||
*/
|
||||
public static Weights of(double... weights) {
|
||||
|
||||
Assert.notNull(weights, "Weights must not be null!");
|
||||
|
||||
return new Weights(DoubleStream.of(weights).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates equal {@link Weights} for a number of input sets {@code count} with a weight of one.
|
||||
*
|
||||
* @param count number of input sets. Must be greater or equal to zero.
|
||||
* @return equal {@link Weights} for a number of input sets with a weight of one.
|
||||
*/
|
||||
public static Weights fromSetCount(int count) {
|
||||
|
||||
Assert.isTrue(count >= 0, "Count of input sorted sets must be greater or equal to zero!");
|
||||
|
||||
return new Weights(IntStream.range(0, count).mapToDouble(value -> 1).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weights} object that contains all weights multiplied by {@code multiplier}
|
||||
*
|
||||
* @param multiplier multiplier used to multiply each weight with.
|
||||
* @return equal {@link Weights} for a number of input sets with a weight of one.
|
||||
*/
|
||||
public Weights multiply(int multiplier) {
|
||||
return apply(it -> it * multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weights} object that contains all weights multiplied by {@code multiplier}
|
||||
*
|
||||
* @param multiplier multiplier used to multiply each weight with.
|
||||
* @return equal {@link Weights} for a number of input sets with a weight of one.
|
||||
*/
|
||||
public Weights multiply(double multiplier) {
|
||||
return apply(it -> it * multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Weights} object that contains all weights with {@link Function} applied.
|
||||
*
|
||||
* @param operator operator function.
|
||||
* @return the new {@link Weights} with {@link DoubleUnaryOperator} applied.
|
||||
*/
|
||||
public Weights apply(Function<Double, Double> operator) {
|
||||
return new Weights(weights.stream().map(operator).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the weight at {@code index}.
|
||||
*
|
||||
* @param index the weight index.
|
||||
* @return the weight at {@code index}.
|
||||
* @throws IndexOutOfBoundsException if the index is out of range
|
||||
*/
|
||||
public double getWeight(int index) {
|
||||
return weights.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of weights.
|
||||
*/
|
||||
public int size() {
|
||||
return weights.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array containing all of the weights in this list in proper sequence (from first to last element).
|
||||
*/
|
||||
public double[] toArray() {
|
||||
return weights.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link List} containing all of the weights in this list in proper sequence (from first to last element).
|
||||
*/
|
||||
public List<Double> toList() {
|
||||
return Collections.unmodifiableList(weights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof Weights)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Weights that = (Weights) o;
|
||||
return ObjectUtils.nullSafeEquals(this.weights, that.weights);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectUtils.nullSafeHashCode(weights);
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,11 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.geo.GeoResults;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.SerializationUtils;
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
|
||||
@@ -22,11 +22,11 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -20,13 +20,13 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,10 +22,10 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.ReactiveStreamCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.convert.Converters;
|
||||
import org.springframework.data.redis.connection.stream.ByteBufferRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
|
||||
@@ -27,13 +27,14 @@ import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.ReactiveZSetCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.zset.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
|
||||
@@ -22,12 +22,12 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -22,24 +22,14 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.stream.ByteBufferRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ObjectRecord;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessage;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessages;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.stream.*;
|
||||
import org.springframework.data.redis.connection.stream.Record;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoConsumer;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroup;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.stream.StreamRecords;
|
||||
import org.springframework.data.redis.hash.HashMapper;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -24,10 +24,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisKeyCommands;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands;
|
||||
import org.springframework.data.redis.connection.RedisTxCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.redis.core.query.QueryUtils;
|
||||
import org.springframework.data.redis.core.query.SortQuery;
|
||||
|
||||
@@ -22,23 +22,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.stream.ByteRecord;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ObjectRecord;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessage;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessages;
|
||||
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.stream.*;
|
||||
import org.springframework.data.redis.connection.stream.Record;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoConsumers;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoGroups;
|
||||
import org.springframework.data.redis.connection.stream.StreamInfo.XInfoStream;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.stream.StreamReadOptions;
|
||||
import org.springframework.data.redis.connection.stream.StreamRecords;
|
||||
import org.springframework.data.redis.hash.HashMapper;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -22,11 +22,11 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.connection.zset.Weights;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.core.BoundZSetOperations;
|
||||
import org.springframework.data.redis.core.ConvertingCursor;
|
||||
|
||||
@@ -23,9 +23,9 @@ import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
import org.springframework.data.redis.connection.zset.Tuple;
|
||||
import org.springframework.data.redis.core.BoundZSetOperations;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
@@ -333,7 +333,7 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
Set<E> reverseRangeByScore(double min, double max);
|
||||
|
||||
/**
|
||||
* Get set of {@link RedisZSetCommands.Tuple}s between {@code start} and {@code end} from sorted set.
|
||||
* Get set of {@link Tuple}s between {@code start} and {@code end} from sorted set.
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
@@ -342,8 +342,7 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
Set<TypedTuple<E>> rangeWithScores(long start, long end);
|
||||
|
||||
/**
|
||||
* Get set of {@link RedisZSetCommands.Tuple}s in range from {@code start} to {@code end} from sorted set ordered from
|
||||
* high to low.
|
||||
* Get set of {@link Tuple}s in range from {@code start} to {@code end} from sorted set ordered from high to low.
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
@@ -352,7 +351,7 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
Set<TypedTuple<E>> reverseRangeWithScores(long start, long end);
|
||||
|
||||
/**
|
||||
* Get set of {@link RedisZSetCommands.Tuple}s where score is between {@code min} and {@code max} from sorted set.
|
||||
* Get set of {@link Tuple}s where score is between {@code min} and {@code max} from sorted set.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
@@ -361,8 +360,8 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
Set<TypedTuple<E>> rangeByScoreWithScores(double min, double max);
|
||||
|
||||
/**
|
||||
* Get set of {@link RedisZSetCommands.Tuple}s where score is between {@code min} and {@code max} from sorted set
|
||||
* ordered from high to low.
|
||||
* Get set of {@link Tuple}s where score is between {@code min} and {@code max} from sorted set ordered from high to
|
||||
* low.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
|
||||
Reference in New Issue
Block a user