Skip to content

Commit fcf92a2

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Remove exposeConnection from AbstractOperations.execute(…) as it's always set to true simplifying calling code. Original Pull Request: #2129
1 parent 5918f91 commit fcf92a2

10 files changed

+218
-223
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ RedisSerializer stringSerializer() {
9393
}
9494

9595
@Nullable
96-
<T> T execute(RedisCallback<T> callback, boolean exposeConnection) {
97-
return template.execute(callback, exposeConnection);
96+
<T> T execute(RedisCallback<T> callback) {
97+
return template.execute(callback, true);
9898
}
9999

100100
public RedisOperations<K, V> getOperations() {

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

+16-19
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Set<K> keys(final RedisClusterNode node, final K pattern) {
5959

6060
Assert.notNull(node, "ClusterNode must not be null.");
6161

62-
return execute(connection -> deserializeKeys(connection.keys(node, rawKey(pattern))));
62+
return doInCluster(connection -> deserializeKeys(connection.keys(node, rawKey(pattern))));
6363
}
6464

6565
/*
@@ -71,7 +71,7 @@ public K randomKey(final RedisClusterNode node) {
7171

7272
Assert.notNull(node, "ClusterNode must not be null.");
7373

74-
return execute(connection -> deserializeKey(connection.randomKey(node)));
74+
return doInCluster(connection -> deserializeKey(connection.randomKey(node)));
7575
}
7676

7777
/*
@@ -83,7 +83,7 @@ public String ping(final RedisClusterNode node) {
8383

8484
Assert.notNull(node, "ClusterNode must not be null.");
8585

86-
return execute(connection -> connection.ping(node));
86+
return doInCluster(connection -> connection.ping(node));
8787
}
8888

8989
/*
@@ -95,7 +95,7 @@ public void addSlots(final RedisClusterNode node, final int... slots) {
9595

9696
Assert.notNull(node, "ClusterNode must not be null.");
9797

98-
execute((RedisClusterCallback<Void>) connection -> {
98+
doInCluster((RedisClusterCallback<Void>) connection -> {
9999
connection.clusterAddSlots(node, slots);
100100
return null;
101101
});
@@ -123,7 +123,7 @@ public void bgReWriteAof(final RedisClusterNode node) {
123123

124124
Assert.notNull(node, "ClusterNode must not be null.");
125125

126-
execute((RedisClusterCallback<Void>) connection -> {
126+
doInCluster((RedisClusterCallback<Void>) connection -> {
127127
connection.bgReWriteAof(node);
128128
return null;
129129
});
@@ -138,7 +138,7 @@ public void bgSave(final RedisClusterNode node) {
138138

139139
Assert.notNull(node, "ClusterNode must not be null.");
140140

141-
execute((RedisClusterCallback<Void>) connection -> {
141+
doInCluster((RedisClusterCallback<Void>) connection -> {
142142
connection.bgSave(node);
143143
return null;
144144
});
@@ -153,7 +153,7 @@ public void meet(final RedisClusterNode node) {
153153

154154
Assert.notNull(node, "ClusterNode must not be null.");
155155

156-
execute((RedisClusterCallback<Void>) connection -> {
156+
doInCluster((RedisClusterCallback<Void>) connection -> {
157157
connection.clusterMeet(node);
158158
return null;
159159
});
@@ -168,7 +168,7 @@ public void forget(final RedisClusterNode node) {
168168

169169
Assert.notNull(node, "ClusterNode must not be null.");
170170

171-
execute((RedisClusterCallback<Void>) connection -> {
171+
doInCluster((RedisClusterCallback<Void>) connection -> {
172172
connection.clusterForget(node);
173173
return null;
174174
});
@@ -183,7 +183,7 @@ public void flushDb(final RedisClusterNode node) {
183183

184184
Assert.notNull(node, "ClusterNode must not be null.");
185185

186-
execute((RedisClusterCallback<Void>) connection -> {
186+
doInCluster((RedisClusterCallback<Void>) connection -> {
187187
connection.flushDb(node);
188188
return null;
189189
});
@@ -198,7 +198,7 @@ public Collection<RedisClusterNode> getSlaves(final RedisClusterNode node) {
198198

199199
Assert.notNull(node, "ClusterNode must not be null.");
200200

201-
return execute(connection -> connection.clusterGetSlaves(node));
201+
return doInCluster(connection -> connection.clusterGetSlaves(node));
202202
}
203203

204204
/*
@@ -210,7 +210,7 @@ public void save(final RedisClusterNode node) {
210210

211211
Assert.notNull(node, "ClusterNode must not be null.");
212212

213-
execute((RedisClusterCallback<Void>) connection -> {
213+
doInCluster((RedisClusterCallback<Void>) connection -> {
214214
connection.save(node);
215215
return null;
216216
});
@@ -225,7 +225,7 @@ public void shutdown(final RedisClusterNode node) {
225225

226226
Assert.notNull(node, "ClusterNode must not be null.");
227227

228-
execute((RedisClusterCallback<Void>) connection -> {
228+
doInCluster((RedisClusterCallback<Void>) connection -> {
229229
connection.shutdown(node);
230230
return null;
231231
});
@@ -241,7 +241,7 @@ public void reshard(final RedisClusterNode source, final int slot, final RedisCl
241241
Assert.notNull(source, "Source node must not be null.");
242242
Assert.notNull(target, "Target node must not be null.");
243243

244-
execute((RedisClusterCallback<Void>) connection -> {
244+
doInCluster((RedisClusterCallback<Void>) connection -> {
245245

246246
connection.clusterSetSlot(target, slot, AddSlots.IMPORTING);
247247
connection.clusterSetSlot(source, slot, AddSlots.MIGRATING);
@@ -262,16 +262,13 @@ public void reshard(final RedisClusterNode source, final int slot, final RedisCl
262262
* @return execution result. Can be {@literal null}.
263263
*/
264264
@Nullable
265-
public <T> T execute(RedisClusterCallback<T> callback) {
265+
<T> T doInCluster(RedisClusterCallback<T> callback) {
266266

267267
Assert.notNull(callback, "ClusterCallback must not be null!");
268268

269-
RedisClusterConnection connection = template.getConnectionFactory().getClusterConnection();
270-
271-
try {
269+
try (RedisClusterConnection connection = template.getConnectionFactory().getClusterConnection()) {
272270
return callback.doInRedis(connection);
273-
} finally {
274-
connection.close();
275271
}
276272
}
273+
277274
}

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

+17-17
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Long add(K key, Point point, M member) {
6161
byte[] rawKey = rawKey(key);
6262
byte[] rawMember = rawValue(member);
6363

64-
return execute(connection -> connection.geoAdd(rawKey, point, rawMember), true);
64+
return execute(connection -> connection.geoAdd(rawKey, point, rawMember));
6565
}
6666

6767
/*
@@ -88,7 +88,7 @@ public Long add(K key, Map<M, Point> memberCoordinateMap) {
8888
rawMemberCoordinateMap.put(rawMember, memberCoordinateMap.get(member));
8989
}
9090

91-
return execute(connection -> connection.geoAdd(rawKey, rawMemberCoordinateMap), true);
91+
return execute(connection -> connection.geoAdd(rawKey, rawMemberCoordinateMap));
9292
}
9393

9494
/*
@@ -117,7 +117,7 @@ public Distance distance(K key, M member1, M member2) {
117117
byte[] rawMember1 = rawValue(member1);
118118
byte[] rawMember2 = rawValue(member2);
119119

120-
return execute(connection -> connection.geoDist(rawKey, rawMember1, rawMember2), true);
120+
return execute(connection -> connection.geoDist(rawKey, rawMember1, rawMember2));
121121
}
122122

123123
/*
@@ -131,7 +131,7 @@ public Distance distance(K key, M member1, M member2, Metric metric) {
131131
byte[] rawMember1 = rawValue(member1);
132132
byte[] rawMember2 = rawValue(member2);
133133

134-
return execute(connection -> connection.geoDist(rawKey, rawMember1, rawMember2, metric), true);
134+
return execute(connection -> connection.geoDist(rawKey, rawMember1, rawMember2, metric));
135135
}
136136

137137
/*
@@ -144,7 +144,7 @@ public List<String> hash(K key, M... members) {
144144
byte[] rawKey = rawKey(key);
145145
byte[][] rawMembers = rawValues(members);
146146

147-
return execute(connection -> connection.geoHash(rawKey, rawMembers), true);
147+
return execute(connection -> connection.geoHash(rawKey, rawMembers));
148148
}
149149

150150
/*
@@ -156,7 +156,7 @@ public List<Point> position(K key, M... members) {
156156
byte[] rawKey = rawKey(key);
157157
byte[][] rawMembers = rawValues(members);
158158

159-
return execute(connection -> connection.geoPos(rawKey, rawMembers), true);
159+
return execute(connection -> connection.geoPos(rawKey, rawMembers));
160160
}
161161

162162
/*
@@ -168,7 +168,7 @@ public GeoResults<GeoLocation<M>> radius(K key, Circle within) {
168168

169169
byte[] rawKey = rawKey(key);
170170

171-
GeoResults<GeoLocation<byte[]>> raw = execute(connection -> connection.geoRadius(rawKey, within), true);
171+
GeoResults<GeoLocation<byte[]>> raw = execute(connection -> connection.geoRadius(rawKey, within));
172172

173173
return deserializeGeoResults(raw);
174174
}
@@ -182,7 +182,7 @@ public GeoResults<GeoLocation<M>> radius(K key, Circle within, GeoRadiusCommandA
182182

183183
byte[] rawKey = rawKey(key);
184184

185-
GeoResults<GeoLocation<byte[]>> raw = execute(connection -> connection.geoRadius(rawKey, within, args), true);
185+
GeoResults<GeoLocation<byte[]>> raw = execute(connection -> connection.geoRadius(rawKey, within, args));
186186

187187
return deserializeGeoResults(raw);
188188
}
@@ -196,8 +196,8 @@ public GeoResults<GeoLocation<M>> radius(K key, M member, double radius) {
196196

197197
byte[] rawKey = rawKey(key);
198198
byte[] rawMember = rawValue(member);
199-
GeoResults<GeoLocation<byte[]>> raw = execute(connection -> connection.geoRadiusByMember(rawKey, rawMember, radius),
200-
true);
199+
GeoResults<GeoLocation<byte[]>> raw = execute(
200+
connection -> connection.geoRadiusByMember(rawKey, rawMember, radius));
201201

202202
return deserializeGeoResults(raw);
203203
}
@@ -213,7 +213,7 @@ public GeoResults<GeoLocation<M>> radius(K key, M member, Distance distance) {
213213
byte[] rawMember = rawValue(member);
214214

215215
GeoResults<GeoLocation<byte[]>> raw = execute(
216-
connection -> connection.geoRadiusByMember(rawKey, rawMember, distance), true);
216+
connection -> connection.geoRadiusByMember(rawKey, rawMember, distance));
217217

218218
return deserializeGeoResults(raw);
219219
}
@@ -229,7 +229,7 @@ public GeoResults<GeoLocation<M>> radius(K key, M member, Distance distance, Geo
229229
byte[] rawMember = rawValue(member);
230230

231231
GeoResults<GeoLocation<byte[]>> raw = execute(
232-
connection -> connection.geoRadiusByMember(rawKey, rawMember, distance, param), true);
232+
connection -> connection.geoRadiusByMember(rawKey, rawMember, distance, param));
233233

234234
return deserializeGeoResults(raw);
235235
}
@@ -243,10 +243,10 @@ public Long remove(K key, M... members) {
243243

244244
byte[] rawKey = rawKey(key);
245245
byte[][] rawMembers = rawValues(members);
246-
return execute(connection -> connection.zRem(rawKey, rawMembers), true);
246+
return execute(connection -> connection.zRem(rawKey, rawMembers));
247247
}
248248

249-
/*
249+
/*
250250
* (non-Javadoc)
251251
* @see org.springframework.data.redis.core.GeoOperations#search(java.lang.Object, org.springframework.data.redis.connection.RedisGeoCommands.GeoReference, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchCommandArgs)
252252
*/
@@ -258,12 +258,12 @@ public GeoResults<GeoLocation<M>> search(K key, GeoReference<M> reference,
258258
GeoReference<byte[]> rawMember = getGeoReference(reference);
259259

260260
GeoResults<GeoLocation<byte[]>> raw = execute(
261-
connection -> connection.geoSearch(rawKey, rawMember, geoPredicate, args), true);
261+
connection -> connection.geoSearch(rawKey, rawMember, geoPredicate, args));
262262

263263
return deserializeGeoResults(raw);
264264
}
265265

266-
/*
266+
/*
267267
* (non-Javadoc)
268268
* @see org.springframework.data.redis.core.GeoOperations#searchAndStore(java.lang.Object, java.lang.Object, org.springframework.data.redis.connection.RedisGeoCommands.GeoReference, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchStoreCommandArgs)
269269
*/
@@ -275,7 +275,7 @@ public Long searchAndStore(K key, K destKey, GeoReference<M> reference,
275275
byte[] rawDestKey = rawKey(destKey);
276276
GeoReference<byte[]> rawMember = getGeoReference(reference);
277277

278-
return execute(connection -> connection.geoSearchStore(rawDestKey, rawKey, rawMember, geoPredicate, args), true);
278+
return execute(connection -> connection.geoSearchStore(rawDestKey, rawKey, rawMember, geoPredicate, args));
279279
}
280280

281281
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)