Skip to content

Commit 77898d4

Browse files
committed
Polishing.
Reword Javadoc comments for clarity and add missing `@SuppressWarnings` annotations. See #2970
1 parent 8b7f39b commit 77898d4

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

Diff for: src/main/java/org/springframework/data/redis/core/RedisOperations.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ default void restore(K key, byte[] value, long timeToLive, TimeUnit unit) {
650650
<HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key);
651651

652652
/**
653-
* @return
653+
* @return never {@literal null}.
654654
* @since 1.5
655655
*/
656656
HyperLogLogOperations<K, V> opsForHyperLogLog();

Diff for: src/main/java/org/springframework/data/redis/core/RedisTemplate.java

+44-21
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@
6666
* Redis store. By default, it uses Java serialization for its objects (through {@link JdkSerializationRedisSerializer}
6767
* ). For String intensive operations consider the dedicated {@link StringRedisTemplate}.
6868
* <p>
69-
* The central method is execute, supporting Redis access code implementing the {@link RedisCallback} interface. It
70-
* provides {@link RedisConnection} handling such that neither the {@link RedisCallback} implementation nor the calling
71-
* code needs to explicitly care about retrieving/closing Redis connections, or handling Connection lifecycle
72-
* exceptions. For typical single step actions, there are various convenience methods.
69+
* The central method is {@link #execute(RedisCallback)}, supporting Redis access code implementing the
70+
* {@link RedisCallback} interface. It provides {@link RedisConnection} handling such that neither the
71+
* {@link RedisCallback} implementation nor the calling code needs to explicitly care about retrieving/closing Redis
72+
* connections, or handling Connection lifecycle exceptions. For typical single step actions, there are various
73+
* convenience methods.
7374
* <p>
7475
* Once configured, this class is thread-safe.
7576
* <p>
@@ -121,7 +122,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
121122
private final ClusterOperations<K, V> clusterOps = new DefaultClusterOperations<>(this);
122123

123124
/**
124-
* Constructs a new <code>RedisTemplate</code> instance.
125+
* Constructs a new {@code RedisTemplate} instance.
125126
*/
126127
public RedisTemplate() {}
127128

@@ -160,46 +161,59 @@ public void afterPropertiesSet() {
160161
}
161162

162163
/**
163-
* Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the
164-
* default).
164+
* Returns whether the underlying RedisConnection should be directly exposed to the RedisCallback code, or rather a
165+
* connection proxy (default behavior).
165166
*
166-
* @return whether to expose the native Redis connection or not
167+
* @return {@literal true} to expose the native Redis connection or {@literal false} to provide a proxied connection
168+
* to RedisCallback code.
167169
*/
168170
public boolean isExposeConnection() {
169171
return exposeConnection;
170172
}
171173

172174
/**
173-
* Sets whether to expose the Redis connection to {@link RedisCallback} code. Default is "false": a proxy will be
174-
* returned, suppressing {@code quit} and {@code disconnect} calls.
175+
* Sets whether the underlying RedisConnection should be directly exposed to the RedisCallback code. By default, the
176+
* connection is not exposed, and a proxy is used instead. This proxy suppresses potentially disruptive operations,
177+
* such as {@code quit} and {@code disconnect} commands, ensuring that the connection remains stable during the
178+
* callback execution. Defaults to proxy use.
175179
*
176-
* @param exposeConnection
180+
* @param exposeConnection {@literal true} to expose the actual Redis connection to RedisCallback code, allowing full
181+
* access to Redis commands, including quit and disconnect. {@literal false} to proxy connections that
182+
* suppress the quit and disconnect commands, protecting the connection from being inadvertently closed
183+
* during callback execution.
177184
*/
178185
public void setExposeConnection(boolean exposeConnection) {
179186
this.exposeConnection = exposeConnection;
180187
}
181188

182189
/**
183-
* @return Whether or not the default serializer should be used. If not, any serializers not explicitly set will
184-
* remain null and values will not be serialized or deserialized.
190+
* Returns whether the default serializer should be used or not.
191+
*
192+
* @return {@literal true} if the default serializer should be used; {@literal false} otherwise.
185193
*/
186194
public boolean isEnableDefaultSerializer() {
187195
return enableDefaultSerializer;
188196
}
189197

190198
/**
191-
* @param enableDefaultSerializer Whether or not the default serializer should be used. If not, any serializers not
192-
* explicitly set will remain null and values will not be serialized or deserialized.
199+
* Configure whether the default serializer should be used or not. If the default serializer is enabled, the template
200+
* will use it to serialize and deserialize values. However, if the default serializer is disabled , any serializers
201+
* that have not been explicitly set will remain {@literal null}, and their corresponding values will neither be
202+
* serialized nor deserialized. Defaults to {@literal true}.
203+
*
204+
* @param enableDefaultSerializer {@literal true} if the default serializer should be used; {@literal false}
205+
* otherwise.
193206
*/
194207
public void setEnableDefaultSerializer(boolean enableDefaultSerializer) {
195208
this.enableDefaultSerializer = enableDefaultSerializer;
196209
}
197210

198211
/**
199-
* If set to {@code true} {@link RedisTemplate} will participate in ongoing transactions using
200-
* {@literal MULTI...EXEC|DISCARD} to keep track of operations.
212+
* Sets whether this template participates in ongoing transactions using {@literal MULTI...EXEC|DISCARD} to keep track
213+
* of operations.
201214
*
202-
* @param enableTransactionSupport whether to participate in ongoing transactions.
215+
* @param enableTransactionSupport {@literal true}to participate in ongoing transactions; {@literal false} to not
216+
* track transactions.
203217
* @since 1.3
204218
* @see RedisConnectionUtils#getConnection(RedisConnectionFactory, boolean)
205219
* @see TransactionSynchronizationManager#isActualTransactionActive()
@@ -209,7 +223,7 @@ public void setEnableTransactionSupport(boolean enableTransactionSupport) {
209223
}
210224

211225
/**
212-
* Set the {@link ClassLoader} to be used for the default {@link JdkSerializationRedisSerializer} in case no other
226+
* Sets the {@link ClassLoader} to be used for the default {@link JdkSerializationRedisSerializer} in case no other
213227
* {@link RedisSerializer} is explicitly set as the default one.
214228
*
215229
* @param classLoader can be {@literal null}.
@@ -224,7 +238,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
224238
/**
225239
* Returns the default serializer used by this template.
226240
*
227-
* @return template default serializer
241+
* @return template default serializer.
228242
*/
229243
@Nullable
230244
public RedisSerializer<?> getDefaultSerializer() {
@@ -236,7 +250,7 @@ public RedisSerializer<?> getDefaultSerializer() {
236250
* {@link #setStringSerializer(RedisSerializer)}) are initialized to this value unless explicitly set. Defaults to
237251
* {@link JdkSerializationRedisSerializer}.
238252
*
239-
* @param serializer default serializer to use
253+
* @param serializer default serializer to use.
240254
*/
241255
public void setDefaultSerializer(RedisSerializer<?> serializer) {
242256
this.defaultSerializer = serializer;
@@ -967,16 +981,19 @@ public GeoOperations<K, V> opsForGeo() {
967981
}
968982

969983
@Override
984+
@SuppressWarnings("unchecked")
970985
public BoundGeoOperations<K, V> boundGeoOps(K key) {
971986
return boundOperations.createProxy(BoundGeoOperations.class, key, DataType.ZSET, this, RedisOperations::opsForGeo);
972987
}
973988

974989
@Override
990+
@SuppressWarnings("unchecked")
975991
public <HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key) {
976992
return boundOperations.createProxy(BoundHashOperations.class, key, DataType.HASH, this, it -> it.opsForHash());
977993
}
978994

979995
@Override
996+
@SuppressWarnings({ "unchecked", "rawtypes" })
980997
public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
981998
return (HashOperations) hashOps;
982999
}
@@ -992,12 +1009,14 @@ public ListOperations<K, V> opsForList() {
9921009
}
9931010

9941011
@Override
1012+
@SuppressWarnings("unchecked")
9951013
public BoundListOperations<K, V> boundListOps(K key) {
9961014
return boundOperations.createProxy(BoundListOperations.class, key, DataType.LIST, this,
9971015
RedisOperations::opsForList);
9981016
}
9991017

10001018
@Override
1019+
@SuppressWarnings("unchecked")
10011020
public BoundSetOperations<K, V> boundSetOps(K key) {
10021021
return boundOperations.createProxy(BoundSetOperations.class, key, DataType.SET, this, RedisOperations::opsForSet);
10031022
}
@@ -1008,6 +1027,7 @@ public SetOperations<K, V> opsForSet() {
10081027
}
10091028

10101029
@Override
1030+
@SuppressWarnings("unchecked")
10111031
public <HK, HV> StreamOperations<K, HK, HV> opsForStream() {
10121032
return (StreamOperations<K, HK, HV>) streamOps;
10131033
}
@@ -1018,11 +1038,13 @@ public <HK, HV> StreamOperations<K, HK, HV> opsForStream(HashMapper<? super K, ?
10181038
}
10191039

10201040
@Override
1041+
@SuppressWarnings("unchecked")
10211042
public <HK, HV> BoundStreamOperations<K, HK, HV> boundStreamOps(K key) {
10221043
return boundOperations.createProxy(BoundStreamOperations.class, key, DataType.STREAM, this, it -> opsForStream());
10231044
}
10241045

10251046
@Override
1047+
@SuppressWarnings("unchecked")
10261048
public BoundValueOperations<K, V> boundValueOps(K key) {
10271049
return boundOperations.createProxy(BoundValueOperations.class, key, DataType.STRING, this,
10281050
RedisOperations::opsForValue);
@@ -1034,6 +1056,7 @@ public ValueOperations<K, V> opsForValue() {
10341056
}
10351057

10361058
@Override
1059+
@SuppressWarnings("unchecked")
10371060
public BoundZSetOperations<K, V> boundZSetOps(K key) {
10381061
return boundOperations.createProxy(BoundZSetOperations.class, key, DataType.ZSET, this,
10391062
RedisOperations::opsForZSet);

0 commit comments

Comments
 (0)