MCPcopy
hub / github.com/redis/go-redis / handle

Method handle

internal_maint_notif_test.go:502–545  ·  view source on GitHub ↗
(c net.Conn)

Source from the content-addressed store, hash-verified

500}
501
502func (s *mockMaintNotificationsDowngradeServer) handle(c net.Conn) {
503 defer c.Close()
504 r := bufio.NewReader(c)
505 for {
506 args, err := readRESPCommand(r)
507 if err != nil {
508 return
509 }
510 if len(args) == 0 {
511 continue
512 }
513 name := strings.ToUpper(args[0])
514 full := name
515 if len(args) > 1 {
516 full = name + " " + strings.ToUpper(args[1])
517 }
518
519 switch {
520 case name == "HELLO":
521 s.record(full)
522 _, _ = c.Write([]byte("%1\r\n+proto\r\n:3\r\n"))
523 case full == maintNotificationsCommand:
524 if call := s.record(full); call == 1 {
525 _, _ = c.Write([]byte("+OK\r\n"))
526 } else {
527 _, _ = c.Write([]byte("-ERR unknown subcommand 'MAINT_NOTIFICATIONS'\r\n"))
528 }
529 case name == "PING":
530 s.record(full)
531 shouldBlock := false
532 s.blockFirstPing.Do(func() {
533 shouldBlock = true
534 close(s.firstPingBlocked)
535 })
536 if shouldBlock {
537 <-s.releaseFirstPing
538 }
539 _, _ = c.Write([]byte("+PONG\r\n"))
540 default:
541 s.record(full)
542 _, _ = c.Write([]byte("+OK\r\n"))
543 }
544 }
545}
546
547func startMockMaintNotificationsDowngradeServer(t *testing.T) *mockMaintNotificationsDowngradeServer {
548 t.Helper()

Calls 5

recordMethod · 0.95
readRESPCommandFunction · 0.85
CloseMethod · 0.65
DoMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected