Skip to content

Commit

Permalink
Adopt Set test to also run on Redis 7 #2349
Browse files Browse the repository at this point in the history
Before this pr, `sscanMultiple` will fail at `assertThat(cursor.getCursor()).isNotNull().isNotEqualTo("0");`
This is because the bottom layer is the ListPack structure at this time. It does not support the count option.
It will return all values and set the CURSOR to 0.

see https://redis.io/commands/scan/ *Why SCAN may return all the items of an aggregate data type in a single call?*
for more info.
  • Loading branch information
yangbodong22011 authored and mp911de committed Apr 18, 2023
1 parent 99934ba commit f5895e1
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void sscanMultiple() {

Set<String> expect = new HashSet<>();
Set<String> check = new HashSet<>();
setup100KeyValues(expect);
setup129KeyValues(expect);

ValueScanCursor<String> cursor = redis.sscan(key, ScanArgs.Builder.limit(5));

Expand All @@ -379,18 +379,20 @@ void sscanMultiple() {
void scanMatch() {

Set<String> expect = new HashSet<>();
setup100KeyValues(expect);
setup129KeyValues(expect);

ValueScanCursor<String> cursor = redis.sscan(key, ScanArgs.Builder.limit(200).match("value1*"));

assertThat(cursor.getCursor()).isEqualTo("0");
assertThat(cursor.isFinished()).isTrue();

assertThat(cursor.getValues()).hasSize(11);
assertThat(cursor.getValues()).hasSize(40);
}

void setup100KeyValues(Set<String> expect) {
for (int i = 0; i < 100; i++) {
void setup129KeyValues(Set<String> expect) {
// Redis 7.0 introduce listpack, and `set-max-listpack-entries` is 128
// so we add 129 elements to convert it to hashtable
for (int i = 0; i < 129; i++) {
redis.sadd(key, value + i);
expect.add(value + i);
}
Expand Down

0 comments on commit f5895e1

Please sign in to comment.