MCPcopy
hub / github.com/bradfitz/gomemcache / handleRequestLine

Method handleRequestLine

memcache/fakeserver_test.go:96–278  ·  view source on GitHub ↗
(line string)

Source from the content-addressed store, hash-verified

94)
95
96func (c *testConn) handleRequestLine(line string) bool {
97 c.s.mu.Lock()
98 defer c.s.mu.Unlock()
99
100 switch line {
101 case "quit\r\n":
102 return false
103 case "version\r\n":
104 return c.reply("VERSION go-client-unit-test")
105 case "flush_all\r\n":
106 c.s.m = make(map[string]serverItem)
107 return c.reply("OK")
108 }
109
110 if strings.HasPrefix(line, "gets ") {
111 keys := strings.Fields(strings.TrimPrefix(line, "gets "))
112 for _, key := range keys {
113 item, ok := c.s.m[key]
114 if !ok {
115 continue
116 }
117 if !item.exp.IsZero() && item.exp.Before(time.Now()) {
118 delete(c.s.m, key)
119 continue
120 }
121 fmt.Fprintf(c.bw, "VALUE %s %d %d %d\r\n", key, item.flags, len(item.data), item.casUniq)
122 c.bw.Write(item.data)
123 c.bw.Write(crlf)
124 }
125 return c.reply("END")
126 }
127
128 if m := deleteRx.FindStringSubmatch(line); m != nil {
129 key, noReply := m[1], strings.TrimSpace(m[2])
130 len0 := len(c.s.m)
131 delete(c.s.m, key)
132 len1 := len(c.s.m)
133 if noReply == "" {
134 if len0 == len1 {
135 return c.reply("NOT_FOUND")
136 }
137 return c.reply("DELETED")
138 }
139 return true
140 }
141
142 if m := touchRx.FindStringSubmatch(line); m != nil {
143 key, exptimeStr, noReply := m[1], m[2], strings.TrimSpace(m[3])
144 exptimeVal, _ := strconv.ParseInt(exptimeStr, 10, 64)
145
146 item, ok := c.s.m[key]
147 if ok {
148 item.exp = computeExpTime(exptimeVal)
149 c.s.m[key] = item
150 }
151 if noReply == "" {
152 if ok {
153 return c.reply("TOUCHED")

Callers 1

serveMethod · 0.95

Calls 2

replyMethod · 0.95
computeExpTimeFunction · 0.85

Tested by

no test coverage detected