Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下: 输入命令时和真正redis的区别 #6

Closed
yuanshuli11 opened this issue Jan 26, 2021 · 2 comments
Closed

请教一下: 输入命令时和真正redis的区别 #6

yuanshuli11 opened this issue Jan 26, 2021 · 2 comments

Comments

@yuanshuli11
Copy link

yuanshuli11 commented Jan 26, 2021

用telnet连接真正的reids时 直接输入 ping 就会返回+pong
但是我按照您的第二章(Golang 实现 Redis(2): 实现 Redis 协议解析器)
实现的demo中
必须用先输入一个 *1 回车

`
➜ src telnet 127.0.0.1 8000

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
*1
ping
+PONG
`

连接真实的redis服务:
`
Trying 127.0.0.1...

Connected to localhost.
Escape character is '^]'.
ping
+PONG
`

请问产生这个区别的原因是 redis用的空格来截取cmd 而您的例子是用的\n 吗?
为什么您的例子不也使用空格呢?

@yuanshuli11
Copy link
Author

yuanshuli11 commented Jan 26, 2021

和这一段 必须先取一下 * 开头的变量也有关系 但真正的redis 并不需要先输入* 。应该是这点区别吧
`
if !client.sending.Get() {
if msg[0] == '*' {
expectedLine, err := strconv.ParseUint(string(msg[1:len(msg)-2]), 10, 32)
if err != nil {
client.conn.Write([]byte("=====UnknownErrReplyBytes" + err.Error()))
continue
}
client.waitingReply.Add(1)
client.sending.Set(true)
client.expectedArgsCount = uint32(expectedLine)
client.receivedCount = 0
client.args = make([][]byte, expectedLine)
} else {
//TODO text protocol
}
}

`

@yuanshuli11
Copy link
Author

哦哦 我理解错了。后面有解决的方式~~~ 打扰了 大神

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant