Skip to content

Commit d76c5be

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Tweak Javadoc. Make tests less strict for random values test. Original Pull Request: #2276
1 parent 4fdb5fd commit d76c5be

File tree

4 files changed

+92
-98
lines changed

4 files changed

+92
-98
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@
7171
* {@link LettuceConnection}s share a single thread-safe native connection by default.
7272
* <p>
7373
* The shared native connection is never closed by {@link LettuceConnection}, therefore it is not validated by default
74-
* on {@link #getConnection()}. Use {@link #setValidateConnection(boolean)} to change this behavior if necessary. Inject
75-
* a {@link Pool} to pool dedicated connections. If shareNativeConnection is true, the pool will be used to select a
76-
* connection for blocking and tx operations only, which should not share a connection. If native connection sharing is
77-
* disabled, the selected connection will be used for all operations.
74+
* on {@link #getConnection()}. Use {@link #setValidateConnection(boolean)} to change this behavior if necessary. If
75+
* {@code shareNativeConnection} is {@literal true}, a shared connection will be used for regular operations and a
76+
* {@link LettuceConnectionProvider} will be used to select a connection for blocking and tx operations only, which
77+
* should not share a connection. If native connection sharing is disabled, new (or pooled) connections will be used for
78+
* all operations.
7879
* <p>
7980
* {@link LettuceConnectionFactory} should be configured using an environmental configuration and the
8081
* {@link LettuceConnectionFactory client configuration}. Lettuce supports the following environmental configurations:

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ <T> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSer
195195
@Nullable
196196
Long countExistingKeys(Collection<K> keys);
197197

198-
199198
/**
200199
* Delete given {@code key}.
201200
*
@@ -367,6 +366,26 @@ default Boolean expireAt(K key, Instant expireAt) {
367366
@Nullable
368367
Boolean persist(K key);
369368

369+
/**
370+
* Get the time to live for {@code key} in seconds.
371+
*
372+
* @param key must not be {@literal null}.
373+
* @return {@literal null} when used in pipeline / transaction.
374+
* @see <a href="https://redis.io/commands/ttl">Redis Documentation: TTL</a>
375+
*/
376+
@Nullable
377+
Long getExpire(K key);
378+
379+
/**
380+
* Get the time to live for {@code key} in and convert it to the given {@link TimeUnit}.
381+
*
382+
* @param key must not be {@literal null}.
383+
* @param timeUnit must not be {@literal null}.
384+
* @return {@literal null} when used in pipeline / transaction.
385+
* @since 1.8
386+
*/
387+
@Nullable
388+
Long getExpire(K key, TimeUnit timeUnit);
370389
/**
371390
* Move given {@code key} to database with {@code index}.
372391
*
@@ -414,27 +433,6 @@ default void restore(K key, byte[] value, long timeToLive, TimeUnit unit) {
414433
*/
415434
void restore(K key, byte[] value, long timeToLive, TimeUnit unit, boolean replace);
416435

417-
/**
418-
* Get the time to live for {@code key} in seconds.
419-
*
420-
* @param key must not be {@literal null}.
421-
* @return {@literal null} when used in pipeline / transaction.
422-
* @see <a href="https://redis.io/commands/ttl">Redis Documentation: TTL</a>
423-
*/
424-
@Nullable
425-
Long getExpire(K key);
426-
427-
/**
428-
* Get the time to live for {@code key} in and convert it to the given {@link TimeUnit}.
429-
*
430-
* @param key must not be {@literal null}.
431-
* @param timeUnit must not be {@literal null}.
432-
* @return {@literal null} when used in pipeline / transaction.
433-
* @since 1.8
434-
*/
435-
@Nullable
436-
Long getExpire(K key, TimeUnit timeUnit);
437-
438436
/**
439437
* Sort the elements for {@code query}.
440438
*

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

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,23 @@ public Boolean copy(K source, K target, boolean replace) {
562562
return doWithKeys(connection -> connection.copy(sourceKey, targetKey, replace));
563563
}
564564

565+
@Override
566+
public Boolean hasKey(K key) {
567+
568+
byte[] rawKey = rawKey(key);
569+
570+
return doWithKeys(connection -> connection.exists(rawKey));
571+
}
572+
573+
@Override
574+
public Long countExistingKeys(Collection<K> keys) {
575+
576+
Assert.notNull(keys, "Keys must not be null!");
577+
578+
byte[][] rawKeys = rawKeys(keys);
579+
return doWithKeys(connection -> connection.exists(rawKeys));
580+
}
581+
565582
@Override
566583
public Boolean delete(K key) {
567584

@@ -606,20 +623,56 @@ public Long unlink(Collection<K> keys) {
606623
}
607624

608625
@Override
609-
public Boolean hasKey(K key) {
626+
public DataType type(K key) {
610627

611628
byte[] rawKey = rawKey(key);
629+
return doWithKeys(connection -> connection.type(rawKey));
630+
}
612631

613-
return doWithKeys(connection -> connection.exists(rawKey));
632+
@Override
633+
@SuppressWarnings("unchecked")
634+
public Set<K> keys(K pattern) {
635+
636+
byte[] rawKey = rawKey(pattern);
637+
Set<byte[]> rawKeys = doWithKeys(connection -> connection.keys(rawKey));
638+
639+
return keySerializer != null ? SerializationUtils.deserialize(rawKeys, keySerializer) : (Set<K>) rawKeys;
614640
}
615641

616642
@Override
617-
public Long countExistingKeys(Collection<K> keys) {
643+
public Cursor<K> scan(ScanOptions options) {
644+
Assert.notNull(options, "ScanOptions must not be null!");
618645

619-
Assert.notNull(keys, "Keys must not be null!");
646+
return executeWithStickyConnection(
647+
(RedisCallback<Cursor<K>>) connection -> new ConvertingCursor<>(connection.scan(options),
648+
this::deserializeKey));
649+
}
620650

621-
byte[][] rawKeys = rawKeys(keys);
622-
return doWithKeys(connection -> connection.exists(rawKeys));
651+
@Override
652+
public K randomKey() {
653+
654+
byte[] rawKey = doWithKeys(RedisKeyCommands::randomKey);
655+
return deserializeKey(rawKey);
656+
}
657+
658+
@Override
659+
public void rename(K oldKey, K newKey) {
660+
661+
byte[] rawOldKey = rawKey(oldKey);
662+
byte[] rawNewKey = rawKey(newKey);
663+
664+
doWithKeys(connection -> {
665+
connection.rename(rawOldKey, rawNewKey);
666+
return null;
667+
});
668+
}
669+
670+
@Override
671+
public Boolean renameIfAbsent(K oldKey, K newKey) {
672+
673+
byte[] rawOldKey = rawKey(oldKey);
674+
byte[] rawNewKey = rawKey(newKey);
675+
return doWithKeys(connection -> connection.renameNX(rawOldKey, rawNewKey));
623676
}
624677

625678
@Override
@@ -652,9 +705,12 @@ public Boolean expireAt(K key, final Date date) {
652705
});
653706
}
654707

655-
// -------------------------------------------------------------------------
656-
// Methods dealing with value operations
657-
// -------------------------------------------------------------------------
708+
@Override
709+
public Boolean persist(K key) {
710+
711+
byte[] rawKey = rawKey(key);
712+
return doWithKeys(connection -> connection.persist(rawKey));
713+
}
658714

659715
@Override
660716
public Long getExpire(K key) {
@@ -664,7 +720,7 @@ public Long getExpire(K key) {
664720
}
665721

666722
@Override
667-
public Long getExpire(K key, final TimeUnit timeUnit) {
723+
public Long getExpire(K key, TimeUnit timeUnit) {
668724

669725
byte[] rawKey = rawKey(key);
670726
return doWithKeys(connection -> {
@@ -677,73 +733,13 @@ public Long getExpire(K key, final TimeUnit timeUnit) {
677733
});
678734
}
679735

680-
@Override
681-
@SuppressWarnings("unchecked")
682-
public Set<K> keys(K pattern) {
683-
684-
byte[] rawKey = rawKey(pattern);
685-
Set<byte[]> rawKeys = doWithKeys(connection -> connection.keys(rawKey));
686-
687-
return keySerializer != null ? SerializationUtils.deserialize(rawKeys, keySerializer) : (Set<K>) rawKeys;
688-
}
689-
690-
@Override
691-
public Cursor<K> scan(ScanOptions options) {
692-
Assert.notNull(options, "ScanOptions must not be null!");
693-
694-
return executeWithStickyConnection(
695-
(RedisCallback<Cursor<K>>) connection -> new ConvertingCursor<>(connection.scan(options),
696-
this::deserializeKey));
697-
}
698-
699-
@Override
700-
public Boolean persist(K key) {
701-
702-
byte[] rawKey = rawKey(key);
703-
return doWithKeys(connection -> connection.persist(rawKey));
704-
}
705-
706736
@Override
707737
public Boolean move(K key, final int dbIndex) {
708738

709739
byte[] rawKey = rawKey(key);
710740
return doWithKeys(connection -> connection.move(rawKey, dbIndex));
711741
}
712742

713-
@Override
714-
public K randomKey() {
715-
716-
byte[] rawKey = doWithKeys(RedisKeyCommands::randomKey);
717-
return deserializeKey(rawKey);
718-
}
719-
720-
@Override
721-
public void rename(K oldKey, K newKey) {
722-
723-
byte[] rawOldKey = rawKey(oldKey);
724-
byte[] rawNewKey = rawKey(newKey);
725-
726-
doWithKeys(connection -> {
727-
connection.rename(rawOldKey, rawNewKey);
728-
return null;
729-
});
730-
}
731-
732-
@Override
733-
public Boolean renameIfAbsent(K oldKey, K newKey) {
734-
735-
byte[] rawOldKey = rawKey(oldKey);
736-
byte[] rawNewKey = rawKey(newKey);
737-
return doWithKeys(connection -> connection.renameNX(rawOldKey, rawNewKey));
738-
}
739-
740-
@Override
741-
public DataType type(K key) {
742-
743-
byte[] rawKey = rawKey(key);
744-
return doWithKeys(connection -> connection.type(rawKey));
745-
}
746-
747743
/**
748744
* Executes the Redis dump command and returns the results. Redis uses a non-standard serialization mechanism and
749745
* includes checksum information, thus the raw bytes are returned as opposed to deserializing with valueSerializer.

src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ public ConsumerStreamReadRequestBuilder<K> consumer(Consumer consumer) {
445445
}
446446

447447
/**
448-
* Configure auto-acknowledgement for stream message consumption. This method is an alias for
449-
* {@link #autoAck(boolean)} for improved readability.
448+
* Configure auto-acknowledgement for stream message consumption.
450449
*
451450
* @param autoAck {@literal true} (default) to auto-acknowledge received messages or {@literal false} for external
452451
* acknowledgement.

0 commit comments

Comments
 (0)