Redis原理

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
$3
SET
$4
name
$5
james
上一篇:C# ICSharpCode.SharpZipLib.Zip 的使用


下一篇:C# 下利用ICSharpCode.SharpZipLib.dll实现文件/目录压缩、解压缩