深入Redis(十一)通信协议

通信协议

Redis单线程对外提供服务,单节点在跑满一个CPU核心的情况下,可以达到10w/s的超高QPS。

RESP(Redis Serialization Protocol)

Redis协议将传输的结构数据分为5种最小单元类型,单元结束时统一加上回车换行符号\r\n。

  1. 单行字符串,+开头;
  2. 多行字符串,$开头;
  3. 整数值,:开头;
  4. 错误消息,-开头;
  5. 数组,*开头,后接数组的长度。

单行字串'hello world'

+hello world\r\n

多行字串

$\r\nhello world\r\n

整数1024

:1024\r\n

错误

-WRONGTYPE Operation against a key holding the wrong kind of value\r\n

数组[1,2,3]

*3\r\n:1\r\n:2\r\n3\r\n

NULL,多行字串表示,长度-1

$-1\r\n

空行,多行字串表示,长度0

$0\r\n\r\n

小结

虽然协议中有大量冗余的回车换行符,但其显示比较友好。

猜你喜欢

转载自www.cnblogs.com/ikct2017/p/9503447.html
今日推荐