diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 79a59dcc6..7feebc50a 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -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)); } /* diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java index 5c232c7d2..28a0d9d16 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java @@ -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()}. */ diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java index c48c096e7..408ee6106 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveKeyCommands.java @@ -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 Redis Documentation: RENAME */ - default Mono rename(ByteBuffer key, ByteBuffer newName) { + default Mono 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> rename(Publisher 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 Redis Documentation: RENAMENX */ - default Mono renameNX(ByteBuffer key, ByteBuffer newName) { + default Mono 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 diff --git a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java index 185e14303..3cb5533c0 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java @@ -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 Redis Documentation: RENAME */ - 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 Redis Documentation: RENAMENX */ @Nullable - Boolean renameNX(byte[] sourceKey, byte[] targetKey); + Boolean renameNX(byte[] oldKey, byte[] newKey); /** * Set time to live for given {@code key} in seconds. diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index 11e6a1825..8792adc6b 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -192,25 +192,25 @@ public interface StringRedisConnection extends RedisConnection { Collection 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 Redis Documentation: RENAME * @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 Redis Documentation: RENAMENX * @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. diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java index cb4112700..f63c269f9 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java @@ -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); } } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java index f721ffc0b..a6c07703f 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java @@ -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); } /* diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyCommands.java index a9fc12286..ee585cc0a 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyCommands.java @@ -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); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java index f09d2683a..795d2ea93 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java @@ -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); } /* diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommands.java index 6fe1e6683..498c32998 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommands.java @@ -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 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)); diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java index 077746ed3..ebc8d3e2d 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java @@ -265,7 +265,7 @@ public interface ReactiveRedisOperations { Mono 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}.