66
66
* Redis store. By default, it uses Java serialization for its objects (through {@link JdkSerializationRedisSerializer}
67
67
* ). For String intensive operations consider the dedicated {@link StringRedisTemplate}.
68
68
* <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.
73
74
* <p>
74
75
* Once configured, this class is thread-safe.
75
76
* <p>
@@ -121,7 +122,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
121
122
private final ClusterOperations <K , V > clusterOps = new DefaultClusterOperations <>(this );
122
123
123
124
/**
124
- * Constructs a new < code> RedisTemplate</code> instance.
125
+ * Constructs a new {@ code RedisTemplate} instance.
125
126
*/
126
127
public RedisTemplate () {}
127
128
@@ -160,46 +161,59 @@ public void afterPropertiesSet() {
160
161
}
161
162
162
163
/**
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 ).
165
166
*
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.
167
169
*/
168
170
public boolean isExposeConnection () {
169
171
return exposeConnection ;
170
172
}
171
173
172
174
/**
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.
175
179
*
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.
177
184
*/
178
185
public void setExposeConnection (boolean exposeConnection ) {
179
186
this .exposeConnection = exposeConnection ;
180
187
}
181
188
182
189
/**
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.
185
193
*/
186
194
public boolean isEnableDefaultSerializer () {
187
195
return enableDefaultSerializer ;
188
196
}
189
197
190
198
/**
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.
193
206
*/
194
207
public void setEnableDefaultSerializer (boolean enableDefaultSerializer ) {
195
208
this .enableDefaultSerializer = enableDefaultSerializer ;
196
209
}
197
210
198
211
/**
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.
201
214
*
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.
203
217
* @since 1.3
204
218
* @see RedisConnectionUtils#getConnection(RedisConnectionFactory, boolean)
205
219
* @see TransactionSynchronizationManager#isActualTransactionActive()
@@ -209,7 +223,7 @@ public void setEnableTransactionSupport(boolean enableTransactionSupport) {
209
223
}
210
224
211
225
/**
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
213
227
* {@link RedisSerializer} is explicitly set as the default one.
214
228
*
215
229
* @param classLoader can be {@literal null}.
@@ -224,7 +238,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {
224
238
/**
225
239
* Returns the default serializer used by this template.
226
240
*
227
- * @return template default serializer
241
+ * @return template default serializer.
228
242
*/
229
243
@ Nullable
230
244
public RedisSerializer <?> getDefaultSerializer () {
@@ -236,7 +250,7 @@ public RedisSerializer<?> getDefaultSerializer() {
236
250
* {@link #setStringSerializer(RedisSerializer)}) are initialized to this value unless explicitly set. Defaults to
237
251
* {@link JdkSerializationRedisSerializer}.
238
252
*
239
- * @param serializer default serializer to use
253
+ * @param serializer default serializer to use.
240
254
*/
241
255
public void setDefaultSerializer (RedisSerializer <?> serializer ) {
242
256
this .defaultSerializer = serializer ;
@@ -967,16 +981,19 @@ public GeoOperations<K, V> opsForGeo() {
967
981
}
968
982
969
983
@ Override
984
+ @ SuppressWarnings ("unchecked" )
970
985
public BoundGeoOperations <K , V > boundGeoOps (K key ) {
971
986
return boundOperations .createProxy (BoundGeoOperations .class , key , DataType .ZSET , this , RedisOperations ::opsForGeo );
972
987
}
973
988
974
989
@ Override
990
+ @ SuppressWarnings ("unchecked" )
975
991
public <HK , HV > BoundHashOperations <K , HK , HV > boundHashOps (K key ) {
976
992
return boundOperations .createProxy (BoundHashOperations .class , key , DataType .HASH , this , it -> it .opsForHash ());
977
993
}
978
994
979
995
@ Override
996
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
980
997
public <HK , HV > HashOperations <K , HK , HV > opsForHash () {
981
998
return (HashOperations ) hashOps ;
982
999
}
@@ -992,12 +1009,14 @@ public ListOperations<K, V> opsForList() {
992
1009
}
993
1010
994
1011
@ Override
1012
+ @ SuppressWarnings ("unchecked" )
995
1013
public BoundListOperations <K , V > boundListOps (K key ) {
996
1014
return boundOperations .createProxy (BoundListOperations .class , key , DataType .LIST , this ,
997
1015
RedisOperations ::opsForList );
998
1016
}
999
1017
1000
1018
@ Override
1019
+ @ SuppressWarnings ("unchecked" )
1001
1020
public BoundSetOperations <K , V > boundSetOps (K key ) {
1002
1021
return boundOperations .createProxy (BoundSetOperations .class , key , DataType .SET , this , RedisOperations ::opsForSet );
1003
1022
}
@@ -1008,6 +1027,7 @@ public SetOperations<K, V> opsForSet() {
1008
1027
}
1009
1028
1010
1029
@ Override
1030
+ @ SuppressWarnings ("unchecked" )
1011
1031
public <HK , HV > StreamOperations <K , HK , HV > opsForStream () {
1012
1032
return (StreamOperations <K , HK , HV >) streamOps ;
1013
1033
}
@@ -1018,11 +1038,13 @@ public <HK, HV> StreamOperations<K, HK, HV> opsForStream(HashMapper<? super K, ?
1018
1038
}
1019
1039
1020
1040
@ Override
1041
+ @ SuppressWarnings ("unchecked" )
1021
1042
public <HK , HV > BoundStreamOperations <K , HK , HV > boundStreamOps (K key ) {
1022
1043
return boundOperations .createProxy (BoundStreamOperations .class , key , DataType .STREAM , this , it -> opsForStream ());
1023
1044
}
1024
1045
1025
1046
@ Override
1047
+ @ SuppressWarnings ("unchecked" )
1026
1048
public BoundValueOperations <K , V > boundValueOps (K key ) {
1027
1049
return boundOperations .createProxy (BoundValueOperations .class , key , DataType .STRING , this ,
1028
1050
RedisOperations ::opsForValue );
@@ -1034,6 +1056,7 @@ public ValueOperations<K, V> opsForValue() {
1034
1056
}
1035
1057
1036
1058
@ Override
1059
+ @ SuppressWarnings ("unchecked" )
1037
1060
public BoundZSetOperations <K , V > boundZSetOps (K key ) {
1038
1061
return boundOperations .createProxy (BoundZSetOperations .class , key , DataType .ZSET , this ,
1039
1062
RedisOperations ::opsForZSet );
0 commit comments