Skip to content

Commit 424026b

Browse files
committed
Add unit tests for the new converter methods
Signed-off-by: Chris Bono <chris.bono@broadcom.com>
1 parent 748e344 commit 424026b

18 files changed

+579
-322
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,20 +2609,21 @@ public List<Long> hTtl(byte[] key, TimeUnit timeUnit, byte[]... fields) {
26092609
return this.delegate.hTtl(key, timeUnit, fields);
26102610
}
26112611

2612-
@Override
2613-
public List<byte[]> hGetDel(@NonNull byte[] key, @NonNull byte[]... fields) {
2614-
return convertAndReturn(delegate.hGetDel(key, fields), Converters.identityConverter());
2615-
}
2616-
2617-
@Override
2618-
public List<byte[]> hGetEx(@NonNull byte[] key, Expiration expiration, @NonNull byte[]... fields) {
2619-
return convertAndReturn(delegate.hGetEx(key, expiration, fields), Converters.identityConverter());
2620-
}
2621-
2622-
@Override
2623-
public Boolean hSetEx(@NonNull byte[] key, @NonNull Map<byte[], byte[]> hashes, HashFieldSetOption condition, Expiration expiration) {
2624-
return convertAndReturn(delegate.hSetEx(key, hashes, condition, expiration), Converters.identityConverter());
2625-
}
2612+
@Override
2613+
public List<byte[]> hGetDel(@NonNull byte[] key, @NonNull byte[]... fields) {
2614+
return convertAndReturn(delegate.hGetDel(key, fields), Converters.identityConverter());
2615+
}
2616+
2617+
@Override
2618+
public List<byte[]> hGetEx(@NonNull byte[] key, @Nullable Expiration expiration, @NonNull byte[]... fields) {
2619+
return convertAndReturn(delegate.hGetEx(key, expiration, fields), Converters.identityConverter());
2620+
}
2621+
2622+
@Override
2623+
public Boolean hSetEx(@NonNull byte[] key, @NonNull Map<byte[], byte[]> hashes, @NonNull HashFieldSetOption condition,
2624+
@Nullable Expiration expiration) {
2625+
return convertAndReturn(delegate.hSetEx(key, hashes, condition, expiration), Converters.identityConverter());
2626+
}
26262627

26272628
public @Nullable List<Long> applyExpiration(String key,
26282629
org.springframework.data.redis.core.types.Expiration expiration,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Set;
2424
import java.util.concurrent.TimeUnit;
2525

26+
import org.jspecify.annotations.NonNull;
2627
import org.jspecify.annotations.NullUnmarked;
2728
import org.jspecify.annotations.Nullable;
2829
import org.springframework.data.geo.Circle;
@@ -1612,14 +1613,15 @@ default List<byte[]> hGetDel(byte[] key, byte[]... fields) {
16121613
/** @deprecated in favor of {@link RedisConnection#hashCommands()}}. */
16131614
@Override
16141615
@Deprecated
1615-
default List<byte[]> hGetEx(byte[] key, Expiration expiration, byte[]... fields) {
1616+
default List<byte[]> hGetEx(byte[] key, @Nullable Expiration expiration, byte[]... fields) {
16161617
return hashCommands().hGetEx(key, expiration, fields);
16171618
}
16181619

16191620
/** @deprecated in favor of {@link RedisConnection#hashCommands()}}. */
16201621
@Override
16211622
@Deprecated
1622-
default Boolean hSetEx(byte[] key, Map<byte[], byte[]> hashes, HashFieldSetOption condition, Expiration expiration) {
1623+
default Boolean hSetEx(byte[] key, Map<byte[], byte[]> hashes, @NonNull HashFieldSetOption condition,
1624+
@Nullable Expiration expiration) {
16231625
return hashCommands().hSetEx(key, hashes, condition, expiration);
16241626
}
16251627

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.TimeUnit;
3030
import java.util.function.Function;
3131

32+
import org.jspecify.annotations.NonNull;
3233
import org.jspecify.annotations.Nullable;
3334
import org.reactivestreams.Publisher;
3435
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -1342,11 +1343,18 @@ default Mono<List<ByteBuffer>> hGetDel(ByteBuffer key, Collection<ByteBuffer> fi
13421343
*/
13431344
Flux<MultiValueResponse<HGetDelCommand, ByteBuffer>> hGetDel(Publisher<HGetDelCommand> commands);
13441345

1346+
/**
1347+
* {@literal HGETEX} {@link Command}.
1348+
*
1349+
* @author Viktoriya Kutsarova
1350+
* @see <a href="https://redis.io/commands/hgetex">Redis Documentation: HGETEX</a>
1351+
* @since 4.0
1352+
*/
13451353
class HGetExCommand extends HashFieldsCommand {
13461354

1347-
private final Expiration expiration;
1355+
private final @Nullable Expiration expiration;
13481356

1349-
private HGetExCommand(@Nullable ByteBuffer key, List<ByteBuffer> fields, Expiration expiration) {
1357+
private HGetExCommand(@Nullable ByteBuffer key, List<ByteBuffer> fields, @Nullable Expiration expiration) {
13501358

13511359
super(key, fields);
13521360

@@ -1357,10 +1365,10 @@ private HGetExCommand(@Nullable ByteBuffer key, List<ByteBuffer> fields, Expirat
13571365
* Creates a new {@link HGetExCommand}.
13581366
*
13591367
* @param fields the {@code fields} names to apply expiration to
1360-
* @param expiration the {@link Expiration} to apply to the given {@literal fields}.
1368+
* @param expiration the optional {@link Expiration} to apply to the given {@literal fields}.
13611369
* @return new instance of {@link HGetExCommand}.
13621370
*/
1363-
public static HGetExCommand expire(List<ByteBuffer> fields, Expiration expiration) {
1371+
public static HGetExCommand expire(List<ByteBuffer> fields, @Nullable Expiration expiration) {
13641372
return new HGetExCommand(null, fields, expiration);
13651373
}
13661374

@@ -1382,7 +1390,7 @@ public HGetExCommand fields(Collection<ByteBuffer> fields) {
13821390
return new HGetExCommand(getKey(), new ArrayList<>(fields), expiration);
13831391
}
13841392

1385-
public Expiration getExpiration() {
1393+
public @Nullable Expiration getExpiration() {
13861394
return expiration;
13871395
}
13881396
}
@@ -1392,11 +1400,12 @@ public Expiration getExpiration() {
13921400
* time-to-live (TTL) for given {@literal fields}.
13931401
*
13941402
* @param key must not be {@literal null}.
1403+
* @param expiration the optional expiration to set.
13951404
* @param fields must not be {@literal null}.
13961405
* @return never {@literal null}.
13971406
* @see <a href="https://redis.io/commands/hgetex">Redis Documentation: HGETEX</a>
13981407
*/
1399-
default Mono<List<ByteBuffer>> hGetEx(ByteBuffer key, Expiration expiration, List<ByteBuffer> fields) {
1408+
default Mono<List<ByteBuffer>> hGetEx(ByteBuffer key, @Nullable Expiration expiration, List<ByteBuffer> fields) {
14001409

14011410
Assert.notNull(key, "Key must not be null");
14021411
Assert.notNull(fields, "Fields must not be null");
@@ -1419,16 +1428,17 @@ default Mono<List<ByteBuffer>> hGetEx(ByteBuffer key, Expiration expiration, Lis
14191428
* {@literal HSETEX} {@link Command}.
14201429
*
14211430
* @author Viktoriya Kutsarova
1431+
* @since 4.0
14221432
* @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
14231433
*/
14241434
class HSetExCommand extends KeyCommand {
14251435

14261436
private final Map<ByteBuffer, ByteBuffer> fieldValueMap;
14271437
private final RedisHashCommands.HashFieldSetOption condition;
1428-
private final Expiration expiration;
1438+
private final @Nullable Expiration expiration;
14291439

14301440
private HSetExCommand(@Nullable ByteBuffer key, Map<ByteBuffer, ByteBuffer> fieldValueMap,
1431-
RedisHashCommands.HashFieldSetOption condition, Expiration expiration) {
1441+
RedisHashCommands.HashFieldSetOption condition, @Nullable Expiration expiration) {
14321442
super(key);
14331443
this.fieldValueMap = fieldValueMap;
14341444
this.condition = condition;
@@ -1440,11 +1450,11 @@ private HSetExCommand(@Nullable ByteBuffer key, Map<ByteBuffer, ByteBuffer> fiel
14401450
*
14411451
* @param fieldValueMap the field-value pairs to set; must not be {@literal null}.
14421452
* @param condition the condition for setting fields; must not be {@literal null}.
1443-
* @param expiration the expiration to apply; must not be {@literal null}.
1453+
* @param expiration the optional expiration to apply.
14441454
* @return new instance of {@link HSetExCommand}.
14451455
*/
14461456
public static HSetExCommand setWithConditionAndExpiration(Map<ByteBuffer, ByteBuffer> fieldValueMap,
1447-
RedisHashCommands.HashFieldSetOption condition, Expiration expiration) {
1457+
RedisHashCommands.HashFieldSetOption condition, @Nullable Expiration expiration) {
14481458
return new HSetExCommand(null, fieldValueMap, condition, expiration);
14491459
}
14501460

@@ -1476,7 +1486,7 @@ public RedisHashCommands.HashFieldSetOption getCondition() {
14761486
/**
14771487
* @return the expiration to apply.
14781488
*/
1479-
public Expiration getExpiration() {
1489+
public @Nullable Expiration getExpiration() {
14801490
return expiration;
14811491
}
14821492
}
@@ -1487,17 +1497,16 @@ public Expiration getExpiration() {
14871497
* @param key must not be {@literal null}.
14881498
* @param fieldValueMap the field-value pairs to set; must not be {@literal null}.
14891499
* @param condition the condition for setting fields; must not be {@literal null}.
1490-
* @param expiration the expiration to apply; must not be {@literal null}.
1500+
* @param expiration the optional expiration to apply
14911501
* @return never {@literal null}.
14921502
* @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
14931503
*/
14941504
default Mono<Boolean> hSetEx(ByteBuffer key, Map<ByteBuffer, ByteBuffer> fieldValueMap,
1495-
RedisHashCommands.HashFieldSetOption condition, Expiration expiration) {
1505+
RedisHashCommands.@NonNull HashFieldSetOption condition, @Nullable Expiration expiration) {
14961506

14971507
Assert.notNull(key, "Key must not be null");
14981508
Assert.notNull(fieldValueMap, "Field-value map must not be null");
14991509
Assert.notNull(condition, "Condition must not be null");
1500-
Assert.notNull(expiration, "Expiration must not be null");
15011510

15021511
return hSetEx(Mono.just(HSetExCommand.setWithConditionAndExpiration(fieldValueMap, condition, expiration)
15031512
.from(key)))

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import org.jspecify.annotations.NonNull;
2525
import org.jspecify.annotations.NullUnmarked;
26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.data.redis.core.Cursor;
2729
import org.springframework.data.redis.core.ScanOptions;
2830
import org.springframework.data.redis.core.types.Expiration;
@@ -562,26 +564,27 @@ default List<Long> hExpireAt(byte @NonNull [] key, long unixTime, byte @NonNull
562564
* time-to-live (TTL) for given {@code fields}.
563565
*
564566
* @param key must not be {@literal null}.
567+
* @param expiration the optional expiration to apply.
565568
* @param fields must not be {@literal null}.
566569
* @return list of values for given {@code fields} or an empty {@link List} if key does not
567570
* exist or {@literal null} when used in pipeline / transaction.
568571
* @see <a href="https://redis.io/commands/hgetex">Redis Documentation: HGETEX</a>
569572
*/
570-
List<byte[]> hGetEx(byte @NonNull [] key, Expiration expiration,
573+
List<byte[]> hGetEx(byte @NonNull [] key, @Nullable Expiration expiration,
571574
byte @NonNull [] @NonNull ... fields);
572575

573576
/**
574577
* Set field-value pairs in hash at {@literal key} with optional condition and expiration.
575578
*
576579
* @param key must not be {@literal null}.
577580
* @param hashes the field-value pairs to set; must not be {@literal null}.
578-
* @param hashFieldSetOption the optional condition for setting fields.
581+
* @param hashFieldSetOption the condition for setting fields; must not be {@literal null}.
579582
* @param expiration the optional expiration to apply.
580583
* @return never {@literal null}.
581584
* @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
582585
*/
583-
Boolean hSetEx(byte @NonNull [] key, @NonNull Map<byte[], byte[]> hashes, HashFieldSetOption hashFieldSetOption,
584-
Expiration expiration);
586+
Boolean hSetEx(byte @NonNull [] key, @NonNull Map<byte[], byte[]> hashes,
587+
@NonNull HashFieldSetOption hashFieldSetOption, @Nullable Expiration expiration);
585588

586589
/**
587590
* {@code HSETEX} command arguments for {@code FNX}, {@code FXX}.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,8 +2599,8 @@ List<Long> hpExpireAt(@NonNull String key, long unixTimeInMillis, ExpirationOpti
25992599
* @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
26002600
* @see RedisHashCommands#hSetEx(byte[], Map, HashFieldSetOption, Expiration)
26012601
*/
2602-
Boolean hSetEx(@NonNull String key, @NonNull Map<@NonNull String, String> hashes, HashFieldSetOption condition,
2603-
Expiration expiration);
2602+
Boolean hSetEx(@NonNull String key, @NonNull Map<@NonNull String, String> hashes,
2603+
@NonNull HashFieldSetOption condition, @Nullable Expiration expiration);
26042604

26052605
// -------------------------------------------------------------------------
26062606
// Methods dealing with HyperLogLog

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterHashCommands.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.redis.connection.jedis;
1717

18-
import org.springframework.data.redis.core.types.Expiration;
1918
import redis.clients.jedis.args.ExpiryOption;
2019
import redis.clients.jedis.params.ScanParams;
2120
import redis.clients.jedis.resps.ScanResult;
@@ -27,6 +26,7 @@
2726
import java.util.Set;
2827
import java.util.concurrent.TimeUnit;
2928

29+
import org.jspecify.annotations.NonNull;
3030
import org.jspecify.annotations.Nullable;
3131
import org.springframework.dao.DataAccessException;
3232
import org.springframework.data.redis.connection.ExpirationOptions;
@@ -35,6 +35,7 @@
3535
import org.springframework.data.redis.core.ScanCursor;
3636
import org.springframework.data.redis.core.ScanIteration;
3737
import org.springframework.data.redis.core.ScanOptions;
38+
import org.springframework.data.redis.core.types.Expiration;
3839
import org.springframework.util.Assert;
3940

4041
/**
@@ -415,44 +416,47 @@ public List<Long> hpTtl(byte[] key, byte[]... fields) {
415416
}
416417
}
417418

418-
@Override
419-
public List<byte[]> hGetDel(byte[] key, byte[]... fields) {
419+
@Override
420+
public List<byte[]> hGetDel(byte[] key, byte[]... fields) {
420421

421-
Assert.notNull(key, "Key must not be null");
422-
Assert.notNull(fields, "Fields must not be null");
422+
Assert.notNull(key, "Key must not be null");
423+
Assert.notNull(fields, "Fields must not be null");
423424

424-
try {
425-
return connection.getCluster().hgetdel(key, fields);
426-
} catch (Exception ex) {
427-
throw convertJedisAccessException(ex);
428-
}
429-
}
425+
try {
426+
return connection.getCluster().hgetdel(key, fields);
427+
} catch (Exception ex) {
428+
throw convertJedisAccessException(ex);
429+
}
430+
}
430431

431-
@Override
432-
public List<byte[]> hGetEx(byte[] key, Expiration expiration, byte[]... fields) {
432+
@Override
433+
public List<byte[]> hGetEx(byte[] key, @Nullable Expiration expiration, byte[]... fields) {
433434

434-
Assert.notNull(key, "Key must not be null");
435-
Assert.notNull(fields, "Fields must not be null");
435+
Assert.notNull(key, "Key must not be null");
436+
Assert.notNull(fields, "Fields must not be null");
436437

437-
try {
438-
return connection.getCluster().hgetex(key, JedisConverters.toHGetExParams(expiration), fields);
439-
} catch (Exception ex) {
440-
throw convertJedisAccessException(ex);
441-
}
442-
}
438+
try {
439+
return connection.getCluster().hgetex(key, JedisConverters.toHGetExParams(expiration), fields);
440+
} catch (Exception ex) {
441+
throw convertJedisAccessException(ex);
442+
}
443+
}
443444

444-
@Override
445-
public Boolean hSetEx(byte[] key, Map<byte[], byte[]> hashes, HashFieldSetOption condition, Expiration expiration) {
445+
@Override
446+
public Boolean hSetEx(byte[] key, Map<byte[], byte[]> hashes, @NonNull HashFieldSetOption condition,
447+
@Nullable Expiration expiration) {
446448

447-
Assert.notNull(key, "Key must not be null");
448-
Assert.notNull(hashes, "Fields must not be null");
449+
Assert.notNull(key, "Key must not be null");
450+
Assert.notNull(hashes, "Fields must not be null");
451+
Assert.notNull(condition, "Condition must not be null");
449452

450-
try {
451-
return JedisConverters.toBoolean(connection.getCluster().hsetex(key, JedisConverters.toHSetExParams(condition, expiration), hashes));
452-
} catch (Exception ex) {
453-
throw convertJedisAccessException(ex);
454-
}
455-
}
453+
try {
454+
return JedisConverters.toBoolean(
455+
connection.getCluster().hsetex(key, JedisConverters.toHSetExParams(condition, expiration), hashes));
456+
} catch (Exception ex) {
457+
throw convertJedisAccessException(ex);
458+
}
459+
}
456460

457461
@Nullable
458462
@Override

0 commit comments

Comments
 (0)