Skip to content

Commit 2d08f28

Browse files
committed
Polishing.
Rename key name arguments consistently to oldKey/newKey. See #2189
1 parent 8bc0b15 commit 2d08f28

11 files changed

+87
-76
lines changed

Diff for: src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -856,17 +856,17 @@ public byte[] randomKey() {
856856
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
857857
*/
858858
@Override
859-
public void rename(byte[] sourceKey, byte[] targetKey) {
860-
delegate.rename(sourceKey, targetKey);
859+
public void rename(byte[] oldKey, byte[] newKey) {
860+
delegate.rename(oldKey, newKey);
861861
}
862862

863863
/*
864864
* (non-Javadoc)
865865
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
866866
*/
867867
@Override
868-
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
869-
return convertAndReturn(delegate.renameNX(sourceKey, targetKey), Converters.identityConverter());
868+
public Boolean renameNX(byte[] oldKey, byte[] newKey) {
869+
return convertAndReturn(delegate.renameNX(oldKey, newKey), Converters.identityConverter());
870870
}
871871

872872
/*
@@ -2300,17 +2300,17 @@ public Long publish(String channel, String message) {
23002300
* @see org.springframework.data.redis.connection.StringRedisConnection#rename(java.lang.String, java.lang.String)
23012301
*/
23022302
@Override
2303-
public void rename(String oldName, String newName) {
2304-
delegate.rename(serialize(oldName), serialize(newName));
2303+
public void rename(String oldKey, String newKey) {
2304+
delegate.rename(serialize(oldKey), serialize(newKey));
23052305
}
23062306

23072307
/*
23082308
* (non-Javadoc)
23092309
* @see org.springframework.data.redis.connection.StringRedisConnection#renameNX(java.lang.String, java.lang.String)
23102310
*/
23112311
@Override
2312-
public Boolean renameNX(String oldName, String newName) {
2313-
return renameNX(serialize(oldName), serialize(newName));
2312+
public Boolean renameNX(String oldKey, String newKey) {
2313+
return renameNX(serialize(oldKey), serialize(newKey));
23142314
}
23152315

23162316
/*

Diff for: src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ default byte[] randomKey() {
128128
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
129129
@Override
130130
@Deprecated
131-
default void rename(byte[] sourceKey, byte[] targetKey) {
132-
keyCommands().rename(sourceKey, targetKey);
131+
default void rename(byte[] oldKey, byte[] newKey) {
132+
keyCommands().rename(oldKey, newKey);
133133
}
134134

135135
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */

Diff for: src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java

+33-22
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ default Flux<ByteBuffer> scan() {
178178
*/
179179
class RenameCommand extends KeyCommand {
180180

181-
private @Nullable ByteBuffer newName;
181+
private @Nullable ByteBuffer newKey;
182182

183-
private RenameCommand(ByteBuffer key, @Nullable ByteBuffer newName) {
183+
private RenameCommand(ByteBuffer key, @Nullable ByteBuffer newKey) {
184184

185185
super(key);
186186

187-
this.newName = newName;
187+
this.newKey = newKey;
188188
}
189189

190190
/**
@@ -201,44 +201,55 @@ public static RenameCommand key(ByteBuffer key) {
201201
}
202202

203203
/**
204-
* Applies the {@literal newName}. Constructs a new command instance with all previously configured properties.
204+
* Applies the {@literal newKey}. Constructs a new command instance with all previously configured properties.
205205
*
206-
* @param newName must not be {@literal null}.
207-
* @return a new {@link RenameCommand} with {@literal newName} applied.
206+
* @param newKey must not be {@literal null}.
207+
* @return a new {@link RenameCommand} with {@literal newKey} applied.
208208
*/
209-
public RenameCommand to(ByteBuffer newName) {
209+
public RenameCommand to(ByteBuffer newKey) {
210210

211-
Assert.notNull(newName, "New name must not be null!");
211+
Assert.notNull(newKey, "New key name must not be null!");
212212

213-
return new RenameCommand(getKey(), newName);
213+
return new RenameCommand(getKey(), newKey);
214214
}
215215

216216
/**
217217
* @return can be {@literal null}.
218+
* @deprecated since 2.5.7, renamed to {@link #getNewKey()}.
218219
*/
219220
@Nullable
221+
@Deprecated
220222
public ByteBuffer getNewName() {
221-
return newName;
223+
return newKey;
224+
}
225+
226+
/**
227+
* @return can be {@literal null}.
228+
* @since 2.5.7
229+
*/
230+
@Nullable
231+
public ByteBuffer getNewKey() {
232+
return newKey;
222233
}
223234
}
224235

225236
/**
226-
* Rename key {@literal oleName} to {@literal newName}.
237+
* Rename key {@literal oldKey} to {@literal newKey}.
227238
*
228-
* @param key must not be {@literal null}.
229-
* @param newName must not be {@literal null}.
239+
* @param oldKey must not be {@literal null}.
240+
* @param newKey must not be {@literal null}.
230241
* @return
231242
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
232243
*/
233-
default Mono<Boolean> rename(ByteBuffer key, ByteBuffer newName) {
244+
default Mono<Boolean> rename(ByteBuffer oldKey, ByteBuffer newKey) {
234245

235-
Assert.notNull(key, "Key must not be null!");
246+
Assert.notNull(oldKey, "Key must not be null!");
236247

237-
return rename(Mono.just(RenameCommand.key(key).to(newName))).next().map(BooleanResponse::getOutput);
248+
return rename(Mono.just(RenameCommand.key(oldKey).to(newKey))).next().map(BooleanResponse::getOutput);
238249
}
239250

240251
/**
241-
* Rename key {@literal oleName} to {@literal newName}.
252+
* Rename key {@literal oldKey} to {@literal newKey}.
242253
*
243254
* @param command must not be {@literal null}.
244255
* @return
@@ -247,22 +258,22 @@ default Mono<Boolean> rename(ByteBuffer key, ByteBuffer newName) {
247258
Flux<BooleanResponse<RenameCommand>> rename(Publisher<RenameCommand> command);
248259

249260
/**
250-
* Rename key {@literal oleName} to {@literal newName} only if {@literal newName} does not exist.
261+
* Rename key {@literal oldKey} to {@literal newKey} only if {@literal newKey} does not exist.
251262
*
252263
* @param key must not be {@literal null}.
253-
* @param newName must not be {@literal null}.
264+
* @param newKey must not be {@literal null}.
254265
* @return
255266
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
256267
*/
257-
default Mono<Boolean> renameNX(ByteBuffer key, ByteBuffer newName) {
268+
default Mono<Boolean> renameNX(ByteBuffer key, ByteBuffer newKey) {
258269

259270
Assert.notNull(key, "Key must not be null!");
260271

261-
return renameNX(Mono.just(RenameCommand.key(key).to(newName))).next().map(BooleanResponse::getOutput);
272+
return renameNX(Mono.just(RenameCommand.key(key).to(newKey))).next().map(BooleanResponse::getOutput);
262273
}
263274

264275
/**
265-
* Rename key {@literal oleName} to {@literal newName} only if {@literal newName} does not exist.
276+
* Rename key {@literal oldKey} to {@literal newKey} only if {@literal newKey} does not exist.
266277
*
267278
* @param command must not be {@literal null}.
268279
* @return

Diff for: src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,24 @@ default Boolean exists(byte[] key) {
134134
byte[] randomKey();
135135

136136
/**
137-
* Rename key {@code sourceKey} to {@code targetKey}.
137+
* Rename key {@code oldKey} to {@code newKey}.
138138
*
139-
* @param sourceKey must not be {@literal null}.
140-
* @param targetKey must not be {@literal null}.
139+
* @param oldKey must not be {@literal null}.
140+
* @param newKey must not be {@literal null}.
141141
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
142142
*/
143-
void rename(byte[] sourceKey, byte[] targetKey);
143+
void rename(byte[] oldKey, byte[] newKey);
144144

145145
/**
146-
* Rename key {@code sourceKey} to {@code targetKey} only if {@code targetKey} does not exist.
146+
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
147147
*
148-
* @param sourceKey must not be {@literal null}.
149-
* @param targetKey must not be {@literal null}.
148+
* @param oldKey must not be {@literal null}.
149+
* @param newKey must not be {@literal null}.
150150
* @return {@literal null} when used in pipeline / transaction.
151151
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
152152
*/
153153
@Nullable
154-
Boolean renameNX(byte[] sourceKey, byte[] targetKey);
154+
Boolean renameNX(byte[] oldKey, byte[] newKey);
155155

156156
/**
157157
* Set time to live for given {@code key} in seconds.

Diff for: src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,25 @@ interface StringTuple extends Tuple {
176176
Collection<String> keys(String pattern);
177177

178178
/**
179-
* Rename key {@code oleName} to {@code newName}.
179+
* Rename key {@code oldKey} to {@code newKey}.
180180
*
181-
* @param oldName must not be {@literal null}.
182-
* @param newName must not be {@literal null}.
181+
* @param oldKey must not be {@literal null}.
182+
* @param newKey must not be {@literal null}.
183183
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
184184
* @see RedisKeyCommands#rename(byte[], byte[])
185185
*/
186-
void rename(String oldName, String newName);
186+
void rename(String oldKey, String newKey);
187187

188188
/**
189-
* Rename key {@code oleName} to {@code newName} only if {@code newName} does not exist.
189+
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
190190
*
191191
* @param oldName must not be {@literal null}.
192-
* @param newName must not be {@literal null}.
192+
* @param newKey must not be {@literal null}.
193193
* @return
194194
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
195195
* @see RedisKeyCommands#renameNX(byte[], byte[])
196196
*/
197-
Boolean renameNX(String oldName, String newName);
197+
Boolean renameNX(String oldKey, String newKey);
198198

199199
/**
200200
* Set time to live for given {@code key} in seconds.

Diff for: src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,27 @@ public byte[] randomKey(RedisClusterNode node) {
252252
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
253253
*/
254254
@Override
255-
public void rename(byte[] sourceKey, byte[] targetKey) {
255+
public void rename(byte[] oldKey, byte[] newKey) {
256256

257-
Assert.notNull(sourceKey, "Source key must not be null!");
258-
Assert.notNull(targetKey, "Target key must not be null!");
257+
Assert.notNull(oldKey, "Old key must not be null!");
258+
Assert.notNull(newKey, "New key must not be null!");
259259

260-
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
260+
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldKey, newKey)) {
261261

262262
try {
263-
connection.getCluster().rename(sourceKey, targetKey);
263+
connection.getCluster().rename(oldKey, newKey);
264264
return;
265265
} catch (Exception ex) {
266266
throw convertJedisAccessException(ex);
267267
}
268268
}
269269

270-
byte[] value = dump(sourceKey);
270+
byte[] value = dump(oldKey);
271271

272272
if (value != null && value.length > 0) {
273273

274-
restore(targetKey, 0, value, true);
275-
del(sourceKey);
274+
restore(newKey, 0, value, true);
275+
del(oldKey);
276276
}
277277
}
278278

Diff for: src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ public byte[] randomKey() {
193193
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
194194
*/
195195
@Override
196-
public void rename(byte[] sourceKey, byte[] targetKey) {
196+
public void rename(byte[] oldKey, byte[] newKey) {
197197

198-
Assert.notNull(sourceKey, "Source key must not be null!");
199-
Assert.notNull(targetKey, "Target key must not be null!");
198+
Assert.notNull(oldKey, "Old key must not be null!");
199+
Assert.notNull(newKey, "New key must not be null!");
200200

201-
connection.invokeStatus().just(BinaryJedis::rename, MultiKeyPipelineBase::rename, sourceKey, targetKey);
201+
connection.invokeStatus().just(BinaryJedis::rename, MultiKeyPipelineBase::rename, oldKey, newKey);
202202
}
203203

204204
/*

Diff for: src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyCommands.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,22 @@ public Set<byte[]> keys(byte[] pattern) {
104104
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#rename(byte[], byte[])
105105
*/
106106
@Override
107-
public void rename(byte[] sourceKey, byte[] targetKey) {
107+
public void rename(byte[] oldKey, byte[] newKey) {
108108

109-
Assert.notNull(sourceKey, "Source key must not be null!");
110-
Assert.notNull(targetKey, "Target key must not be null!");
109+
Assert.notNull(oldKey, "Old key must not be null!");
110+
Assert.notNull(newKey, "New key must not be null!");
111111

112-
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
113-
super.rename(sourceKey, targetKey);
112+
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldKey, newKey)) {
113+
super.rename(oldKey, newKey);
114114
return;
115115
}
116116

117-
byte[] value = dump(sourceKey);
117+
byte[] value = dump(oldKey);
118118

119119
if (value != null && value.length > 0) {
120120

121-
restore(targetKey, 0, value, true);
122-
del(sourceKey);
121+
restore(newKey, 0, value, true);
122+
del(oldKey);
123123
}
124124
}
125125

Diff for: src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ public byte[] randomKey() {
200200
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
201201
*/
202202
@Override
203-
public void rename(byte[] sourceKey, byte[] targetKey) {
203+
public void rename(byte[] oldKey, byte[] newKey) {
204204

205-
Assert.notNull(sourceKey, "Source key must not be null!");
206-
Assert.notNull(targetKey, "Target key must not be null!");
205+
Assert.notNull(oldKey, "Old key must not be null!");
206+
Assert.notNull(newKey, "New key must not be null!");
207207

208-
connection.invokeStatus().just(RedisKeyAsyncCommands::rename, sourceKey, targetKey);
208+
connection.invokeStatus().just(RedisKeyAsyncCommands::rename, oldKey, newKey);
209209
}
210210

211211
/*

Diff for: src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommands.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ public Flux<BooleanResponse<RenameCommand>> rename(Publisher<RenameCommand> comm
7878

7979
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
8080

81-
Assert.notNull(command.getKey(), "key must not be null.");
82-
Assert.notNull(command.getNewName(), "NewName must not be null!");
81+
Assert.notNull(command.getKey(), "Old key must not be null.");
82+
Assert.notNull(command.getNewKey(), "New key must not be null!");
8383

84-
if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getKey(), command.getNewName())) {
84+
if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getKey(), command.getNewKey())) {
8585
return super.rename(Mono.just(command));
8686
}
8787

8888
Mono<Boolean> result = cmd.dump(command.getKey())
8989
.switchIfEmpty(Mono.error(new RedisSystemException("Cannot rename key that does not exist",
9090
new RedisException("ERR no such key."))))
91-
.flatMap(value -> cmd.restore(command.getNewName(), 0, value).flatMap(res -> cmd.del(command.getKey())))
91+
.flatMap(value -> cmd.restore(command.getNewKey(), 0, value).flatMap(res -> cmd.del(command.getKey())))
9292
.map(LettuceConverters.longToBooleanConverter()::convert);
9393

9494
return result.map(val -> new BooleanResponse<>(command, val));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ default Flux<K> scan() {
194194
Mono<Boolean> rename(K oldKey, K newKey);
195195

196196
/**
197-
* Rename key {@code oleName} to {@code newKey} only if {@code newKey} does not exist.
197+
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
198198
*
199199
* @param oldKey must not be {@literal null}.
200200
* @param newKey must not be {@literal null}.

0 commit comments

Comments
 (0)