DATAREDIS-696 - Add support for REPLACE option to RESTORE.

We bypass the lack of driver support by directly executing a custom command.

Original pull request: #344.
This commit is contained in:
Christoph Strobl
2018-05-25 13:55:19 +02:00
committed by Mark Paluch
parent 64dee51919
commit 9e74556f74
13 changed files with 134 additions and 31 deletions

View File

@@ -1113,6 +1113,20 @@ public abstract class AbstractConnectionIntegrationTests {
getResults();
}
@Test // DATAREDIS-696
@IfProfileValue(name = "redisVersion", value = "3.0+")
public void testRestoreExistingKeyWithReplaceOption() {
actual.add(connection.set("testing", "12"));
actual.add(connection.dump("testing".getBytes()));
actual.add(connection.set("testing", "21"));
connection.restore("testing".getBytes(), 0, (byte[]) getResults().get(1), true);
initConnection();
actual.add(connection.get("testing"));
verifyResults(Arrays.asList(new Object[] { "12" }));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreTtl() {
@@ -2947,14 +2961,10 @@ public abstract class AbstractConnectionIntegrationTests {
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
actual.add(
connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(
connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(
connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(
connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
actual.add(connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L)));
List<Object> results = getResults();
assertThat((List<Long>) results.get(0), contains(1L));
@@ -2969,8 +2979,7 @@ public abstract class AbstractConnectionIntegrationTests {
public void bitfieldShouldAllowMultipleSubcommands() {
actual.add(
connection.bitfield(KEY_1,
create().incr(signed(5)).valueAt(offset(100L)).by(1L).get(unsigned(4)).valueAt(0L)));
connection.bitfield(KEY_1, create().incr(signed(5)).valueAt(offset(100L)).by(1L).get(unsigned(4)).valueAt(0L)));
assertThat((List<Long>) getResults().get(0), contains(1L, 0L));
}

View File

@@ -96,6 +96,9 @@ public interface ClusterConnectionTests {
// DATAREDIS-315
void dumpAndRestoreShouldWorkCorrectly();
// DATAREDIS-696
void dumpAndRestoreWithReplaceOptionShouldWorkCorrectly();
// DATAREDIS-315
void echoShouldReturnInputCorrectly();

View File

@@ -772,8 +772,8 @@ public class RedisConnectionUnitTests {
delegate.slaveOfNoOne();
}
public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) {
delegate.restore(key, ttlInMillis, serializedValue);
public void restore(byte[] key, long ttlInMillis, byte[] serializedValue, boolean replace) {
delegate.restore(key, ttlInMillis, serializedValue, replace);
}
public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) {

View File

@@ -355,6 +355,20 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
assertThat(nativeConnection.get(KEY_2), is(VALUE_1));
}
@Test // DATAREDIS-696
public void dumpAndRestoreWithReplaceOptionShouldWorkCorrectly() {
nativeConnection.set(KEY_1, VALUE_1);
byte[] dumpedValue = clusterConnection.keyCommands().dump(KEY_1_BYTES);
nativeConnection.set(KEY_1, VALUE_2);
clusterConnection.keyCommands().restore(KEY_1_BYTES, 0, dumpedValue, true);
assertThat(nativeConnection.get(KEY_1), is(VALUE_1));
}
@Test // DATAREDIS-315
public void echoShouldReturnInputCorrectly() {
assertThat(clusterConnection.echo(VALUE_1_BYTES), is(VALUE_1_BYTES));

View File

@@ -392,6 +392,20 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
assertThat(nativeConnection.get(KEY_2), is(VALUE_1));
}
@Test // DATAREDIS-696
public void dumpAndRestoreWithReplaceOptionShouldWorkCorrectly() {
nativeConnection.set(KEY_1, VALUE_1);
byte[] dumpedValue = clusterConnection.keyCommands().dump(KEY_1_BYTES);
nativeConnection.set(KEY_1, VALUE_2);
clusterConnection.keyCommands().restore(KEY_1_BYTES, 0, dumpedValue, true);
assertThat(nativeConnection.get(KEY_1), is(VALUE_1));
}
@Test // DATAREDIS-315
public void echoShouldReturnInputCorrectly() {
assertThat(clusterConnection.echo(VALUE_1_BYTES), is(VALUE_1_BYTES));