RESP协议
支持tcp协议、基本数据类型,比如数组,字符串等,也可支持其他的通信场景。
模拟redis接收传输过来的set数据
//ServerSocket监听6379端口模拟redis public static void jasonWriteSocketServer() { ServerSocket serverSocket = null; Socket socket = null; InputStream inputStream = null; try { serverSocket = new ServerSocket(6379); socket = serverSocket.accept(); inputStream = socket.getInputStream(); byte[] b = new byte[64]; inputStream.read(b); System.out.println("jasonWriteSocketServer receive msg: "+new String(b)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { try { serverSocket.close(); socket.close(); inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
//正常的setString public static void setString() { Jedis jedis = new Jedis(); System.out.println("redis is connect success!"); jedis.set("name", "james"); System.out.println("address is setting success!"); jedis.close(); }
测试结果
jasonWriteSocketServer recieve msg: *3$3SET$4name$5james