Add imperative support for ZDIFF, ZDIFFSTORE, ZINTER, and ZUNION commands.
See: #2041 & #2042 Original Pull Request: #2097
This commit is contained in:
committed by
Christoph Strobl
parent
755c8417a3
commit
1c30d69195
@@ -23,6 +23,7 @@ import java.util.function.IntFunction;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.geo.Circle;
|
||||
import org.springframework.data.geo.Distance;
|
||||
@@ -278,7 +279,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return convertAndReturn(delegate.decrBy(key, value), Converters.identityConverter());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#del(byte[][])
|
||||
@@ -1453,6 +1453,127 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return convertAndReturn(delegate.zIncrBy(key, increment, value), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiff(byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<byte[]> zDiff(byte[]... sets) {
|
||||
return convertAndReturn(delegate.zDiff(sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffWithScores(byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<Tuple> zDiffWithScores(byte[]... sets) {
|
||||
return convertAndReturn(delegate.zDiffWithScores(sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffStore(byte[], byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Long zDiffStore(byte[] destKey, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zDiffStore(destKey, sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zDiff(java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<String> zDiff(String... sets) {
|
||||
return convertAndReturn(delegate.zDiff(serializeMulti(sets)), byteSetToStringSet);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zDiffWithScores(java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<StringTuple> zDiffWithScores(String... sets) {
|
||||
return convertAndReturn(delegate.zDiffWithScores(serializeMulti(sets)), tupleToStringTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zDiffStore(java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Long zDiffStore(String destKey, String... sets) {
|
||||
return convertAndReturn(delegate.zDiffStore(serialize(destKey), serializeMulti(sets)),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInter(byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<byte[]> zInter(byte[]... sets) {
|
||||
return convertAndReturn(delegate.zInter(sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(byte[]... sets) {
|
||||
return convertAndReturn(delegate.zInterWithScores(sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zInterWithScores(aggregate, weights, sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zInter(java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<String> zInter(String... sets) {
|
||||
return convertAndReturn(delegate.zInter(serializeMulti(sets)), byteSetToStringSet);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zInterWithScores(java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<StringTuple> zInterWithScores(String... sets) {
|
||||
return convertAndReturn(delegate.zInterWithScores(serializeMulti(sets)), tupleToStringTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zInterWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<StringTuple> zInterWithScores(Aggregate aggregate, Weights weights, String... sets) {
|
||||
return convertAndReturn(delegate.zInterWithScores(aggregate, weights, serializeMulti(sets)), tupleToStringTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
@@ -1531,7 +1652,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
return convertAndReturn(delegate.zRangeByScoreWithScores(key, min, max, offset, count), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.zRangeByScoreWithScores(key, min, max, offset, count),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1603,7 +1725,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
return convertAndReturn(delegate.zRevRangeByScoreWithScores(key, min, max, offset, count), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.zRevRangeByScoreWithScores(key, min, max, offset, count),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1732,6 +1855,66 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return convertAndReturn(delegate.zMScore(key, values), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnion(byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<byte[]> zUnion(byte[]... sets) {
|
||||
return convertAndReturn(delegate.zUnion(sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(byte[]... sets) {
|
||||
return convertAndReturn(delegate.zUnionWithScores(sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
return convertAndReturn(delegate.zUnionWithScores(aggregate, weights, sets), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zUnion(java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<String> zUnion(String... sets) {
|
||||
return convertAndReturn(delegate.zUnion(serializeMulti(sets)), byteSetToStringSet);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zUnionWithScores(java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<StringTuple> zUnionWithScores(String... sets) {
|
||||
return convertAndReturn(delegate.zUnionWithScores(serializeMulti(sets)), tupleToStringTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zUnionWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, java.lang.String[])
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<StringTuple> zUnionWithScores(Aggregate aggregate, Weights weights, String... sets) {
|
||||
return convertAndReturn(delegate.zUnionWithScores(aggregate, weights, serializeMulti(sets)), tupleToStringTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
@@ -1863,7 +2046,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
*/
|
||||
@Override
|
||||
public <T> T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
|
||||
return convertAndReturn(delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1872,7 +2056,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
*/
|
||||
@Override
|
||||
public <T> T evalSha(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
|
||||
return convertAndReturn(delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1959,6 +2144,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
public Boolean copy(String sourceKey, String targetKey, boolean replace) {
|
||||
return copy(serialize(sourceKey), serialize(targetKey), replace);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#decr(java.lang.String)
|
||||
@@ -1986,7 +2172,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return del(serializeMulti(keys));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#unlink(java.lang.String[])
|
||||
@@ -3999,7 +4184,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
*/
|
||||
@Override
|
||||
public List<RecordId> xClaimJustId(String key, String group, String consumer, XClaimOptions options) {
|
||||
return convertAndReturn(delegate.xClaimJustId(serialize(key), group, consumer, options), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.xClaimJustId(serialize(key), group, consumer, options),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4036,7 +4222,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
*/
|
||||
@Override
|
||||
public String xGroupCreate(String key, ReadOffset readOffset, String group, boolean mkStream) {
|
||||
return convertAndReturn(delegate.xGroupCreate(serialize(key), group, readOffset, mkStream), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.xGroupCreate(serialize(key), group, readOffset, mkStream),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4109,7 +4296,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
@Override
|
||||
public PendingMessages xPending(String key, String groupName, String consumer,
|
||||
org.springframework.data.domain.Range<String> range, Long count) {
|
||||
return convertAndReturn(delegate.xPending(serialize(key), groupName, consumer, range, count), Converters.identityConverter());
|
||||
return convertAndReturn(delegate.xPending(serialize(key), groupName, consumer, range, count),
|
||||
Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4406,7 +4594,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
}
|
||||
|
||||
return value == null ? null
|
||||
: ObjectUtils.nullSafeEquals(converter, Converters.identityConverter()) ? (T) value : (T) converter.convert(value);
|
||||
: ObjectUtils.nullSafeEquals(converter, Converters.identityConverter()) ? (T) value
|
||||
: (T) converter.convert(value);
|
||||
}
|
||||
|
||||
private void addResultConverter(Converter<?, ?> converter) {
|
||||
|
||||
@@ -991,6 +991,27 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
return zSetCommands().zCount(key, range);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zDiff(byte[]... sets) {
|
||||
return zSetCommands().zDiff(sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zDiffWithScores(byte[]... sets) {
|
||||
return zSetCommands().zDiffWithScores(sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Long zDiffStore(byte[] destKey, byte[]... sets) {
|
||||
return zSetCommands().zDiffStore(destKey, sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -998,6 +1019,34 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
return zSetCommands().zIncrBy(key, increment, value);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zInter(byte[]... sets) {
|
||||
return zSetCommands().zInter(sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zInterWithScores(Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zSetCommands().zInterWithScores(aggregate, weights, sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
return zSetCommands().zInterWithScores(aggregate, weights, sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zInterWithScores(byte[]... sets) {
|
||||
return zSetCommands().zInterWithScores(sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -1152,6 +1201,34 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
return zSetCommands().zMScore(key, values);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<byte[]> zUnion(byte[]... sets) {
|
||||
return zSetCommands().zUnion(sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zUnionWithScores(Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zSetCommands().zUnionWithScores(aggregate, weights, sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
return zSetCommands().zUnionWithScores(aggregate, weights, sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Set<Tuple> zUnionWithScores(byte[]... sets) {
|
||||
return zSetCommands().zUnionWithScores(sets);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
|
||||
@@ -108,6 +108,27 @@ public interface RedisSetCommands {
|
||||
@Nullable
|
||||
Boolean sIsMember(byte[] key, byte[] value);
|
||||
|
||||
/**
|
||||
* Diff all sets for given {@code keys}.
|
||||
*
|
||||
* @param keys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/sdiff">Redis Documentation: SDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> sDiff(byte[]... keys);
|
||||
|
||||
/**
|
||||
* Diff all sets for given {@code keys} and store result in {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param keys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/sdiffstore">Redis Documentation: SDIFFSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long sDiffStore(byte[] destKey, byte[]... keys);
|
||||
|
||||
/**
|
||||
* Returns the members intersecting all given sets at {@code keys}.
|
||||
*
|
||||
@@ -150,26 +171,6 @@ public interface RedisSetCommands {
|
||||
@Nullable
|
||||
Long sUnionStore(byte[] destKey, byte[]... keys);
|
||||
|
||||
/**
|
||||
* Diff all sets for given {@code keys}.
|
||||
*
|
||||
* @param keys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/sdiff">Redis Documentation: SDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> sDiff(byte[]... keys);
|
||||
|
||||
/**
|
||||
* Diff all sets for given {@code keys} and store result in {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param keys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/sdiffstore">Redis Documentation: SDIFFSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long sDiffStore(byte[] destKey, byte[]... keys);
|
||||
|
||||
/**
|
||||
* Get all elements of set at {@code key}.
|
||||
|
||||
@@ -1130,18 +1130,249 @@ public interface RedisZSetCommands {
|
||||
Long zRemRangeByScore(byte[] key, Range range);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zDiff(byte[]... sets);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zDiffWithScores(byte[]... sets);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiffstore">Redis Documentation: ZDIFFSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zDiffStore(byte[] destKey, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zInter(byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<byte[]> zInter(Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zInter(aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zInter(Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zInterWithScores(byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<Tuple> zInterWithScores(Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zInterWithScores(aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zInterStore(byte[] destKey, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zInterStore(destKey, aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zInterStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zUnion(byte[]... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<byte[]> zUnion(Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zUnion(aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<byte[]> zUnion(Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zUnionWithScores(byte[]... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<Tuple> zUnionWithScores(Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zUnionWithScores(aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zUnionStore(byte[] destKey, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
* Union sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
@@ -1156,7 +1387,7 @@ public interface RedisZSetCommands {
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
* Union sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
@@ -1169,46 +1400,6 @@ public interface RedisZSetCommands {
|
||||
@Nullable
|
||||
Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code key}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zInterStore(byte[] destKey, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code key}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
|
||||
return zInterStore(destKey, aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code key}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zInterStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets);
|
||||
|
||||
/**
|
||||
* Use a {@link Cursor} to iterate over elements in sorted set at {@code key}.
|
||||
*
|
||||
|
||||
@@ -1578,28 +1578,88 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
Long zRemRangeByScore(String key, double min, double max);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
* @see RedisZSetCommands#zUnionStore(byte[], byte[]...)
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
Long zUnionStore(String destKey, String... sets);
|
||||
@Nullable
|
||||
Set<String> zDiff(String... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<StringTuple> zDiffWithScores(String... sets);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiffstore">Redis Documentation: ZDIFFSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zDiffStore(String destKey, String... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<String> zInter(String... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<StringTuple> zInterWithScores(String... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
* @see RedisZSetCommands#zUnionStore(byte[], Aggregate, int[], byte[]...)
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
|
||||
@Nullable
|
||||
default Set<StringTuple> zInterWithScores(Aggregate aggregate, int[] weights, String... sets) {
|
||||
return zInterWithScores(aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<StringTuple> zInterWithScores(Aggregate aggregate, Weights weights, String... sets);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets} and store result in destination {@code key}.
|
||||
@@ -1625,6 +1685,82 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
*/
|
||||
Long zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<String> zUnion(String... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<StringTuple> zUnionWithScores(String... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<StringTuple> zUnionWithScores(Aggregate aggregate, int[] weights, String... sets) {
|
||||
return zUnionWithScores(aggregate, Weights.of(weights), sets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<StringTuple> zUnionWithScores(Aggregate aggregate, Weights weights, String... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
* @see RedisZSetCommands#zUnionStore(byte[], byte[]...)
|
||||
*/
|
||||
Long zUnionStore(String destKey, String... sets);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets} and store result in destination {@code key}.
|
||||
*
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights
|
||||
* @param sets must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
* @see RedisZSetCommands#zUnionStore(byte[], Aggregate, int[], byte[]...)
|
||||
*/
|
||||
Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
|
||||
|
||||
/**
|
||||
* Use a {@link Cursor} to iterate over elements in sorted set at {@code key}.
|
||||
*
|
||||
|
||||
@@ -64,7 +64,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
|
||||
try {
|
||||
return JedisConverters.toBoolean(connection.getCluster().zadd(key, score, value, JedisConverters.toZAddParams(args)));
|
||||
return JedisConverters
|
||||
.toBoolean(connection.getCluster().zadd(key, score, value, JedisConverters.toZAddParams(args)));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -798,56 +799,135 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], byte[][])
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiff(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
public Set<byte[]> zDiff(byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return connection.getCluster().zunionstore(destKey, sets);
|
||||
return connection.getCluster().zdiff(sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNIONSTORE can only be executed when all keys map to the same slot");
|
||||
throw new InvalidDataAccessApiUsageException("ZDIFF can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
public Set<Tuple> zDiffWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
|
||||
|
||||
ZParams zparams = new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return connection.getCluster().zunionstore(destKey, zparams, sets);
|
||||
return JedisConverters.toTupleSet(connection.getCluster().zdiffWithScores(sets));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNIONSTORE can only be executed when all keys map to the same slot");
|
||||
throw new InvalidDataAccessApiUsageException("ZDIFF can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffStore(byte[], byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zDiffStore(byte[] destKey, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
|
||||
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
|
||||
|
||||
try {
|
||||
return connection.getCluster().zdiffStore(destKey, sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZDIFFSTORE can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInter(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<byte[]> zInter(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return connection.getCluster().zinter(new ZParams(), sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZINTER can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return JedisConverters.toTupleSet(connection.getCluster().zinterWithScores(new ZParams(), sets));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZINTER can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return JedisConverters
|
||||
.toTupleSet(connection.getCluster().zinterWithScores(toZParams(aggregate, weights), sets));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZINTER can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -892,10 +972,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
|
||||
|
||||
ZParams zparams = new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
|
||||
|
||||
try {
|
||||
return connection.getCluster().zinterstore(destKey, zparams, sets);
|
||||
return connection.getCluster().zinterstore(destKey, toZParams(aggregate, weights), sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -904,6 +982,127 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
throw new IllegalArgumentException("ZINTERSTORE can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnion(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<byte[]> zUnion(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return connection.getCluster().zunion(new ZParams(), sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNION can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return JedisConverters.toTupleSet(connection.getCluster().zunionWithScores(new ZParams(), sets));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNION can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sets)) {
|
||||
|
||||
try {
|
||||
return JedisConverters
|
||||
.toTupleSet(connection.getCluster().zunionWithScores(toZParams(aggregate, weights), sets));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNION can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
|
||||
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
|
||||
|
||||
try {
|
||||
return connection.getCluster().zunionstore(destKey, sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNIONSTORE can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
|
||||
|
||||
ZParams zparams = toZParams(aggregate, weights);
|
||||
|
||||
try {
|
||||
return connection.getCluster().zunionstore(destKey, zparams, sets);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("ZUNIONSTORE can only be executed when all keys map to the same slot");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScan(byte[], org.springframework.data.redis.core.ScanOptions)
|
||||
@@ -973,6 +1172,10 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
return TUPLE_SET_CONVERTER.convert(source);
|
||||
}
|
||||
|
||||
private static ZParams toZParams(Aggregate aggregate, Weights weights) {
|
||||
return new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for broken Jedis BZPOP signature.
|
||||
*
|
||||
|
||||
@@ -476,36 +476,82 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiff(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
public Set<byte[]> zDiff(byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.notNull(weights, "Weights must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
ZParams zparams = new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zunionstore, MultiKeyPipelineBase::zunionstore, destKey, zparams,
|
||||
sets);
|
||||
return connection.invoke().just(BinaryJedis::zdiff, MultiKeyPipelineBase::zdiff, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], byte[][])
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
public Set<Tuple> zDiffWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().fromMany(BinaryJedis::zdiffWithScores, MultiKeyPipelineBase::zdiffWithScores, sets)
|
||||
.toSet(JedisConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffStore(byte[], byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zDiffStore(byte[] destKey, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zunionstore, MultiKeyPipelineBase::zunionstore, destKey, sets);
|
||||
return connection.invoke().just(BinaryJedis::zdiffStore, MultiKeyPipelineBase::zdiffStore, destKey, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInter(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<byte[]> zInter(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zinter, MultiKeyPipelineBase::zinter, new ZParams(), sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke()
|
||||
.fromMany(BinaryJedis::zinterWithScores, MultiKeyPipelineBase::zinterWithScores, new ZParams(), sets)
|
||||
.toSet(JedisConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
return connection.invoke().fromMany(BinaryJedis::zinterWithScores, MultiKeyPipelineBase::zinterWithScores,
|
||||
toZParams(aggregate, weights), sets).toSet(JedisConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -521,7 +567,7 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
ZParams zparams = new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
|
||||
ZParams zparams = toZParams(aggregate, weights);
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zinterstore, MultiKeyPipelineBase::zinterstore, destKey, zparams,
|
||||
sets);
|
||||
@@ -541,6 +587,82 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
return connection.invoke().just(BinaryJedis::zinterstore, MultiKeyPipelineBase::zinterstore, destKey, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnion(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<byte[]> zUnion(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zunion, MultiKeyPipelineBase::zunion, new ZParams(), sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke()
|
||||
.fromMany(BinaryJedis::zunionWithScores, MultiKeyPipelineBase::zunionWithScores, new ZParams(), sets)
|
||||
.toSet(JedisConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
return connection.invoke().fromMany(BinaryJedis::zunionWithScores, MultiKeyPipelineBase::zunionWithScores,
|
||||
toZParams(aggregate, weights), sets).toSet(JedisConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.notNull(weights, "Weights must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
ZParams zparams = toZParams(aggregate, weights);
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zunionstore, MultiKeyPipelineBase::zunionstore, destKey, zparams,
|
||||
sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
|
||||
return connection.invoke().just(BinaryJedis::zunionstore, MultiKeyPipelineBase::zunionstore, destKey, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScan(byte[], org.springframework.data.redis.core.ScanOptions)
|
||||
@@ -695,6 +817,10 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
return connection.isQueueing();
|
||||
}
|
||||
|
||||
private static ZParams toZParams(Aggregate aggregate, Weights weights) {
|
||||
return new ZParams().weights(weights.toArray()).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for broken Jedis BZPOP signature.
|
||||
*
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
import io.lettuce.core.ScanArgs;
|
||||
import io.lettuce.core.ScoredValue;
|
||||
import io.lettuce.core.ScoredValueScanCursor;
|
||||
import io.lettuce.core.ZAggregateArgs;
|
||||
import io.lettuce.core.ZStoreArgs;
|
||||
import io.lettuce.core.api.async.RedisSortedSetAsyncCommands;
|
||||
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
|
||||
@@ -458,34 +459,83 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiff(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
public Set<byte[]> zDiff(byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
ZStoreArgs storeArgs = zStoreArgs(aggregate, weights);
|
||||
|
||||
return connection.invoke().just(RedisSortedSetAsyncCommands::zunionstore, destKey, storeArgs, sets);
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zdiff, sets).toSet();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], byte[][])
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
public Set<Tuple> zDiffWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zdiffWithScores, sets)
|
||||
.toSet(LettuceConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zDiffStore(byte[], byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zDiffStore(byte[] destKey, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
|
||||
return connection.invoke().just(RedisSortedSetAsyncCommands::zunionstore, destKey, sets);
|
||||
return connection.invoke().just(RedisSortedSetAsyncCommands::zdiffstore, destKey, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInter(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<byte[]> zInter(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zinter, sets).toSet();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zinterWithScores, sets)
|
||||
.toSet(LettuceConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zInterWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
ZAggregateArgs zAggregateArgs = zAggregateArgs(aggregate, weights);
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zinterWithScores, zAggregateArgs, sets)
|
||||
.toSet(LettuceConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -520,6 +570,81 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
return connection.invoke().just(RedisSortedSetAsyncCommands::zinterstore, destKey, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnion(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<byte[]> zUnion(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zunion, sets).toSet();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zunionWithScores, sets)
|
||||
.toSet(LettuceConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionWithScores(org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(sets, "Sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
ZAggregateArgs zAggregateArgs = zAggregateArgs(aggregate, weights);
|
||||
|
||||
return connection.invoke().fromMany(RedisSortedSetAsyncCommands::zunionWithScores, zAggregateArgs, sets)
|
||||
.toSet(LettuceConverters::toTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, Aggregate aggregate, Weights weights, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
Assert.isTrue(weights.size() == sets.length, () -> String
|
||||
.format("The number of weights (%d) must match the number of source sets (%d)!", weights.size(), sets.length));
|
||||
|
||||
ZStoreArgs storeArgs = zStoreArgs(aggregate, weights);
|
||||
|
||||
return connection.invoke().just(RedisSortedSetAsyncCommands::zunionstore, destKey, storeArgs, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], byte[][])
|
||||
*/
|
||||
@Override
|
||||
public Long zUnionStore(byte[] destKey, byte[]... sets) {
|
||||
|
||||
Assert.notNull(destKey, "Destination key must not be null!");
|
||||
Assert.notNull(sets, "Source sets must not be null!");
|
||||
Assert.noNullElements(sets, "Source sets must not contain null elements!");
|
||||
|
||||
return connection.invoke().just(RedisSortedSetAsyncCommands::zunionstore, destKey, sets);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zScan(byte[], org.springframework.data.redis.core.ScanOptions)
|
||||
@@ -684,6 +809,29 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
return args;
|
||||
}
|
||||
|
||||
private static ZAggregateArgs zAggregateArgs(@Nullable Aggregate aggregate, Weights weights) {
|
||||
|
||||
ZAggregateArgs args = new ZAggregateArgs();
|
||||
|
||||
if (aggregate != null) {
|
||||
switch (aggregate) {
|
||||
case MIN:
|
||||
args.min();
|
||||
break;
|
||||
case MAX:
|
||||
args.max();
|
||||
break;
|
||||
default:
|
||||
args.sum();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
args.weights(weights.toArray());
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert {@link ZAddArgs} to {@link io.lettuce.core.ZAddArgs}.
|
||||
*
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -53,7 +54,7 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
Boolean add(V value, double score);
|
||||
|
||||
/**
|
||||
* Add {@code value} to a sorted set at {@code key} if it does not already exists.
|
||||
* Add {@code value} to a sorted set at the bound key if it does not already exists.
|
||||
*
|
||||
* @param score the score.
|
||||
* @param value the value.
|
||||
@@ -75,7 +76,7 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
Long add(Set<TypedTuple<V>> tuples);
|
||||
|
||||
/**
|
||||
* Add {@code tuples} to a sorted set at {@code key} if it does not already exists.
|
||||
* Add {@code tuples} to a sorted set at the bound key if it does not already exists.
|
||||
*
|
||||
* @param tuples must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
@@ -418,41 +419,6 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
Long removeRangeByScore(double min, double max);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K otherKey, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(Collection<K> otherKeys, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
@@ -467,6 +433,127 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
Long unionAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> difference(K otherKey) {
|
||||
return difference(Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> difference(Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> differenceWithScores(K otherKey) {
|
||||
return differenceWithScores(Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> differenceWithScores(Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiffstore">Redis Documentation: ZDIFFSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long differenceAndStore(Collection<K> otherKeys, K destKey);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> intersect(K otherKey) {
|
||||
return intersect(Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> intersect(Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> intersectWithScores(K otherKey) {
|
||||
return intersectWithScores(Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> intersectWithScores(Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> intersectWithScores(Collection<K> otherKeys, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Intersect sorted sets at the bound key and {@code otherKey} and store result in destination {@code destKey}.
|
||||
*
|
||||
@@ -516,6 +603,116 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
Long intersectAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> union(K otherKey) {
|
||||
return union(Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> union(Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> unionWithScores(K otherKey) {
|
||||
return unionWithScores(Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> unionWithScores(Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> unionWithScores(Collection<K> otherKeys, Aggregate aggregate) {
|
||||
return unionWithScores(otherKeys, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> unionWithScores(Collection<K> otherKeys, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K otherKey, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(Collection<K> otherKeys, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at the bound key and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate);
|
||||
|
||||
/**
|
||||
* Iterate over elements in zset at the bound key. <br />
|
||||
* <strong>Important:</strong> Call {@link Cursor#close()} when done to avoid resource leak.
|
||||
|
||||
@@ -108,42 +108,6 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.getOperations();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K otherKey, K destKey) {
|
||||
return ops.intersectAndStore(getKey(), otherKey, destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(Collection<K> otherKeys, K destKey) {
|
||||
return ops.intersectAndStore(getKey(), otherKeys, destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate) {
|
||||
return ops.intersectAndStore(getKey(), otherKeys, destKey, aggregate);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights) {
|
||||
return ops.intersectAndStore(getKey(), otherKeys, destKey, aggregate, weights);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#range(long, long)
|
||||
@@ -402,6 +366,132 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.zCard(getKey());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#difference(java.util.Collection)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<V> difference(Collection<K> otherKeys) {
|
||||
return ops.difference(getKey(), otherKeys);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#differenceWithScores(java.util.Collection)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<TypedTuple<V>> differenceWithScores(Collection<K> otherKeys) {
|
||||
return ops.differenceWithScores(getKey(), otherKeys);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#differenceAndStore(java.util.Collection, java.lang.Object)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Long differenceAndStore(Collection<K> otherKeys, K destKey) {
|
||||
return ops.differenceAndStore(getKey(), otherKeys, destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersect(java.util.Collection)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<V> intersect(Collection<K> otherKeys) {
|
||||
return ops.intersect(getKey(), otherKeys);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectWithScores(java.util.Collection)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<TypedTuple<V>> intersectWithScores(Collection<K> otherKeys) {
|
||||
return ops.intersectWithScores(getKey(), otherKeys);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectWithScores(java.util.Collection, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<TypedTuple<V>> intersectWithScores(Collection<K> otherKeys, Aggregate aggregate, Weights weights) {
|
||||
return ops.intersectWithScores(getKey(), otherKeys, aggregate, weights);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K otherKey, K destKey) {
|
||||
return ops.intersectAndStore(getKey(), otherKey, destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(Collection<K> otherKeys, K destKey) {
|
||||
return ops.intersectAndStore(getKey(), otherKeys, destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate) {
|
||||
return ops.intersectAndStore(getKey(), otherKeys, destKey, aggregate);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights) {
|
||||
return ops.intersectAndStore(getKey(), otherKeys, destKey, aggregate, weights);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#union(java.util.Collection)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<V> union(Collection<K> otherKeys) {
|
||||
return ops.union(getKey(), otherKeys);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#unionWithScores(java.util.Collection)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<TypedTuple<V>> unionWithScores(Collection<K> otherKeys) {
|
||||
return ops.unionWithScores(getKey(), otherKeys);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#unionWithScores(java.util.Collection, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Set<TypedTuple<V>> unionWithScores(Collection<K> otherKeys, Aggregate aggregate, Weights weights) {
|
||||
return ops.unionWithScores(getKey(), otherKeys, aggregate, weights);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#unionAndStore(java.lang.Object, java.lang.Object)
|
||||
|
||||
@@ -130,41 +130,6 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
return execute(connection -> connection.zIncrBy(rawKey, delta, rawValue), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K key, K otherKey, K destKey) {
|
||||
return intersectAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
byte[] rawDestKey = rawKey(destKey);
|
||||
|
||||
return execute(connection -> connection.zInterStore(rawDestKey, rawKeys), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
byte[] rawDestKey = rawKey(destKey);
|
||||
|
||||
return execute(connection -> connection.zInterStore(rawDestKey, aggregate, weights, rawKeys), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#range(java.lang.Object, long, long)
|
||||
@@ -565,6 +530,147 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
return execute(connection -> connection.zCard(rawKey), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#difference(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Set<V> difference(K key, Collection<K> otherKeys) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
Set<byte[]> rawValues = execute(connection -> connection.zDiff(rawKeys), true);
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#differenceWithScores(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Set<TypedTuple<V>> differenceWithScores(K key, Collection<K> otherKeys) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
return deserializeTupleValues(execute(connection -> connection.zDiffWithScores(rawKeys), true));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#differenceAndStore(java.lang.Object, java.util.Collection, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long differenceAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
byte[] rawDestKey = rawKey(destKey);
|
||||
|
||||
return execute(connection -> connection.zDiffStore(rawDestKey, rawKeys), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersect(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Set<V> intersect(K key, Collection<K> otherKeys) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
Set<byte[]> rawValues = execute(connection -> connection.zInter(rawKeys), true);
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectWithScores(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Set<TypedTuple<V>> intersectWithScores(K key, Collection<K> otherKeys) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
return deserializeTupleValues(execute(connection -> connection.zInterWithScores(rawKeys), true));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectWithScores(java.lang.Object, java.util.Collection, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Override
|
||||
public Set<TypedTuple<V>> intersectWithScores(K key, Collection<K> otherKeys, Aggregate aggregate, Weights weights) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
return deserializeTupleValues(
|
||||
execute(connection -> connection.zInterWithScores(aggregate, weights, rawKeys), true));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K key, K otherKey, K destKey) {
|
||||
return intersectAndStore(key, Collections.singleton(otherKey), destKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
byte[] rawDestKey = rawKey(destKey);
|
||||
|
||||
return execute(connection -> connection.zInterStore(rawDestKey, rawKeys), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#intersectAndStore(java.lang.Object, java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Override
|
||||
public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
byte[] rawDestKey = rawKey(destKey);
|
||||
|
||||
return execute(connection -> connection.zInterStore(rawDestKey, aggregate, weights, rawKeys), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#union(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Set<V> union(K key, Collection<K> otherKeys) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
Set<byte[]> rawValues = execute(connection -> connection.zUnion(rawKeys), true);
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#unionWithScores(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Set<TypedTuple<V>> unionWithScores(K key, Collection<K> otherKeys) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
return deserializeTupleValues(execute(connection -> connection.zUnionWithScores(rawKeys), true));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#unionWithScores(java.lang.Object, java.util.Collection, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
|
||||
*/
|
||||
@Override
|
||||
public Set<TypedTuple<V>> unionWithScores(K key, Collection<K> otherKeys, Aggregate aggregate, Weights weights) {
|
||||
|
||||
byte[][] rawKeys = rawKeys(key, otherKeys);
|
||||
return deserializeTupleValues(
|
||||
execute(connection -> connection.zUnionWithScores(aggregate, weights, rawKeys), true));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#unionAndStore(java.lang.Object, java.lang.Object, java.lang.Object)
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.redis.core;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -537,59 +538,150 @@ public interface ZSetOperations<K, V> {
|
||||
Long removeRangeByScore(K key, double min, double max);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Long unionAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate) {
|
||||
return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
|
||||
default Set<V> difference(K key, K otherKey) {
|
||||
return difference(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> difference(K key, Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> differenceWithScores(K key, K otherKey) {
|
||||
return differenceWithScores(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiff">Redis Documentation: ZDIFF</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> differenceWithScores(K key, Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Diff sorted {@code sets} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zdiffstore">Redis Documentation: ZDIFFSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights);
|
||||
Long differenceAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> intersect(K key, K otherKey) {
|
||||
return intersect(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> intersect(K key, Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> intersectWithScores(K key, K otherKey) {
|
||||
return intersectWithScores(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> intersectWithScores(K key, Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Intersect sorted sets at {@code key} and {@code otherKeys} .
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> intersectWithScores(K key, Collection<K> otherKeys, Aggregate aggregate) {
|
||||
return intersectWithScores(key, otherKeys, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zinter">Redis Documentation: ZINTER</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> intersectWithScores(K key, Collection<K> otherKeys, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Intersect sorted sets at {@code key} and {@code otherKey} and store result in destination {@code destKey}.
|
||||
@@ -646,6 +738,142 @@ public interface ZSetOperations<K, V> {
|
||||
@Nullable
|
||||
Long intersectAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> union(K key, K otherKey) {
|
||||
return union(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> union(K key, Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> unionWithScores(K key, K otherKey) {
|
||||
return unionWithScores(key, Collections.singleton(otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> unionWithScores(K key, Collection<K> otherKeys);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} .
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<TypedTuple<V>> unionWithScores(K key, Collection<K> otherKeys, Aggregate aggregate) {
|
||||
return unionWithScores(key, otherKeys, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted {@code sets}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.6
|
||||
* @see <a href="https://redis.io/commands/zunion">Redis Documentation: ZUNION</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<TypedTuple<V>> unionWithScores(K key, Collection<K> otherKeys, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKey must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Long unionAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate) {
|
||||
return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param otherKeys must not be {@literal null}.
|
||||
* @param destKey must not be {@literal null}.
|
||||
* @param aggregate must not be {@literal null}.
|
||||
* @param weights must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.1
|
||||
* @see <a href="https://redis.io/commands/zunionstore">Redis Documentation: ZUNIONSTORE</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long unionAndStore(K key, Collection<K> otherKeys, K destKey, Aggregate aggregate, Weights weights);
|
||||
|
||||
/**
|
||||
* Iterate over elements in zset at {@code key}. <br />
|
||||
* <strong>Important:</strong> Call {@link Cursor#close()} when done to avoid resource leak.
|
||||
@@ -688,38 +916,38 @@ public interface ZSetOperations<K, V> {
|
||||
@Nullable
|
||||
Set<V> rangeByLex(K key, Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
|
||||
* {@link Range#getMin()} and {@link Range#getMax()}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> reverseRangeByLex(K key, Range range) {
|
||||
return reverseRangeByLex(key, range, Limit.unlimited());
|
||||
/**
|
||||
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
|
||||
* {@link Range#getMin()} and {@link Range#getMax()}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
default Set<V> reverseRangeByLex(K key, Range range) {
|
||||
return reverseRangeByLex(key, range, Limit.unlimited());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
|
||||
* {@link Limit#getOffset()} with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value
|
||||
* between {@link Range#getMin()} and {@link Range#getMax()}.
|
||||
*
|
||||
* @param key must not be {@literal null}
|
||||
* @param range must not be {@literal null}.
|
||||
* @param limit can be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> reverseRangeByLex(K key, Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
RedisOperations<K, V> getOperations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
|
||||
* {@link Limit#getOffset()} with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value
|
||||
* between {@link Range#getMin()} and {@link Range#getMax()}.
|
||||
*
|
||||
* @param key must not be {@literal null}
|
||||
* @param range must not be {@literal null}.
|
||||
* @param limit can be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Set<V> reverseRangeByLex(K key, Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
RedisOperations<K, V> getOperations();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user