Authored by jie

commit

  1 +target/
  2 +.idea/
  3 +jedis.iml
@@ -105,7 +105,7 @@ public class Connection implements Closeable { @@ -105,7 +105,7 @@ public class Connection implements Closeable {
105 } 105 }
106 106
107 107
108 - public Operation sendNioCommand(final Command cmd, final byte[]... args) throws IOException { 108 + public Connection sendNioCommand(final Command cmd, final byte[]... args) throws IOException {
109 109
110 //连接 110 //连接
111 nioConnect(); 111 nioConnect();
@@ -123,7 +123,7 @@ public class Connection implements Closeable { @@ -123,7 +123,7 @@ public class Connection implements Closeable {
123 tcpComponent.notifyWrite(channel, this); 123 tcpComponent.notifyWrite(channel, this);
124 } 124 }
125 125
126 - return operation; 126 + return this;
127 } 127 }
128 128
129 //循环去写 129 //循环去写
@@ -262,7 +262,7 @@ public class Connection implements Closeable { @@ -262,7 +262,7 @@ public class Connection implements Closeable {
262 } 262 }
263 } 263 }
264 264
265 - protected Operation sendCommand(final Command cmd, final String... args) { 265 + protected Connection sendCommand(final Command cmd, final String... args) {
266 final byte[][] bargs = new byte[args.length][]; 266 final byte[][] bargs = new byte[args.length][];
267 for (int i = 0; i < args.length; i++) { 267 for (int i = 0; i < args.length; i++) {
268 bargs[i] = SafeEncoder.encode(args[i]); 268 bargs[i] = SafeEncoder.encode(args[i]);
@@ -270,11 +270,11 @@ public class Connection implements Closeable { @@ -270,11 +270,11 @@ public class Connection implements Closeable {
270 return sendCommand(cmd, bargs); 270 return sendCommand(cmd, bargs);
271 } 271 }
272 272
273 - protected Operation sendCommand(final Command cmd) { 273 + protected Connection sendCommand(final Command cmd) {
274 return sendCommand(cmd, EMPTY_ARGS); 274 return sendCommand(cmd, EMPTY_ARGS);
275 } 275 }
276 276
277 - protected Operation sendCommand(final Command cmd, final byte[]... args) { 277 + protected Connection sendCommand(final Command cmd, final byte[]... args) {
278 try { 278 try {
279 /*connect(); 279 /*connect();
280 Protocol.sendCommand(outputStream, cmd, args);*/ 280 Protocol.sendCommand(outputStream, cmd, args);*/
1 -import org.junit.Test;  
2 -import redis.clients.jedis.Connection;  
3 -import redis.clients.jedis.Protocol;  
4 -import redis.clients.jedis.nio.Operation;  
5 -  
6 -import java.io.IOException;  
7 -import java.io.UnsupportedEncodingException;  
8 -import java.util.List;  
9 -import java.util.concurrent.ExecutionException;  
10 -  
11 -/**  
12 - * 描述:  
13 - * Created by pangjie@yoho.cn on 2017/11/9.  
14 - */  
15 -public class ConnectionNioTest {  
16 -  
17 - @Test  
18 - public void test1() throws IOException, ExecutionException, InterruptedException {  
19 -  
20 - Connection connection = new Connection("192.168.157.128", 8000);  
21 - Connection connection2 = new Connection("192.168.157.128", 8001);  
22 -  
23 - Operation operation1 = connection.sendNioCommand(Protocol.Command.SET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));  
24 - Operation operation12 = connection2.sendNioCommand(Protocol.Command.SET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));  
25 -  
26 -// connection2.sendNioCommand(Protocol.Command.SET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));  
27 - long s1 = System.nanoTime();  
28 - Operation operation2 = connection.sendNioCommand(Protocol.Command.GET, "myKey2".getBytes("UTF-8"), "myKey2".getBytes("UTF-8"));  
29 - Operation operation3 = connection.sendNioCommand(Protocol.Command.INCR, "myKey3".getBytes("UTF-8"));  
30 - Operation operation22 = connection2.sendNioCommand(Protocol.Command.GET, "myKey3".getBytes("UTF-8"));  
31 - Operation operation23 = connection2.sendNioCommand(Protocol.Command.GET, "myKey3".getBytes("UTF-8"));  
32 -  
33 -// connection2.sendNioCommand(Protocol.Command.GET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));  
34 - long s2 = System.nanoTime();  
35 - System.out.println(s2 - s1);  
36 -  
37 - System.out.println("result:" + new String((byte[]) operation1.getOperationFuture().get()));  
38 - System.out.println("result:" + operation3.getOperationFuture().get());  
39 - System.out.println("result:" + operation23.getOperationFuture().get());  
40 - System.out.println("result:" + operation22.getOperationFuture().get());  
41 - operation2.getOperationFuture().get();  
42 -  
43 - System.out.println(s2 - s1);  
44 - try {  
45 - Thread.sleep(1000);  
46 - } catch (InterruptedException e) {  
47 - e.printStackTrace();  
48 - }  
49 - }  
50 -  
51 -  
52 - @Test  
53 - public void MutiGet() throws IOException, ExecutionException, InterruptedException {  
54 - Connection connection = new Connection("192.168.157.128", 8000);  
55 -  
56 - Operation operation1 = connection.sendNioCommand(Protocol.Command.MGET, "myKey".getBytes("UTF-8"), "myKey".getBytes("UTF-8"));  
57 -  
58 - List list = (List) operation1.getOperationFuture().get();  
59 - for (Object o : list) {  
60 - System.out.println(new String( (byte[]) o));  
61 - }  
62 - }  
63 -}