ConnectionNioTest.java
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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));
}
}
}