模拟redis-server

  • Post author:
  • Post category:其他

    @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  字符串3S E T

$1  字符串1个
a

$3  字符串31 1 1

版权声明:本文为sinat_40735973原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。