Skip to content

Commit b2f7b6f

Browse files
committed
Polishing.
Rename key name arguments consistently to oldKey/newKey. See #2189
1 parent b67f133 commit b2f7b6f

11 files changed

+87
-76
lines changed

src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -963,17 +963,17 @@ public byte[] randomKey() {
963963
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
964964
*/
965965
@Override
966-
public void rename(byte[] sourceKey, byte[] targetKey) {
967-
delegate.rename(sourceKey, targetKey);
966+
public void rename(byte[] oldKey, byte[] newKey) {
967+
delegate.rename(oldKey, newKey);
968968
}
969969

970970
/*
971971
* (non-Javadoc)
972972
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
973973
*/
974974
@Override
975-
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
976-
return convertAndReturn(delegate.renameNX(sourceKey, targetKey), Converters.identityConverter());
975+
public Boolean renameNX(byte[] oldKey, byte[] newKey) {
976+
return convertAndReturn(delegate.renameNX(oldKey, newKey), Converters.identityConverter());
977977
}
978978

979979
/*
@@ -2727,17 +2727,17 @@ public Long publish(String channel, String message) {
27272727
* @see org.springframework.data.redis.connection.StringRedisConnection#rename(java.lang.String, java.lang.String)
27282728
*/
27292729
@Override
2730-
public void rename(String oldName, String newName) {
2731-
delegate.rename(serialize(oldName), serialize(newName));
2730+
public void rename(String oldKey, String newKey) {
2731+
delegate.rename(serialize(oldKey), serialize(newKey));
27322732
}
27332733

27342734
/*
27352735
* (non-Javadoc)
27362736
* @see org.springframework.data.redis.connection.StringRedisConnection#renameNX(java.lang.String, java.lang.String)
27372737
*/
27382738
@Override
2739-
public Boolean renameNX(String oldName, String newName) {
2740-
return renameNX(serialize(oldName), serialize(newName));
2739+
public Boolean renameNX(String oldKey, String newKey) {
2740+
return renameNX(serialize(oldKey), serialize(newKey));
27412741
}
27422742

27432743
/*

src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ default byte[] randomKey() {
139139
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
140140
@Override
141141
@Deprecated
142-
default void rename(byte[] sourceKey, byte[] targetKey) {
143-
keyCommands().rename(sourceKey, targetKey);
142+
default void rename(byte[] oldKey, byte[] newKey) {
143+
keyCommands().rename(oldKey, newKey);
144144
}
145145

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

src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,13 @@ default Flux<ByteBuffer> scan(KeyScanOptions options) {
311311
*/
312312
class RenameCommand extends KeyCommand {
313313

314-
private @Nullable ByteBuffer newName;
314+
private @Nullable ByteBuffer newKey;
315315

316-
private RenameCommand(ByteBuffer key, @Nullable ByteBuffer newName) {
316+
private RenameCommand(ByteBuffer key, @Nullable ByteBuffer newKey) {
317317

318318
super(key);
319319

320-
this.newName = newName;
320+
this.newKey = newKey;
321321
}
322322

323323
/**
@@ -334,44 +334,55 @@ public static RenameCommand key(ByteBuffer key) {
334334
}
335335

336336
/**
337-
* Applies the {@literal newName}. Constructs a new command instance with all previously configured properties.
337+
* Applies the {@literal newKey}. Constructs a new command instance with all previously configured properties.
338338
*
339-
* @param newName must not be {@literal null}.
340-
* @return a new {@link RenameCommand} with {@literal newName} applied.
339+
* @param newKey must not be {@literal null}.
340+
* @return a new {@link RenameCommand} with {@literal newKey} applied.
341341
*/
342-
public RenameCommand to(ByteBuffer newName) {
342+
public RenameCommand to(ByteBuffer newKey) {
343343

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

346-
return new RenameCommand(getKey(), newName);
346+
return new RenameCommand(getKey(), newKey);
347347
}
348348

349349
/**
350350
* @return can be {@literal null}.
351+
* @deprecated since 2.5.7, renamed to {@link #getNewKey()}.
351352
*/
352353
@Nullable
354+
@Deprecated
353355
public ByteBuffer getNewName() {
354-
return newName;
356+
return newKey;
357+
}
358+
359+
/**
360+
* @return can be {@literal null}.
361+
* @since 2.5.7
362+
*/
363+
@Nullable
364+
public ByteBuffer getNewKey() {
365+
return newKey;
355366
}
356367
}
357368

358369
/**
359-
* Rename key {@literal oleName} to {@literal newName}.
370+
* Rename key {@literal oldKey} to {@literal newKey}.
360371
*
361-
* @param key must not be {@literal null}.
362-
* @param newName must not be {@literal null}.
372+
* @param oldKey must not be {@literal null}.
373+
* @param newKey must not be {@literal null}.
363374
* @return
364375
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
365376
*/
366-
default Mono<Boolean> rename(ByteBuffer key, ByteBuffer newName) {
377+
default Mono<Boolean> rename(ByteBuffer oldKey, ByteBuffer newKey) {
367378

368-
Assert.notNull(key, "Key must not be null!");
379+
Assert.notNull(oldKey, "Key must not be null!");
369380

370-
return rename(Mono.just(RenameCommand.key(key).to(newName))).next().map(BooleanResponse::getOutput);
381+
return rename(Mono.just(RenameCommand.key(oldKey).to(newKey))).next().map(BooleanResponse::getOutput);
371382
}
372383

373384
/**
374-
* Rename key {@literal oleName} to {@literal newName}.
385+
* Rename key {@literal oldKey} to {@literal newKey}.
375386
*
376387
* @param command must not be {@literal null}.
377388
* @return
@@ -380,22 +391,22 @@ default Mono<Boolean> rename(ByteBuffer key, ByteBuffer newName) {
380391
Flux<BooleanResponse<RenameCommand>> rename(Publisher<RenameCommand> command);
381392

382393
/**
383-
* Rename key {@literal oleName} to {@literal newName} only if {@literal newName} does not exist.
394+
* Rename key {@literal oldKey} to {@literal newKey} only if {@literal newKey} does not exist.
384395
*
385396
* @param key must not be {@literal null}.
386-
* @param newName must not be {@literal null}.
397+
* @param newKey must not be {@literal null}.
387398
* @return
388399
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
389400
*/
390-
default Mono<Boolean> renameNX(ByteBuffer key, ByteBuffer newName) {
401+
default Mono<Boolean> renameNX(ByteBuffer key, ByteBuffer newKey) {
391402

392403
Assert.notNull(key, "Key must not be null!");
393404

394-
return renameNX(Mono.just(RenameCommand.key(key).to(newName))).next().map(BooleanResponse::getOutput);
405+
return renameNX(Mono.just(RenameCommand.key(key).to(newKey))).next().map(BooleanResponse::getOutput);
395406
}
396407

397408
/**
398-
* Rename key {@literal oleName} to {@literal newName} only if {@literal newName} does not exist.
409+
* Rename key {@literal oldKey} to {@literal newKey} only if {@literal newKey} does not exist.
399410
*
400411
* @param command must not be {@literal null}.
401412
* @return

src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,24 @@ default Cursor<byte[]> scan(KeyScanOptions options) {
161161
byte[] randomKey();
162162

163163
/**
164-
* Rename key {@code sourceKey} to {@code targetKey}.
164+
* Rename key {@code oldKey} to {@code newKey}.
165165
*
166-
* @param sourceKey must not be {@literal null}.
167-
* @param targetKey must not be {@literal null}.
166+
* @param oldKey must not be {@literal null}.
167+
* @param newKey must not be {@literal null}.
168168
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
169169
*/
170-
void rename(byte[] sourceKey, byte[] targetKey);
170+
void rename(byte[] oldKey, byte[] newKey);
171171

172172
/**
173-
* Rename key {@code sourceKey} to {@code targetKey} only if {@code targetKey} does not exist.
173+
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
174174
*
175-
* @param sourceKey must not be {@literal null}.
176-
* @param targetKey must not be {@literal null}.
175+
* @param oldKey must not be {@literal null}.
176+
* @param newKey must not be {@literal null}.
177177
* @return {@literal null} when used in pipeline / transaction.
178178
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
179179
*/
180180
@Nullable
181-
Boolean renameNX(byte[] sourceKey, byte[] targetKey);
181+
Boolean renameNX(byte[] oldKey, byte[] newKey);
182182

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

src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,25 @@ interface StringTuple extends Tuple {
192192
Collection<String> keys(String pattern);
193193

194194
/**
195-
* Rename key {@code oleName} to {@code newName}.
195+
* Rename key {@code oldKey} to {@code newKey}.
196196
*
197-
* @param oldName must not be {@literal null}.
198-
* @param newName must not be {@literal null}.
197+
* @param oldKey must not be {@literal null}.
198+
* @param newKey must not be {@literal null}.
199199
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
200200
* @see RedisKeyCommands#rename(byte[], byte[])
201201
*/
202-
void rename(String oldName, String newName);
202+
void rename(String oldKey, String newKey);
203203

204204
/**
205-
* Rename key {@code oleName} to {@code newName} only if {@code newName} does not exist.
205+
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
206206
*
207207
* @param oldName must not be {@literal null}.
208-
* @param newName must not be {@literal null}.
208+
* @param newKey must not be {@literal null}.
209209
* @return
210210
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
211211
* @see RedisKeyCommands#renameNX(byte[], byte[])
212212
*/
213-
Boolean renameNX(String oldName, String newName);
213+
Boolean renameNX(String oldKey, String newKey);
214214

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

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,27 +266,27 @@ public byte[] randomKey(RedisClusterNode node) {
266266
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
267267
*/
268268
@Override
269-
public void rename(byte[] sourceKey, byte[] targetKey) {
269+
public void rename(byte[] oldKey, byte[] newKey) {
270270

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

274-
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
274+
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldKey, newKey)) {
275275

276276
try {
277-
connection.getCluster().rename(sourceKey, targetKey);
277+
connection.getCluster().rename(oldKey, newKey);
278278
return;
279279
} catch (Exception ex) {
280280
throw convertJedisAccessException(ex);
281281
}
282282
}
283283

284-
byte[] value = dump(sourceKey);
284+
byte[] value = dump(oldKey);
285285

286286
if (value != null && value.length > 0) {
287287

288-
restore(targetKey, 0, value, true);
289-
del(sourceKey);
288+
restore(newKey, 0, value, true);
289+
del(oldKey);
290290
}
291291
}
292292

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ public byte[] randomKey() {
228228
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
229229
*/
230230
@Override
231-
public void rename(byte[] sourceKey, byte[] targetKey) {
231+
public void rename(byte[] oldKey, byte[] newKey) {
232232

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

236-
connection.invokeStatus().just(BinaryJedis::rename, MultiKeyPipelineBase::rename, sourceKey, targetKey);
236+
connection.invokeStatus().just(BinaryJedis::rename, MultiKeyPipelineBase::rename, oldKey, newKey);
237237
}
238238

239239
/*

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

Lines changed: 8 additions & 8 deletions
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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ public byte[] randomKey() {
217217
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
218218
*/
219219
@Override
220-
public void rename(byte[] sourceKey, byte[] targetKey) {
220+
public void rename(byte[] oldKey, byte[] newKey) {
221221

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

225-
connection.invokeStatus().just(RedisKeyAsyncCommands::rename, sourceKey, targetKey);
225+
connection.invokeStatus().just(RedisKeyAsyncCommands::rename, oldKey, newKey);
226226
}
227227

228228
/*

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

Lines changed: 4 additions & 4 deletions
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));

src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ default Flux<K> scan() {
265265
Mono<Boolean> rename(K oldKey, K newKey);
266266

267267
/**
268-
* Rename key {@code oleName} to {@code newKey} only if {@code newKey} does not exist.
268+
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
269269
*
270270
* @param oldKey must not be {@literal null}.
271271
* @param newKey must not be {@literal null}.

0 commit comments

Comments
 (0)