Skip to content

Commit 0ee04a7

Browse files
jankovdchristophstrobl
authored andcommitted
DATAREDIS-1207 - Fix LettuceStreamCommands.xRevRange Range conversion.
LettuceStreamCommands.xRevRange converts Ranges with a StringCodec that produces Boundary<ByteBuffer>, while Lettuce expects the range's Boundary to include strings. The conversion worked well only in cases where the Range was unbounded (- or +), and failed with ClassCastException on the consuming site for other cases. Original pull request: #556
1 parent 9b87d3f commit 0ee04a7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceStreamCommands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
/**
4848
* @author Mark Paluch
4949
* @author Tugdual Grall
50+
* @author Dejan Jankov
5051
* @since 2.2
5152
*/
5253
class LettuceStreamCommands implements RedisStreamCommands {
@@ -632,7 +633,7 @@ public List<ByteRecord> xRevRange(byte[] key, Range<String> range, Limit limit)
632633
Assert.notNull(range, "Range must not be null!");
633634
Assert.notNull(limit, "Limit must not be null!");
634635

635-
io.lettuce.core.Range<String> lettuceRange = RangeConverter.toRange(range);
636+
io.lettuce.core.Range<String> lettuceRange = RangeConverter.toRange(range, Function.identity());
636637
io.lettuce.core.Limit lettuceLimit = LettuceConverters.toLimit(limit);
637638
try {
638639
if (isPipelined()) {

src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
* @author Thomas Darimont
100100
* @author Mark Paluch
101101
* @author Tugdual Grall
102+
* @author Dejan Jankov
102103
*/
103104
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
104105
public abstract class AbstractConnectionIntegrationTests {
@@ -3125,6 +3126,28 @@ public void xRevRangeShouldReportMessages() {
31253126
assertThat(messages.get(1).getValue()).isEqualTo(Collections.singletonMap(KEY_2, VALUE_2));
31263127
}
31273128

3129+
@Test // DATAREDIS-1207
3130+
@IfProfileValue(name = "redisVersion", value = "5.0")
3131+
@WithRedisDriver({ RedisDriver.LETTUCE })
3132+
public void xRevRangeShouldWorkWithBoundedRange() {
3133+
3134+
actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2)));
3135+
actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3)));
3136+
actual.add(connection.xRevRange(KEY_1, org.springframework.data.domain.Range.closed("0-0", "+")));
3137+
3138+
List<Object> results = getResults();
3139+
assertThat(results).hasSize(3);
3140+
3141+
List<MapRecord<String, String, String>> messages = (List) results.get(2);
3142+
assertThat(messages).hasSize(2);
3143+
3144+
assertThat(messages.get(0).getStream()).isEqualTo(KEY_1);
3145+
assertThat(messages.get(0).getValue()).isEqualTo(Collections.singletonMap(KEY_3, VALUE_3));
3146+
3147+
assertThat(messages.get(1).getStream()).isEqualTo(KEY_1);
3148+
assertThat(messages.get(1).getValue()).isEqualTo(Collections.singletonMap(KEY_2, VALUE_2));
3149+
}
3150+
31283151
@Test // DATAREDIS-1084
31293152
@IfProfileValue(name = "redisVersion", value = "5.0")
31303153
@WithRedisDriver({ RedisDriver.LETTUCE })

0 commit comments

Comments
 (0)