RObject.copy method added

pull/1423/head
Nikita 7 years ago
parent 601ba4d16f
commit b5688fc07e

@ -103,6 +103,16 @@ public abstract class RedissonObject implements RObject {
return commandExecutor.writeAsync(getName(), RedisCommands.MIGRATE, host, port, getName(), database, timeout); return commandExecutor.writeAsync(getName(), RedisCommands.MIGRATE, host, port, getName(), database, timeout);
} }
@Override
public void copy(String host, int port, int database, long timeout) {
get(copyAsync(host, port, database, timeout));
}
@Override
public RFuture<Void> copyAsync(String host, int port, int database, long timeout) {
return commandExecutor.writeAsync(getName(), RedisCommands.MIGRATE, host, port, getName(), database, timeout, "COPY");
}
@Override @Override
public boolean move(int database) { public boolean move(int database) {
return get(moveAsync(database)); return get(moveAsync(database));

@ -33,7 +33,7 @@ public interface RObject extends RObjectAsync {
boolean touch(); boolean touch();
/** /**
* Transfer an object from source Redis instance to destination Redis instance * Copy object from source Redis instance to destination Redis instance
* *
* @param host - destination host * @param host - destination host
* @param port - destination port * @param port - destination port
@ -42,6 +42,16 @@ public interface RObject extends RObjectAsync {
*/ */
void migrate(String host, int port, int database, long timeout); void migrate(String host, int port, int database, long timeout);
/**
* Copy object from source Redis instance to destination Redis instance
*
* @param host - destination host
* @param port - destination port
* @param database - destination database
* @param timeout - maximum idle time in any moment of the communication with the destination instance in milliseconds
*/
void copy(String host, int port, int database, long timeout);
/** /**
* Move object to another database * Move object to another database
* *

@ -31,7 +31,7 @@ public interface RObjectAsync {
RFuture<Boolean> touchAsync(); RFuture<Boolean> touchAsync();
/** /**
* Transfer an object from source Redis instance to destination Redis instance * Transfer object from source Redis instance to destination Redis instance
* in async mode * in async mode
* *
* @param host - destination host * @param host - destination host
@ -42,6 +42,18 @@ public interface RObjectAsync {
*/ */
RFuture<Void> migrateAsync(String host, int port, int database, long timeout); RFuture<Void> migrateAsync(String host, int port, int database, long timeout);
/**
* Copy object from source Redis instance to destination Redis instance
* in async mode
*
* @param host - destination host
* @param port - destination port
* @param database - destination database
* @param timeout - maximum idle time in any moment of the communication with the destination instance in milliseconds
* @return void
*/
RFuture<Void> copyAsync(String host, int port, int database, long timeout);
/** /**
* Move object to another database in async mode * Move object to another database in async mode
* *

@ -142,6 +142,29 @@ public class RedissonBucketTest extends BaseTest {
runner.stop(); runner.stop();
} }
@Test
public void testCopy() throws FailedToStartRedisException, IOException, InterruptedException {
RedisProcess runner = new RedisRunner()
.appendonly(true)
.randomDir()
.randomPort()
.run();
RBucket<String> bucket = redisson.getBucket("test");
bucket.set("someValue");
bucket.copy(runner.getRedisServerBindAddress(), runner.getRedisServerPort(), 0, 5000);
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient r = Redisson.create(config);
RBucket<String> bucket2 = r.getBucket("test");
assertThat(bucket2.get()).isEqualTo("someValue");
assertThat(bucket.get()).isEqualTo("someValue");
runner.stop();
}
@Test @Test
public void testRename() { public void testRename() {

Loading…
Cancel
Save