Skip to content

Commit 47c7ce2

Browse files
Polishing stream commands changes
Signed-off-by: viktoriya.kutsarova <viktoriya.kutsarova@redis.com>
1 parent da57163 commit 47c7ce2

12 files changed

+449
-198
lines changed

src/main/java/org/springframework/data/redis/connection/ClusterTopology.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public RedisClusterNode lookup(String nodeId) {
186186
}
187187

188188
/**
189-
* Get the {@link RedisClusterNode} matching matching either {@link RedisClusterNode#getHost() host} and
189+
* Get the {@link RedisClusterNode} matching either {@link RedisClusterNode#getHost() host} and
190190
* {@link RedisClusterNode#getPort() port} or {@link RedisClusterNode#getId() nodeId}
191191
*
192192
* @param node must not be {@literal null}

src/main/java/org/springframework/data/redis/connection/ReactiveStreamCommands.java

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
3434
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
3535
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
36+
import org.springframework.data.redis.connection.RedisStreamCommands.MaxLenTrimStrategy;
37+
import org.springframework.data.redis.connection.RedisStreamCommands.TrimOperator;
38+
import org.springframework.data.redis.connection.RedisStreamCommands.TrimOptions;
39+
import org.springframework.data.redis.connection.RedisStreamCommands.TrimStrategy;
3640
import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions;
3741
import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions;
3842
import org.springframework.data.redis.connection.RedisStreamCommands.XDelOptions;
@@ -639,7 +643,7 @@ public static DeleteExCommand stream(ByteBuffer key) {
639643

640644
Assert.notNull(key, "Key must not be null");
641645

642-
return new DeleteExCommand(key, Collections.emptyList(), XDelOptions.defaultOptions());
646+
return new DeleteExCommand(key, Collections.emptyList(), XDelOptions.defaults());
643647
}
644648

645649
/**
@@ -726,7 +730,7 @@ public static AcknowledgeDeleteCommand stream(ByteBuffer key) {
726730

727731
Assert.notNull(key, "Key must not be null");
728732

729-
return new AcknowledgeDeleteCommand(key, null, Collections.emptyList(), XDelOptions.defaultOptions());
733+
return new AcknowledgeDeleteCommand(key, null, Collections.emptyList(), XDelOptions.defaults());
730734
}
731735

732736
/**
@@ -1895,23 +1899,40 @@ private TrimCommand(@Nullable ByteBuffer key, XTrimOptions options) {
18951899
*
18961900
* @param key must not be {@literal null}.
18971901
* @return a new {@link TrimCommand} for {@link ByteBuffer key}.
1902+
* @since 4.0
1903+
* @deprecated since 4.0, prefer {@link #stream(ByteBuffer, XTrimOptions)} instead.
18981904
*/
1905+
@Deprecated(since = "4.0", forRemoval = false)
18991906
public static TrimCommand stream(ByteBuffer key) {
19001907

19011908
Assert.notNull(key, "Key must not be null");
19021909

1903-
return new TrimCommand(key, XTrimOptions.none());
1910+
return new TrimCommand(key, XTrimOptions.trim(TrimOptions.maxLen(0)));
19041911
}
19051912

19061913
/**
1907-
* Applies the numeric {@literal limit}. Constructs a new command instance with all previously configured
1914+
* Creates a new {@link TrimCommand} given a {@link ByteBuffer key} and {@link XTrimOptions}.
1915+
*
1916+
* @param key must not be {@literal null}.
1917+
* @param options must not be {@literal null}.
1918+
* @return a new {@link TrimCommand} for {@link ByteBuffer key}.
1919+
* @since 4.0
1920+
*/
1921+
public static TrimCommand stream(ByteBuffer key, XTrimOptions options) {
1922+
return new TrimCommand(key, options);
1923+
}
1924+
1925+
/**
1926+
* Applies the numeric {@literal threshold}. Constructs a new command instance with all previously configured
19081927
* properties.
19091928
*
1910-
* @param limit
1911-
* @return a new {@link TrimCommand} with {@literal limit} applied.
1929+
* @param threshold
1930+
* @return a new {@link TrimCommand} with {@literal threshold} applied.
19121931
*/
1913-
public TrimCommand to(long limit) {
1914-
return new TrimCommand(getKey(), options.limit(limit));
1932+
@Deprecated(since = "4.0", forRemoval = false)
1933+
public TrimCommand to(long threshold) {
1934+
// should I change only the maxLen here to keep backwards compatible? or the whole concept is off?
1935+
return new TrimCommand(getKey(), XTrimOptions.trim(TrimOptions.maxLen(threshold)));
19151936
}
19161937

19171938
/**
@@ -1920,6 +1941,7 @@ public TrimCommand to(long limit) {
19201941
* @return a new {@link TrimCommand} with {@literal approximateTrimming} applied.
19211942
* @since 2.4
19221943
*/
1944+
@Deprecated(since = "4.0", forRemoval = false)
19231945
public TrimCommand approximate() {
19241946
return approximate(true);
19251947
}
@@ -1931,36 +1953,44 @@ public TrimCommand approximate() {
19311953
* @return a new {@link TrimCommand} with {@literal approximateTrimming} applied.
19321954
* @since 2.4
19331955
*/
1956+
@Deprecated(since = "4.0", forRemoval = false)
19341957
public TrimCommand approximate(boolean approximateTrimming) {
1935-
return new TrimCommand(getKey(), options.approximateTrimming(approximateTrimming));
1958+
if (approximateTrimming) {
1959+
return new TrimCommand(getKey(), XTrimOptions.trim(options.getTrimOptions().approximate()));
1960+
}
1961+
return new TrimCommand(getKey(), XTrimOptions.trim(options.getTrimOptions().exact()));
19361962
}
19371963

19381964
/**
19391965
* Apply the given {@link XTrimOptions} to configure the {@literal XTRIM} command.
19401966
* <p>
19411967
* This method allows setting all XTRIM options at once, including trimming strategies
1942-
* ({@literal MAXLEN}, {@literal MINID}), stream creation behavior ({@literal NOMKSTREAM}),
1943-
* and other parameters. Constructs a new command instance with all previously configured
1944-
* properties except the options, which are replaced by the provided {@link XTrimOptions}.
1968+
* ({@literal MAXLEN}, {@literal MINID}) and other parameters. Constructs a new command instance with all
1969+
* previously configured properties except the options, which are replaced by the provided {@link XTrimOptions}.
19451970
*
19461971
* @param options the {@link XTrimOptions} to apply. Must not be {@literal null}.
19471972
* @return a new {@link TrimCommand} with the specified options applied.
19481973
* @since 4.0
19491974
*/
1950-
public TrimCommand withOptions(XTrimOptions options) {
1975+
public TrimCommand options(XTrimOptions options) {
19511976
return new TrimCommand(getKey(), options);
19521977
}
19531978

19541979
/**
19551980
* @return can be {@literal null}.
19561981
*/
1982+
@Deprecated(since = "4.0", forRemoval = false)
19571983
public @Nullable Long getCount() {
1958-
return options.getLimit();
1984+
TrimStrategy strategy = options.getTrimOptions().getTrimStrategy();
1985+
if (strategy instanceof MaxLenTrimStrategy maxLen) {
1986+
return maxLen.threshold();
1987+
}
1988+
return null;
19591989
}
19601990

19611991

19621992
public boolean isApproximateTrimming() {
1963-
return options.isApproximateTrimming();
1993+
return options.getTrimOptions().getTrimOperator() == TrimOperator.APPROXIMATE;
19641994
}
19651995

19661996
public XTrimOptions getOptions() {
@@ -2002,7 +2032,7 @@ default Mono<Long> xTrim(ByteBuffer key, XTrimOptions options) {
20022032

20032033
Assert.notNull(key, "Key must not be null");
20042034

2005-
return xTrim(Mono.just(TrimCommand.stream(key).withOptions(options))).next()
2035+
return xTrim(Mono.just(TrimCommand.stream(key).options(options))).next()
20062036
.map(NumericResponse::getOutput);
20072037
}
20082038

0 commit comments

Comments
 (0)