MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / handle

Method handle

IceFireDB-Redis-Proxy/proxy/handle.go:33–81  ·  view source on GitHub ↗
(conn bareneter.Conn)

Source from the content-addressed store, hash-verified

31)
32
33func (p *Proxy) handle(conn bareneter.Conn) {
34 defer func() {
35 _ = conn.Close()
36 }()
37 localConn := conn.NetConn()
38 localWriteHandle := RESPHandle.NewWriterHandle(localConn)
39 decoder := credis.NewDecoderSize(localConn, 1024)
40 for {
41 resp, err := decoder.Decode()
42 if err != nil {
43 /*if err.Error() != io.EOF.Error() && strings.Index(err.Error(), net.ErrClosed.Error()) == -1 {
44 logrus.Errorf("RESP fail:%v", err)
45 }*/
46 return
47 }
48
49 if resp.Type != credis.TypeArray {
50 _ = router.WriteError(localWriteHandle, fmt.Errorf(router.ErrUnknownCommand, "cmd"))
51 return
52 }
53
54 respCount := len(resp.Array)
55
56 if respCount < 1 {
57 _ = router.WriteError(localWriteHandle, fmt.Errorf(router.ErrArguments, "cmd"))
58 return
59 }
60
61 if resp.Array[0].Type != credis.TypeBulkBytes {
62 _ = router.WriteError(localWriteHandle, router.ErrCmdTypeWrong)
63 return
64 }
65
66 commandArgs := make([]interface{}, respCount)
67 for i := 0; i < respCount; i++ {
68 commandArgs[i] = resp.Array[i].Value
69 }
70 err = p.router.Handle(localWriteHandle, commandArgs)
71
72 if err != nil {
73 if errors.Is(err, router.ErrLocalWriter) || errors.Is(err, router.ErrLocalFlush) {
74 return
75 }
76 _ = router.WriteError(localWriteHandle, err)
77 logrus.Errorf("resp command exec fail:%s , %v", commandArgs, err)
78 return
79 }
80 }
81}

Callers

nothing calls this directly

Calls 4

WriteErrorFunction · 0.92
CloseMethod · 0.65
HandleMethod · 0.65
DecodeMethod · 0.45

Tested by

no test coverage detected