Polishing.
Rename key name arguments consistently to oldKey/newKey. See #2189
This commit is contained in:
@@ -963,8 +963,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
|
||||
*/
|
||||
@Override
|
||||
public void rename(byte[] sourceKey, byte[] targetKey) {
|
||||
delegate.rename(sourceKey, targetKey);
|
||||
public void rename(byte[] oldKey, byte[] newKey) {
|
||||
delegate.rename(oldKey, newKey);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -972,8 +972,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#renameNX(byte[], byte[])
|
||||
*/
|
||||
@Override
|
||||
public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
|
||||
return convertAndReturn(delegate.renameNX(sourceKey, targetKey), Converters.identityConverter());
|
||||
public Boolean renameNX(byte[] oldKey, byte[] newKey) {
|
||||
return convertAndReturn(delegate.renameNX(oldKey, newKey), Converters.identityConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2727,8 +2727,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#rename(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void rename(String oldName, String newName) {
|
||||
delegate.rename(serialize(oldName), serialize(newName));
|
||||
public void rename(String oldKey, String newKey) {
|
||||
delegate.rename(serialize(oldKey), serialize(newKey));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2736,8 +2736,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#renameNX(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Boolean renameNX(String oldName, String newName) {
|
||||
return renameNX(serialize(oldName), serialize(newName));
|
||||
public Boolean renameNX(String oldKey, String newKey) {
|
||||
return renameNX(serialize(oldKey), serialize(newKey));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -139,8 +139,8 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default void rename(byte[] sourceKey, byte[] targetKey) {
|
||||
keyCommands().rename(sourceKey, targetKey);
|
||||
default void rename(byte[] oldKey, byte[] newKey) {
|
||||
keyCommands().rename(oldKey, newKey);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#keyCommands()}. */
|
||||
|
||||
@@ -311,13 +311,13 @@ public interface ReactiveKeyCommands {
|
||||
*/
|
||||
class RenameCommand extends KeyCommand {
|
||||
|
||||
private @Nullable ByteBuffer newName;
|
||||
private @Nullable ByteBuffer newKey;
|
||||
|
||||
private RenameCommand(ByteBuffer key, @Nullable ByteBuffer newName) {
|
||||
private RenameCommand(ByteBuffer key, @Nullable ByteBuffer newKey) {
|
||||
|
||||
super(key);
|
||||
|
||||
this.newName = newName;
|
||||
this.newKey = newKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,44 +334,55 @@ public interface ReactiveKeyCommands {
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the {@literal newName}. Constructs a new command instance with all previously configured properties.
|
||||
* Applies the {@literal newKey}. Constructs a new command instance with all previously configured properties.
|
||||
*
|
||||
* @param newName must not be {@literal null}.
|
||||
* @return a new {@link RenameCommand} with {@literal newName} applied.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @return a new {@link RenameCommand} with {@literal newKey} applied.
|
||||
*/
|
||||
public RenameCommand to(ByteBuffer newName) {
|
||||
public RenameCommand to(ByteBuffer newKey) {
|
||||
|
||||
Assert.notNull(newName, "New name must not be null!");
|
||||
Assert.notNull(newKey, "New key name must not be null!");
|
||||
|
||||
return new RenameCommand(getKey(), newName);
|
||||
return new RenameCommand(getKey(), newKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return can be {@literal null}.
|
||||
* @deprecated since 2.5.7, renamed to {@link #getNewKey()}.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public ByteBuffer getNewName() {
|
||||
return newName;
|
||||
return newKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return can be {@literal null}.
|
||||
* @since 2.5.7
|
||||
*/
|
||||
@Nullable
|
||||
public ByteBuffer getNewKey() {
|
||||
return newKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename key {@literal oleName} to {@literal newName}.
|
||||
* Rename key {@literal oldKey} to {@literal newKey}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param newName must not be {@literal null}.
|
||||
* @param oldKey must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
|
||||
*/
|
||||
default Mono<Boolean> rename(ByteBuffer key, ByteBuffer newName) {
|
||||
default Mono<Boolean> rename(ByteBuffer oldKey, ByteBuffer newKey) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(oldKey, "Key must not be null!");
|
||||
|
||||
return rename(Mono.just(RenameCommand.key(key).to(newName))).next().map(BooleanResponse::getOutput);
|
||||
return rename(Mono.just(RenameCommand.key(oldKey).to(newKey))).next().map(BooleanResponse::getOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename key {@literal oleName} to {@literal newName}.
|
||||
* Rename key {@literal oldKey} to {@literal newKey}.
|
||||
*
|
||||
* @param command must not be {@literal null}.
|
||||
* @return
|
||||
@@ -380,22 +391,22 @@ public interface ReactiveKeyCommands {
|
||||
Flux<BooleanResponse<RenameCommand>> rename(Publisher<RenameCommand> command);
|
||||
|
||||
/**
|
||||
* Rename key {@literal oleName} to {@literal newName} only if {@literal newName} does not exist.
|
||||
* Rename key {@literal oldKey} to {@literal newKey} only if {@literal newKey} does not exist.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param newName must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
|
||||
*/
|
||||
default Mono<Boolean> renameNX(ByteBuffer key, ByteBuffer newName) {
|
||||
default Mono<Boolean> renameNX(ByteBuffer key, ByteBuffer newKey) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return renameNX(Mono.just(RenameCommand.key(key).to(newName))).next().map(BooleanResponse::getOutput);
|
||||
return renameNX(Mono.just(RenameCommand.key(key).to(newKey))).next().map(BooleanResponse::getOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename key {@literal oleName} to {@literal newName} only if {@literal newName} does not exist.
|
||||
* Rename key {@literal oldKey} to {@literal newKey} only if {@literal newKey} does not exist.
|
||||
*
|
||||
* @param command must not be {@literal null}.
|
||||
* @return
|
||||
|
||||
@@ -161,24 +161,24 @@ public interface RedisKeyCommands {
|
||||
byte[] randomKey();
|
||||
|
||||
/**
|
||||
* Rename key {@code sourceKey} to {@code targetKey}.
|
||||
* Rename key {@code oldKey} to {@code newKey}.
|
||||
*
|
||||
* @param sourceKey must not be {@literal null}.
|
||||
* @param targetKey must not be {@literal null}.
|
||||
* @param oldKey must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
|
||||
*/
|
||||
void rename(byte[] sourceKey, byte[] targetKey);
|
||||
void rename(byte[] oldKey, byte[] newKey);
|
||||
|
||||
/**
|
||||
* Rename key {@code sourceKey} to {@code targetKey} only if {@code targetKey} does not exist.
|
||||
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
|
||||
*
|
||||
* @param sourceKey must not be {@literal null}.
|
||||
* @param targetKey must not be {@literal null}.
|
||||
* @param oldKey must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
|
||||
*/
|
||||
@Nullable
|
||||
Boolean renameNX(byte[] sourceKey, byte[] targetKey);
|
||||
Boolean renameNX(byte[] oldKey, byte[] newKey);
|
||||
|
||||
/**
|
||||
* Set time to live for given {@code key} in seconds.
|
||||
|
||||
@@ -192,25 +192,25 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
Collection<String> keys(String pattern);
|
||||
|
||||
/**
|
||||
* Rename key {@code oleName} to {@code newName}.
|
||||
* Rename key {@code oldKey} to {@code newKey}.
|
||||
*
|
||||
* @param oldName must not be {@literal null}.
|
||||
* @param newName must not be {@literal null}.
|
||||
* @param oldKey must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/rename">Redis Documentation: RENAME</a>
|
||||
* @see RedisKeyCommands#rename(byte[], byte[])
|
||||
*/
|
||||
void rename(String oldName, String newName);
|
||||
void rename(String oldKey, String newKey);
|
||||
|
||||
/**
|
||||
* Rename key {@code oleName} to {@code newName} only if {@code newName} does not exist.
|
||||
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
|
||||
*
|
||||
* @param oldName must not be {@literal null}.
|
||||
* @param newName must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/renamenx">Redis Documentation: RENAMENX</a>
|
||||
* @see RedisKeyCommands#renameNX(byte[], byte[])
|
||||
*/
|
||||
Boolean renameNX(String oldName, String newName);
|
||||
Boolean renameNX(String oldKey, String newKey);
|
||||
|
||||
/**
|
||||
* Set time to live for given {@code key} in seconds.
|
||||
|
||||
@@ -266,27 +266,27 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
|
||||
*/
|
||||
@Override
|
||||
public void rename(byte[] sourceKey, byte[] targetKey) {
|
||||
public void rename(byte[] oldKey, byte[] newKey) {
|
||||
|
||||
Assert.notNull(sourceKey, "Source key must not be null!");
|
||||
Assert.notNull(targetKey, "Target key must not be null!");
|
||||
Assert.notNull(oldKey, "Old key must not be null!");
|
||||
Assert.notNull(newKey, "New key must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldKey, newKey)) {
|
||||
|
||||
try {
|
||||
connection.getCluster().rename(sourceKey, targetKey);
|
||||
connection.getCluster().rename(oldKey, newKey);
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] value = dump(sourceKey);
|
||||
byte[] value = dump(oldKey);
|
||||
|
||||
if (value != null && value.length > 0) {
|
||||
|
||||
restore(targetKey, 0, value, true);
|
||||
del(sourceKey);
|
||||
restore(newKey, 0, value, true);
|
||||
del(oldKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -228,12 +228,12 @@ class JedisKeyCommands implements RedisKeyCommands {
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
|
||||
*/
|
||||
@Override
|
||||
public void rename(byte[] sourceKey, byte[] targetKey) {
|
||||
public void rename(byte[] oldKey, byte[] newKey) {
|
||||
|
||||
Assert.notNull(sourceKey, "Source key must not be null!");
|
||||
Assert.notNull(targetKey, "Target key must not be null!");
|
||||
Assert.notNull(oldKey, "Old key must not be null!");
|
||||
Assert.notNull(newKey, "New key must not be null!");
|
||||
|
||||
connection.invokeStatus().just(BinaryJedis::rename, MultiKeyPipelineBase::rename, sourceKey, targetKey);
|
||||
connection.invokeStatus().just(BinaryJedis::rename, MultiKeyPipelineBase::rename, oldKey, newKey);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -104,22 +104,22 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
|
||||
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#rename(byte[], byte[])
|
||||
*/
|
||||
@Override
|
||||
public void rename(byte[] sourceKey, byte[] targetKey) {
|
||||
public void rename(byte[] oldKey, byte[] newKey) {
|
||||
|
||||
Assert.notNull(sourceKey, "Source key must not be null!");
|
||||
Assert.notNull(targetKey, "Target key must not be null!");
|
||||
Assert.notNull(oldKey, "Old key must not be null!");
|
||||
Assert.notNull(newKey, "New key must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) {
|
||||
super.rename(sourceKey, targetKey);
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(oldKey, newKey)) {
|
||||
super.rename(oldKey, newKey);
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] value = dump(sourceKey);
|
||||
byte[] value = dump(oldKey);
|
||||
|
||||
if (value != null && value.length > 0) {
|
||||
|
||||
restore(targetKey, 0, value, true);
|
||||
del(sourceKey);
|
||||
restore(newKey, 0, value, true);
|
||||
del(oldKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,12 +217,12 @@ class LettuceKeyCommands implements RedisKeyCommands {
|
||||
* @see org.springframework.data.redis.connection.RedisKeyCommands#rename(byte[], byte[])
|
||||
*/
|
||||
@Override
|
||||
public void rename(byte[] sourceKey, byte[] targetKey) {
|
||||
public void rename(byte[] oldKey, byte[] newKey) {
|
||||
|
||||
Assert.notNull(sourceKey, "Source key must not be null!");
|
||||
Assert.notNull(targetKey, "Target key must not be null!");
|
||||
Assert.notNull(oldKey, "Old key must not be null!");
|
||||
Assert.notNull(newKey, "New key must not be null!");
|
||||
|
||||
connection.invokeStatus().just(RedisKeyAsyncCommands::rename, sourceKey, targetKey);
|
||||
connection.invokeStatus().just(RedisKeyAsyncCommands::rename, oldKey, newKey);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -78,17 +78,17 @@ class LettuceReactiveClusterKeyCommands extends LettuceReactiveKeyCommands imple
|
||||
|
||||
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
|
||||
|
||||
Assert.notNull(command.getKey(), "key must not be null.");
|
||||
Assert.notNull(command.getNewName(), "NewName must not be null!");
|
||||
Assert.notNull(command.getKey(), "Old key must not be null.");
|
||||
Assert.notNull(command.getNewKey(), "New key must not be null!");
|
||||
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getKey(), command.getNewName())) {
|
||||
if (ClusterSlotHashUtil.isSameSlotForAllKeys(command.getKey(), command.getNewKey())) {
|
||||
return super.rename(Mono.just(command));
|
||||
}
|
||||
|
||||
Mono<Boolean> result = cmd.dump(command.getKey())
|
||||
.switchIfEmpty(Mono.error(new RedisSystemException("Cannot rename key that does not exist",
|
||||
new RedisException("ERR no such key."))))
|
||||
.flatMap(value -> cmd.restore(command.getNewName(), 0, value).flatMap(res -> cmd.del(command.getKey())))
|
||||
.flatMap(value -> cmd.restore(command.getNewKey(), 0, value).flatMap(res -> cmd.del(command.getKey())))
|
||||
.map(LettuceConverters.longToBooleanConverter()::convert);
|
||||
|
||||
return result.map(val -> new BooleanResponse<>(command, val));
|
||||
|
||||
@@ -265,7 +265,7 @@ public interface ReactiveRedisOperations<K, V> {
|
||||
Mono<Boolean> rename(K oldKey, K newKey);
|
||||
|
||||
/**
|
||||
* Rename key {@code oleName} to {@code newKey} only if {@code newKey} does not exist.
|
||||
* Rename key {@code oldKey} to {@code newKey} only if {@code newKey} does not exist.
|
||||
*
|
||||
* @param oldKey must not be {@literal null}.
|
||||
* @param newKey must not be {@literal null}.
|
||||
|
||||
Reference in New Issue
Block a user