Authored by jie

commit

target/
.idea/
jedis.iml
... ...
... ... @@ -105,7 +105,7 @@ public class Connection implements Closeable {
}
public Operation sendNioCommand(final Command cmd, final byte[]... args) throws IOException {
public Connection sendNioCommand(final Command cmd, final byte[]... args) throws IOException {
//连接
nioConnect();
... ... @@ -123,7 +123,7 @@ public class Connection implements Closeable {
tcpComponent.notifyWrite(channel, this);
}
return operation;
return this;
}
//循环去写
... ... @@ -262,7 +262,7 @@ public class Connection implements Closeable {
}
}
protected Operation sendCommand(final Command cmd, final String... args) {
protected Connection sendCommand(final Command cmd, final String... args) {
final byte[][] bargs = new byte[args.length][];
for (int i = 0; i < args.length; i++) {
bargs[i] = SafeEncoder.encode(args[i]);
... ... @@ -270,11 +270,11 @@ public class Connection implements Closeable {
return sendCommand(cmd, bargs);
}
protected Operation sendCommand(final Command cmd) {
protected Connection sendCommand(final Command cmd) {
return sendCommand(cmd, EMPTY_ARGS);
}
protected Operation sendCommand(final Command cmd, final byte[]... args) {
protected Connection sendCommand(final Command cmd, final byte[]... args) {
try {
/*connect();
Protocol.sendCommand(outputStream, cmd, args);*/
... ...
import org.junit.Test;
import redis.clients.jedis.Connection;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.nio.Operation;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* 描述:
* Created by pangjie@yoho.cn on 2017/11/9.
*/
public class ConnectionNioTest {
@Test
public void test1() throws IOException, ExecutionException, InterruptedException {
Connection connection = new Connection("192.168.157.128", 8000);
Connection connection2 = new Connection("192.168.157.128", 8001);
Operation operation1 = connection.sendNioCommand(Protocol.Command.SET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));
Operation operation12 = connection2.sendNioCommand(Protocol.Command.SET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));
// connection2.sendNioCommand(Protocol.Command.SET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));
long s1 = System.nanoTime();
Operation operation2 = connection.sendNioCommand(Protocol.Command.GET, "myKey2".getBytes("UTF-8"), "myKey2".getBytes("UTF-8"));
Operation operation3 = connection.sendNioCommand(Protocol.Command.INCR, "myKey3".getBytes("UTF-8"));
Operation operation22 = connection2.sendNioCommand(Protocol.Command.GET, "myKey3".getBytes("UTF-8"));
Operation operation23 = connection2.sendNioCommand(Protocol.Command.GET, "myKey3".getBytes("UTF-8"));
// connection2.sendNioCommand(Protocol.Command.GET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));
long s2 = System.nanoTime();
System.out.println(s2 - s1);
System.out.println("result:" + new String((byte[]) operation1.getOperationFuture().get()));
System.out.println("result:" + operation3.getOperationFuture().get());
System.out.println("result:" + operation23.getOperationFuture().get());
System.out.println("result:" + operation22.getOperationFuture().get());
operation2.getOperationFuture().get();
System.out.println(s2 - s1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Test
public void MutiGet() throws IOException, ExecutionException, InterruptedException {
Connection connection = new Connection("192.168.157.128", 8000);
Operation operation1 = connection.sendNioCommand(Protocol.Command.MGET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));
List list = (List) operation1.getOperationFuture().get();
for (Object o : list) {
System.out.println(new String( (byte[]) o));
}
}
}