I’m trying to propagate the commands, locally it works perfectly using this code:
func (r *RedisReplicaInfo) Propagate(rawCommand string) {
fmt.Println("Propagating to replica: ", r.port)
fmt.Println("Command: ", rawCommand)
d, err := net.Dial("tcp", "localhost:"+r.port)
if err != nil {
fmt.Printf("Failed to connect to replica during the propagate to %s\n", r.port)
fmt.Println(err)
os.Exit(1)
}
d.Write([]byte(rawCommand))
}
But for some reason, when I run codecrafters test
or making a git push, it fails with:
remote: [replication-11] Reading RDB file...
remote: [replication-11] replica: Received bytes: "$88\r\nREDIS0011\xfa\tredis-ver\x057.2.0\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2m\b\xbce\xfa\bused-mem°\xc4\x10\x00\xfa\baof-base\xc0\x00\xff\xf0n;\xfe\xc0\xffZ\xa2"
remote: [replication-11] Received RDB file
remote: [replication-11] client: $ redis-cli SET foo 123
remote: [replication-11] client: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
remote: [your_program] Received: *3
remote: [your_program] $3
remote: [your_program] SET
remote: [your_program] $3
remote: [your_program] foo
remote: [your_program] $3
remote: [your_program] 123
remote: [your_program]
remote: [your_program] Command: [set foo 123 ]
remote: [your_program] Propagating to replica: 6380
remote: [your_program] Command: *3
remote: [your_program] $3
remote: [your_program] SET
remote: [your_program] $3
remote: [your_program] foo
remote: [your_program] $3
remote: [your_program] 123
remote: [your_program]
remote: [your_program] Failed to connect to replica during the propagate to 6380
remote: [your_program] dial tcp [::1]:6380: connect: connection refused
remote: [replication-11] Received: "" (no content received)
remote: [replication-11] ^ error
remote: [replication-11] Error: Expected start of a new RESP value (either +, -, :, $ or *)
remote: [replication-11] Test failed
remote: [replication-11] Terminating program
remote: [replication-11] Program terminated successfully
I tried with localhost, [::1], 127.0.0.1, but i only received the port during the handshake. Am I missing something?
thanks!