标准文档:https://redis.io/topics/protocol
客户端一组参数组成的指令,服务端接受后,处理并返回结果。
支持流水线式操作:客户端发送多个指令,统一处理完毕后返回结果
支持订阅/发布模式,当客户端订阅时,服务端会在客户端push后自动返回消息。(不是很懂。。。)
支持数据类型:Simple Strings, Errors, Integers, Bulk Strings and Arrays
.
请求-响应处理过程:
客户端发送指令,指令用字符串形式的RESP数组(RESP Array of Bulk Strings)表示。
服务端根据指令执行结果,返回处理结果RESP类型。
In RESP, the type of some data depends on the first byte:
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 "$"
For Arrays the first byte of the reply is "*"
In RESP different parts of the protocol are always terminated with "\r\n" (CRLF).
协议中使用CRLF来区分各个部分。协议形如:
*<参数数量> CR LF
$<参数 1 的字节数量> CR LF
<参数 1 的数据> CR LF
...
$<参数 N 的字节数量> CR LF
<参数 N 的数据> CR LF
表示返回成功
"+OK\r\n"
表示返回错误
"-Error message\r\n"
For example ":0\r\n", or ":1000\r\n" are integer replies.
返回int的指令: SETNX, DEL, EXISTS, INCR, INCRBY, DECR, DECRBY, DBSIZE, LASTSAVE, RENAMENX, MOVE, LLEN, SADD, SREM, SISMEMBER, SCARD.
"$6\r\nfoobar\r\n"
最大为512M,结构如下:
其中"$-1\r\n"表示空。
*5\r\n
:1\r\n
:2\r\n
:3\r\n
:4\r\n
$6\r\n
foobar\r\n
结构如下:
用于表示空元素
$-1\r\n
原文:https://www.cnblogs.com/omg-two/p/12558282.html