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

fix:Using localhost as the IP address in slaveof will result in an error state. #2170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void SlaveofCmd::DoInitial() {
return;
}

if ((master_ip_ == "127.0.0.1" || master_ip_ == g_pika_server->host()) && master_port_ == g_pika_server->port()) {
if ((pstd::StringToLower(master_ip_) == "localhost" || master_ip_ == "127.0.0.1" || master_ip_ == g_pika_server->host()) && master_port_ == g_pika_server->port()) {
res_.SetRes(CmdRes::kErrOther, "The master ip:port and the slave ip:port are the same");
return;
}
Expand Down
21 changes: 11 additions & 10 deletions tests/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,17 @@ var _ = Describe("Server", func() {
// }, "10s").Should(Equal("OK"))
//})

// todo 待回滚
//It("should SlaveOf", func() {
// slaveOf := client.SlaveOf(ctx, "localhost", "8888")
// Expect(slaveOf.Err()).NotTo(HaveOccurred())
// Expect(slaveOf.Val()).To(Equal("OK"))
//
// slaveOf = client.SlaveOf(ctx, "NO", "ONE")
// Expect(slaveOf.Err()).NotTo(HaveOccurred())
// Expect(slaveOf.Val()).To(Equal("OK"))
//})
// fix: https://github.com/OpenAtomFoundation/pika/issues/2168
It("should SlaveOf itself", func() {
slaveOf := client.SlaveOf(ctx, "127.0.0.1", "9221")
Expect(slaveOf.Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))

slaveOf = client.SlaveOf(ctx, "localhost", "9221")
Expect(slaveOf.Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))

slaveOf = client.SlaveOf(ctx, "loCalHoSt", "9221")
Expect(slaveOf.Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))
})

It("should Time", func() {
tm, err := client.Time(ctx).Result()
Expand Down
Loading