|
|
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));
|
|
|
}
|
|
|
}
|
|
|
} |