Skip to content

Commit 8c8ba7a

Browse files
mp911dechristophstrobl
authored andcommitted
DATAREDIS-1031 - Fix reactive pExpire/pExpireAt to invoke correct command.
We now invoke the correct PEXPIRE(AT) command. Previously, we invoked EXPIRE/EXPIREAT commands resulting in the wrong command being called. Original Pull Request: #474
1 parent 1ec61c5 commit 8c8ba7a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ default Mono<List<ByteBuffer>> keys(ByteBuffer pattern) {
131131
* Find all keys matching the given {@literal pattern}.<br />
132132
* It is recommended to use {@link #scan(ScanOptions)} to iterate over the keyspace as {@link #keys(Publisher)} is a
133133
* non-interruptible and expensive Redis operation.
134-
*
134+
*
135135
* @param patterns must not be {@literal null}.
136136
* @return
137137
* @see <a href="https://redis.io/commands/keys">Redis Documentation: KEYS</a>
@@ -462,7 +462,7 @@ default Mono<Boolean> pExpire(ByteBuffer key, Duration timeout) {
462462
Assert.notNull(key, "Key must not be null!");
463463
Assert.notNull(timeout, "Timeout must not be null!");
464464

465-
return expire(Mono.just(new ExpireCommand(key, timeout))).next().map(BooleanResponse::getOutput);
465+
return pExpire(Mono.just(new ExpireCommand(key, timeout))).next().map(BooleanResponse::getOutput);
466466
}
467467

468468
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public Flux<BooleanResponse<ExpireCommand>> pExpire(Publisher<ExpireCommand> com
262262
Assert.notNull(command.getKey(), "Key must not be null!");
263263
Assert.notNull(command.getTimeout(), "Timeout must not be null!");
264264

265-
return cmd.pexpire(command.getKey(), command.getTimeout().getSeconds())
265+
return cmd.pexpire(command.getKey(), command.getTimeout().toMillis())
266266
.map(value -> new BooleanResponse<>(command, value));
267267
}));
268268
}
@@ -294,7 +294,7 @@ public Flux<BooleanResponse<ExpireAtCommand>> pExpireAt(Publisher<ExpireAtComman
294294
Assert.notNull(command.getKey(), "Key must not be null!");
295295
Assert.notNull(command.getExpireAt(), "Expire at must not be null!");
296296

297-
return cmd.expireat(command.getKey(), command.getExpireAt().toEpochMilli())
297+
return cmd.pexpireat(command.getKey(), command.getExpireAt().toEpochMilli())
298298
.map(value -> new BooleanResponse<>(command, value));
299299
}));
300300
}

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsTests.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public void shouldExpireKeysCorrectly() {
278278
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
279279
}
280280

281-
@Test // DATAREDIS-602
281+
@Test // DATAREDIS-602, DATAREDIS-1031
282282
public void shouldPreciseExpireKeysCorrectly() {
283283

284284
nativeCommands.set(KEY_1, VALUE_1);
@@ -289,9 +289,10 @@ public void shouldPreciseExpireKeysCorrectly() {
289289
.verify();
290290

291291
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
292+
assertThat(nativeCommands.ttl(KEY_1), is(lessThan(11L)));
292293
}
293294

294-
@Test // DATAREDIS-602
295+
@Test // DATAREDIS-602, DATAREDIS-1031
295296
public void shouldExpireAtKeysCorrectly() {
296297

297298
nativeCommands.set(KEY_1, VALUE_1);
@@ -303,9 +304,10 @@ public void shouldExpireAtKeysCorrectly() {
303304
.verify();
304305

305306
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
307+
assertThat(nativeCommands.ttl(KEY_1), is(lessThan(11L)));
306308
}
307309

308-
@Test // DATAREDIS-602
310+
@Test // DATAREDIS-602, DATAREDIS-1031
309311
public void shouldPreciseExpireAtKeysCorrectly() {
310312

311313
nativeCommands.set(KEY_1, VALUE_1);
@@ -317,6 +319,7 @@ public void shouldPreciseExpireAtKeysCorrectly() {
317319
.verify();
318320

319321
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
322+
assertThat(nativeCommands.ttl(KEY_1), is(lessThan(11L)));
320323
}
321324

322325
@Test // DATAREDIS-602

0 commit comments

Comments
 (0)