81
81
* @author Ninad Divadkar
82
82
* @author Anqing Shao
83
83
* @author Mark Paluch
84
+ * @author Denis Zavedeev
84
85
* @param <K> the Redis key type against which the template works (usually a String)
85
86
* @param <V> the Redis value type against which the template works
86
87
* @see StringRedisTemplate
@@ -102,14 +103,14 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
102
103
103
104
private @ Nullable ScriptExecutor <K > scriptExecutor ;
104
105
105
- // cache singleton objects (where possible)
106
- private @ Nullable ValueOperations <K , V > valueOps ;
107
- private @ Nullable ListOperations <K , V > listOps ;
108
- private @ Nullable SetOperations <K , V > setOps ;
109
- private @ Nullable StreamOperations <K , ?, ?> streamOps ;
110
- private @ Nullable ZSetOperations <K , V > zSetOps ;
111
- private @ Nullable GeoOperations <K , V > geoOps ;
112
- private @ Nullable HyperLogLogOperations <K , V > hllOps ;
106
+ private final ValueOperations < K , V > valueOps = new DefaultValueOperations <>( this );
107
+ private final ListOperations <K , V > listOps = new DefaultListOperations <>( this ) ;
108
+ private final SetOperations <K , V > setOps = new DefaultSetOperations <>( this ) ;
109
+ private final StreamOperations <K , ?, ?> streamOps = new DefaultStreamOperations <>( this , new ObjectHashMapper ()) ;
110
+ private final ZSetOperations <K , V > zSetOps = new DefaultZSetOperations <>( this ) ;
111
+ private final GeoOperations <K , V > geoOps = new DefaultGeoOperations <>( this ) ;
112
+ private final HyperLogLogOperations <K , V > hllOps = new DefaultHyperLogLogOperations <>( this ) ;
113
+ private final ClusterOperations <K , V > clusterOps = new DefaultClusterOperations <>( this ) ;
113
114
114
115
/**
115
116
* Constructs a new <code>RedisTemplate</code> instance.
@@ -1203,7 +1204,7 @@ public void slaveOfNoOne() {
1203
1204
*/
1204
1205
@ Override
1205
1206
public ClusterOperations <K , V > opsForCluster () {
1206
- return new DefaultClusterOperations <>( this ) ;
1207
+ return clusterOps ;
1207
1208
}
1208
1209
1209
1210
/*
@@ -1212,10 +1213,6 @@ public ClusterOperations<K, V> opsForCluster() {
1212
1213
*/
1213
1214
@ Override
1214
1215
public GeoOperations <K , V > opsForGeo () {
1215
-
1216
- if (geoOps == null ) {
1217
- geoOps = new DefaultGeoOperations <>(this );
1218
- }
1219
1216
return geoOps ;
1220
1217
}
1221
1218
@@ -1252,10 +1249,6 @@ public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
1252
1249
*/
1253
1250
@ Override
1254
1251
public HyperLogLogOperations <K , V > opsForHyperLogLog () {
1255
-
1256
- if (hllOps == null ) {
1257
- hllOps = new DefaultHyperLogLogOperations <>(this );
1258
- }
1259
1252
return hllOps ;
1260
1253
}
1261
1254
@@ -1265,10 +1258,6 @@ public HyperLogLogOperations<K, V> opsForHyperLogLog() {
1265
1258
*/
1266
1259
@ Override
1267
1260
public ListOperations <K , V > opsForList () {
1268
-
1269
- if (listOps == null ) {
1270
- listOps = new DefaultListOperations <>(this );
1271
- }
1272
1261
return listOps ;
1273
1262
}
1274
1263
@@ -1296,10 +1285,6 @@ public BoundSetOperations<K, V> boundSetOps(K key) {
1296
1285
*/
1297
1286
@ Override
1298
1287
public SetOperations <K , V > opsForSet () {
1299
-
1300
- if (setOps == null ) {
1301
- setOps = new DefaultSetOperations <>(this );
1302
- }
1303
1288
return setOps ;
1304
1289
}
1305
1290
@@ -1309,10 +1294,6 @@ public SetOperations<K, V> opsForSet() {
1309
1294
*/
1310
1295
@ Override
1311
1296
public <HK , HV > StreamOperations <K , HK , HV > opsForStream () {
1312
-
1313
- if (streamOps == null ) {
1314
- streamOps = new DefaultStreamOperations <>(this , new ObjectHashMapper ());
1315
- }
1316
1297
return (StreamOperations <K , HK , HV >) streamOps ;
1317
1298
}
1318
1299
@@ -1350,10 +1331,6 @@ public BoundValueOperations<K, V> boundValueOps(K key) {
1350
1331
*/
1351
1332
@ Override
1352
1333
public ValueOperations <K , V > opsForValue () {
1353
-
1354
- if (valueOps == null ) {
1355
- valueOps = new DefaultValueOperations <>(this );
1356
- }
1357
1334
return valueOps ;
1358
1335
}
1359
1336
@@ -1372,10 +1349,6 @@ public BoundZSetOperations<K, V> boundZSetOps(K key) {
1372
1349
*/
1373
1350
@ Override
1374
1351
public ZSetOperations <K , V > opsForZSet () {
1375
-
1376
- if (zSetOps == null ) {
1377
- zSetOps = new DefaultZSetOperations <>(this );
1378
- }
1379
1352
return zSetOps ;
1380
1353
}
1381
1354
0 commit comments