@Test
void fakeRedis() throws IOException {
ServerSocket serverSocket = new ServerSocket(6379);
Socket accept = serverSocket.accept();
byte[] bytes = new byte[1024];
accept.getInputStream().read(bytes);
System.out.println(new String(bytes));
}
@Test
void testJedis(){
Jedis jedis = new Jedis("localhost",6379);
// jedis.auth("2273");
System.out.println(jedis.set("a", "111"));
System.out.println(jedis.get("a"));
}
结果:
*3
$3
SET
$1
a
$3
111
RESP (REdis Serialization Protocol)redis序列化协议
For Simple Strings the first byte of the reply is “+”
For Errors the first byte of the reply is “-”
For Integers the first byte of the reply is “:”
For Bulk Strings the first byte of the reply is “
”
F
o
r
A
r
r
a
y
s
t
h
e
f
i
r
s
t
b
y
t
e
o
f
t
h
e
r
e
p
l
y
i
s
”
∗
”
对
于
简
单
字
符
串
,
回
复
的
第
一
个
字
节
是
“
+
”
对
于
错
误
,
回
复
的
第
一
个
字
节
是
“
−
”
对
于
整
数
,
回
复
的
第
一
个
字
节
是
“
:
”
对
于
大
容
量
字
符
串
,
回
复
的
第
一
个
字
节
为
”
” For Arrays the first byte of the reply is “*” 对于简单字符串,回复的第一个字节是“+” 对于错误,回复的第一个字节是“-” 对于整数,回复的第一个字节是“:” 对于大容量字符串,回复的第一个字节为”
“ForArraysthefirstbyteofthereplyis“∗“对于简单字符串,回复的第一个字节是“+”对于错误,回复的第一个字节是“−”对于整数,回复的第一个字节是“:”对于大容量字符串,回复的第一个字节为“”
对于数组,回复的第一个字节是”*”
*3 数组3个
$3 字符串3个
S E T
$1 字符串1个
a
$3 字符串3个
1 1 1