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

Method ReadMapLen

internal/proto/reader.go:698–719  ·  view source on GitHub ↗

ReadMapLen reads the length of the map type. If responding to the array type (RespArray/RespSet/RespPush), it must be a multiple of 2 and return n/2. Other types will return an error.

()

Source from the content-addressed store, hash-verified

696// it must be a multiple of 2 and return n/2.
697// Other types will return an error.
698func (r *Reader) ReadMapLen() (int, error) {
699 line, err := r.ReadLine()
700 if err != nil {
701 return 0, err
702 }
703 switch line[0] {
704 case RespMap:
705 return replyLen(line)
706 case RespArray, RespSet, RespPush:
707 // Some commands and RESP2 protocol may respond to array types.
708 n, err := replyLen(line)
709 if err != nil {
710 return 0, err
711 }
712 if n%2 != 0 {
713 return 0, fmt.Errorf("redis: the length of the array must be a multiple of 2, got: %d", n)
714 }
715 return n / 2, nil
716 default:
717 return 0, fmt.Errorf("redis: can't parse map reply: %.100q", line)
718 }
719}
720
721// DiscardNext read and discard the data represented by the next line.
722func (r *Reader) DiscardNext() error {

Callers 15

ReadFixedMapLenMethod · 0.95
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80
readReplyMethod · 0.80

Calls 2

ReadLineMethod · 0.95
replyLenFunction · 0.85

Tested by

no test coverage detected