79
79
* @author Ninad Divadkar
80
80
* @author Anqing Shao
81
81
* @author Mark Paluch
82
+ * @author Denis Zavedeev
82
83
* @param <K> the Redis key type against which the template works (usually a String)
83
84
* @param <V> the Redis value type against which the template works
84
85
* @see StringRedisTemplate
@@ -100,13 +101,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
100
101
101
102
private @ Nullable ScriptExecutor <K > scriptExecutor ;
102
103
103
- // cache singleton objects (where possible)
104
- private @ Nullable ValueOperations <K , V > valueOps ;
105
- private @ Nullable ListOperations <K , V > listOps ;
106
- private @ Nullable SetOperations <K , V > setOps ;
107
- private @ Nullable ZSetOperations <K , V > zSetOps ;
108
- private @ Nullable GeoOperations <K , V > geoOps ;
109
- private @ Nullable HyperLogLogOperations <K , V > hllOps ;
104
+ private final ValueOperations < K , V > valueOps = new DefaultValueOperations <>( this );
105
+ private final ListOperations <K , V > listOps = new DefaultListOperations <>( this ) ;
106
+ private final SetOperations <K , V > setOps = new DefaultSetOperations <>( this ) ;
107
+ private final ZSetOperations <K , V > zSetOps = new DefaultZSetOperations <>( this ) ;
108
+ private final GeoOperations <K , V > geoOps = new DefaultGeoOperations <>( this ) ;
109
+ private final HyperLogLogOperations <K , V > hllOps = new DefaultHyperLogLogOperations <>( this ) ;
110
+ private final ClusterOperations <K , V > clusterOps = new DefaultClusterOperations <>( this ) ;
110
111
111
112
/**
112
113
* Constructs a new <code>RedisTemplate</code> instance.
@@ -1200,7 +1201,7 @@ public void slaveOfNoOne() {
1200
1201
*/
1201
1202
@ Override
1202
1203
public ClusterOperations <K , V > opsForCluster () {
1203
- return new DefaultClusterOperations <>( this ) ;
1204
+ return clusterOps ;
1204
1205
}
1205
1206
1206
1207
/*
@@ -1209,10 +1210,6 @@ public ClusterOperations<K, V> opsForCluster() {
1209
1210
*/
1210
1211
@ Override
1211
1212
public GeoOperations <K , V > opsForGeo () {
1212
-
1213
- if (geoOps == null ) {
1214
- geoOps = new DefaultGeoOperations <>(this );
1215
- }
1216
1213
return geoOps ;
1217
1214
}
1218
1215
@@ -1249,10 +1246,6 @@ public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
1249
1246
*/
1250
1247
@ Override
1251
1248
public HyperLogLogOperations <K , V > opsForHyperLogLog () {
1252
-
1253
- if (hllOps == null ) {
1254
- hllOps = new DefaultHyperLogLogOperations <>(this );
1255
- }
1256
1249
return hllOps ;
1257
1250
}
1258
1251
@@ -1262,10 +1255,6 @@ public HyperLogLogOperations<K, V> opsForHyperLogLog() {
1262
1255
*/
1263
1256
@ Override
1264
1257
public ListOperations <K , V > opsForList () {
1265
-
1266
- if (listOps == null ) {
1267
- listOps = new DefaultListOperations <>(this );
1268
- }
1269
1258
return listOps ;
1270
1259
}
1271
1260
@@ -1293,10 +1282,6 @@ public BoundSetOperations<K, V> boundSetOps(K key) {
1293
1282
*/
1294
1283
@ Override
1295
1284
public SetOperations <K , V > opsForSet () {
1296
-
1297
- if (setOps == null ) {
1298
- setOps = new DefaultSetOperations <>(this );
1299
- }
1300
1285
return setOps ;
1301
1286
}
1302
1287
@@ -1315,10 +1300,6 @@ public BoundValueOperations<K, V> boundValueOps(K key) {
1315
1300
*/
1316
1301
@ Override
1317
1302
public ValueOperations <K , V > opsForValue () {
1318
-
1319
- if (valueOps == null ) {
1320
- valueOps = new DefaultValueOperations <>(this );
1321
- }
1322
1303
return valueOps ;
1323
1304
}
1324
1305
@@ -1337,10 +1318,6 @@ public BoundZSetOperations<K, V> boundZSetOps(K key) {
1337
1318
*/
1338
1319
@ Override
1339
1320
public ZSetOperations <K , V > opsForZSet () {
1340
-
1341
- if (zSetOps == null ) {
1342
- zSetOps = new DefaultZSetOperations <>(this );
1343
- }
1344
1321
return zSetOps ;
1345
1322
}
1346
1323
0 commit comments