public class RenameCmd extends CmdBase implements Cmd<Boolean>
An Usage Example:
Supposing you want to rename a key(the name is "key") to another key "newkey", you could write this as:
package com.example;
import ax.antpick.k2hdkc.*;
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import java.io.IOException;
import java.util.*;
import java.util.stream.*;
public class App {
public static void main(String[] args) {
try (Cluster c = Cluster.of("cluster/slave.yaml");
Session s = Session.of(c); ) {
SetCmd set = SetCmd.of("key", "value");
assert ((Boolean) set.execute(s).get().getValue() == true);
RenameCmd rm = RenameCmd.of("key", "newkey");
assert ((Boolean) rm.execute(s).get().getValue() == true);
GetCmd get = GetCmd.of("newkey");
String str = (String) get.execute(s).get().getValue();
System.out.println(str);
} catch (IOException ex) {
System.out.println(ex.getMessage());
assert (false);
}
}
}
You shoule see the "true" message on the stdout if you could successfully run it. Before running the code above, You should run three processes.
The following commands in this repository will run all processes you need in localhost.
$ cd cluster
$ sh start_server.sh
Cmd.DataType
DEFAULT_CHECK_PARENT_ATTRS, DEFAULT_EXPIRATION_DURATION, DEFAULT_IS_CHECK_PARENT_ATTRS, DEFAULT_IS_CLEAR_SUBKEYS, DEFAULT_IS_FIFO, DEFAULT_IS_INCREMENT, DEFAULT_NEED_RETURN_VALUE, DEFAULT_PARENT_KEY, DEFAULT_PASS, DEFAULT_REMOVE_ELEMENT_SIZE, DEFAULT_REMOVE_RECURSIVELY, DEFAULT_SUBKEYS
Modifier and Type | Method and Description |
---|---|
<T> Optional<Result<T>> |
execute(Session session)
Rename a old key with a new key.
|
static RenameCmd |
of(String key,
String newKey)
Constructs a RenameCmd instance.
|
static RenameCmd |
of(String key,
String newKey,
String parentKey,
boolean checkParentAttrs,
String password,
long expirationDuration)
Constructs a RenameCmd instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bytesToInt, getValusAsInt
public static RenameCmd of(String key, String newKey)
key
- a key stringnewKey
- a new key stringIllegalArgumentException
- if a key or a val string is null or emptypublic static RenameCmd of(String key, String newKey, String parentKey, boolean checkParentAttrs, String password, long expirationDuration)
key
- a key stringnewKey
- a newKey stringparentKey
- a parentKey stringcheckParentAttrs
- true
if checking parent attributes before changing a
subkeys. false
otherwise.password
- a password stringexpirationDuration
- a duration to expire.IllegalArgumentException
- if a key or a val string is null or emptypublic <T> Optional<Result<T>> execute(Session session) throws IOException
execute
in interface Cmd<Boolean>
session
- a session instanceIllegalArgumentException
- if an illegal augment existsIOException
- if underlying library errors occur.Copyright © 2020. All rights reserved.