Skip to content

Commit e5cec58

Browse files
jxblumchristophstrobl
authored andcommitted
Fix RedisCommand.requiresArguments for zero argument length.
Closes #2646 Original Pull Request: #2647
1 parent 59a7266 commit e5cec58

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/main/java/org/springframework/data/redis/core/RedisCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ public static RedisCommand failsafeCommandLookup(String key) {
257257
private final boolean read;
258258
private final boolean write;
259259

260-
private final int minArgs;
261-
private final int maxArgs;
260+
final int minArgs;
261+
final int maxArgs;
262262

263263
private final @Nullable String alias;
264264

@@ -313,7 +313,7 @@ public static RedisCommand failsafeCommandLookup(String key) {
313313
* @return {@literal true} if the command requires arguments
314314
*/
315315
public boolean requiresArguments() {
316-
return minArgs >= 0;
316+
return minArgs > 0;
317317
}
318318

319319
/**

src/test/java/org/springframework/data/redis/core/RedisCommandUnitTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20+
import java.util.Arrays;
21+
2022
import org.junit.jupiter.api.Test;
2123

2224
/**
@@ -117,4 +119,23 @@ void isRepresentedByIsCorrectForAllCommandsAndTheirAliases() {
117119
}
118120
}
119121
}
122+
123+
@Test // GH-2646
124+
void commandRequiresArgumentsIsCorrect() {
125+
126+
Arrays.stream(RedisCommand.values()).forEach(command ->
127+
assertThat(command.requiresArguments())
128+
.describedAs("Redis command [%s] failed required arguments check", command)
129+
.isEqualTo(command.minArgs > 0));
130+
}
131+
132+
@Test // GH-2646
133+
void commandRequiresExactNumberOfArgumentsIsCorrect() {
134+
135+
Arrays.stream(RedisCommand.values()).forEach(command ->
136+
assertThat(command.requiresExactNumberOfArguments())
137+
.describedAs("Redis command [%s] failed requires exact arguments check")
138+
.isEqualTo(command.minArgs == command.maxArgs));
139+
}
140+
120141
}

0 commit comments

Comments
 (0)