Migrate command support. #187

pull/243/head
Nikita 10 years ago
parent 6a7e64a50d
commit 5006723b31

@ -51,15 +51,25 @@ abstract class RedissonObject implements RObject {
}
@Override
public boolean rename(String newName) {
return get(renameAsync(newName));
public void rename(String newName) {
get(renameAsync(newName));
}
@Override
public Future<Boolean> renameAsync(String newName) {
public Future<Void> renameAsync(String newName) {
return commandExecutor.writeAsync(getName(), RedisCommands.RENAME, getName(), newName);
}
@Override
public void migrate(String host, int port, int database) {
get(migrateAsync(host, port, database));
}
@Override
public Future<Void> migrateAsync(String host, int port, int database) {
return commandExecutor.writeAsync(getName(), RedisCommands.MIGRATE, host, port, getName(), database);
}
@Override
public boolean move(int database) {
return get(moveAsync(database));

@ -45,9 +45,9 @@ public interface RedisCommands {
RedisStrictCommand<String> PING = new RedisStrictCommand<String>("PING");
RedisStrictCommand<Boolean> UNWATCH = new RedisStrictCommand<Boolean>("UNWATCH", new BooleanReplayConvertor());
RedisStrictCommand<Boolean> WATCH = new RedisStrictCommand<Boolean>("WATCH", new BooleanReplayConvertor());
RedisStrictCommand<Boolean> MULTI = new RedisStrictCommand<Boolean>("MULTI", new BooleanReplayConvertor());
RedisStrictCommand<Void> UNWATCH = new RedisStrictCommand<Void>("UNWATCH", new VoidReplayConvertor());
RedisStrictCommand<Void> WATCH = new RedisStrictCommand<Void>("WATCH", new VoidReplayConvertor());
RedisStrictCommand<Void> MULTI = new RedisStrictCommand<Void>("MULTI", new VoidReplayConvertor());
RedisCommand<List<Object>> EXEC = new RedisCommand<List<Object>>("EXEC", new ObjectListReplayDecoder());
RedisCommand<Long> SREM = new RedisCommand<Long>("SREM", 2, ValueType.OBJECTS);
@ -135,8 +135,9 @@ public interface RedisCommands {
RedisStrictCommand<Boolean> EXISTS = new RedisStrictCommand<Boolean>("EXISTS", new BooleanReplayConvertor());
RedisStrictCommand<Boolean> RENAMENX = new RedisStrictCommand<Boolean>("RENAMENX", new BooleanReplayConvertor());
RedisStrictCommand<Boolean> RENAME = new RedisStrictCommand<Boolean>("RENAME", new BooleanReplayConvertor());
RedisStrictCommand<Void> RENAME = new RedisStrictCommand<Void>("RENAME", new VoidReplayConvertor());
RedisStrictCommand<Boolean> MOVE = new RedisStrictCommand<Boolean>("MOVE", new BooleanReplayConvertor());
RedisStrictCommand<Void> MIGRATE = new RedisStrictCommand<Void>("MIGRATE", new VoidReplayConvertor());
RedisCommand<Long> PUBLISH = new RedisCommand<Long>("PUBLISH", 2);

@ -23,6 +23,16 @@ package org.redisson.core;
*/
public interface RObject extends RObjectAsync {
/**
* Transfer a object from a source Redis instance to a destination Redis instance
*
* @param host - destination host
* @param port - destination port
* @param database - destination database
* @return
*/
void migrate(String host, int port, int database);
/**
* Move object to another database
*
@ -47,9 +57,8 @@ public interface RObject extends RObjectAsync {
* Rename current object key to <code>newName</code>
*
* @param newName
* @return
*/
boolean rename(String newName);
void rename(String newName);
/**
* Rename current object key to <code>newName</code>

@ -26,7 +26,18 @@ import io.netty.util.concurrent.Future;
public interface RObjectAsync {
/**
* Move object to another database
* Transfer a object from a source Redis instance to a destination Redis instance
* in async mode
*
* @param host - destination host
* @param port - destination port
* @param database - destination database
* @return
*/
Future<Void> migrateAsync(String host, int port, int database);
/**
* Move object to another database in async mode
*
* @param database
* @return <code>true</code> if key was moved else <code>false</code>
@ -42,7 +53,7 @@ public interface RObjectAsync {
* @param newName
* @return
*/
Future<Boolean> renameAsync(String newName);
Future<Void> renameAsync(String newName);
/**
* Rename current object key to <code>newName</code>

@ -23,18 +23,18 @@ public class RedissonBucketTest extends BaseTest {
Assert.assertEquals("someValue", newBucket.get());
Assert.assertFalse(newBucket.renamenx("test2"));
}
@Test
public void testRename() {
RBucket<String> bucket = redisson.getBucket("test");
bucket.set("someValue");
Assert.assertTrue(bucket.rename("test1"));
bucket.rename("test1");
RBucket<String> oldBucket = redisson.getBucket("test");
Assert.assertNull(oldBucket.get());
RBucket<String> newBucket = redisson.getBucket("test1");
Assert.assertEquals("someValue", newBucket.get());
}
@Test
public void testSetGet() {
RBucket<String> bucket = redisson.getBucket("test");

Loading…
Cancel
Save