DATAREDIS-1190 - Cluster rename now correctly overwrites existing keys.
rename(…) behavior in cluster-mode is now aligned with standalone Redis behavior that overwrites the target key if it already exists and the renamed key uses a different slot. Previously, the underlying restore command was called without the replace option which caused BUSYKEY failures. Original Pull Request: #555
This commit is contained in:
committed by
Christoph Strobl
parent
e987f33248
commit
5c6b0c3fb3
@@ -269,7 +269,7 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
|
||||
|
||||
if (value != null && value.length > 0) {
|
||||
|
||||
restore(targetKey, 0, value);
|
||||
restore(targetKey, 0, value, true);
|
||||
del(sourceKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class LettuceClusterKeyCommands extends LettuceKeyCommands {
|
||||
|
||||
if (value != null && value.length > 0) {
|
||||
|
||||
restore(targetKey, 0, value);
|
||||
restore(targetKey, 0, value, true);
|
||||
del(sourceKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,6 +413,9 @@ public interface ClusterConnectionTests {
|
||||
// DATAREDIS-315
|
||||
void rename();
|
||||
|
||||
// DATAREDIS-1190
|
||||
void renameShouldOverwriteTargetKey();
|
||||
|
||||
// DATAREDIS-315
|
||||
void renameNXWhenOnSameSlot();
|
||||
|
||||
|
||||
@@ -1421,6 +1421,18 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(nativeConnection.get(KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1190
|
||||
public void renameShouldOverwriteTargetKey() {
|
||||
|
||||
nativeConnection.set(KEY_1_BYTES, VALUE_1_BYTES);
|
||||
nativeConnection.set(KEY_2_BYTES, VALUE_2_BYTES);
|
||||
|
||||
clusterConnection.rename(KEY_1_BYTES, KEY_2_BYTES);
|
||||
|
||||
assertThat(nativeConnection.exists(KEY_1_BYTES)).isFalse();
|
||||
assertThat(nativeConnection.get(KEY_2_BYTES)).isEqualTo(VALUE_1_BYTES);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void renameNXWhenOnSameSlot() {
|
||||
|
||||
|
||||
@@ -1437,6 +1437,18 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(nativeConnection.get(KEY_2)).isEqualTo(VALUE_1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1190
|
||||
public void renameShouldOverwriteTargetKey() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_2);
|
||||
|
||||
clusterConnection.rename(KEY_1_BYTES, KEY_2_BYTES);
|
||||
|
||||
assertThat(nativeConnection.exists(KEY_1)).isEqualTo(0L);
|
||||
assertThat(nativeConnection.get(KEY_2)).isEqualTo(VALUE_1);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void renameNXWhenOnSameSlot() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user