func findKeys(t *telnet.Conn, slabs map[string]int64, prefix string) []string { var keys []string r, err := regexp.Compile(`ITEM (.+?) \[(\d+) b; (\d+) s\]`) checkErr(err) for k, v := range slabs { sendln(t, "stats cachedump "+k+" "+strconv.FormatInt(v, 10)) line, e := t.ReadString('\n') checkErr(e) for !strings.HasPrefix(line, "END") { // log.Printf("Got item line: %s", line) if r.MatchString(line) == true { m := r.FindStringSubmatch(line) key := m[1] if len(prefix) == 0 || (len(prefix) > 0 && strings.HasPrefix(key, prefix)) { keys = append(keys, key) } } line, e = t.ReadString('\n') checkErr(e) } } return keys }
func getSlabs(t *telnet.Conn) map[string]int64 { var line string slabs := make(map[string]int64) r, err := regexp.Compile(`STAT items:(\d+):number (\d+)`) // slab id & slab items checkErr(err) sendln(t, "stats items") line, e := t.ReadString('\n') checkErr(e) for !strings.HasPrefix(line, "END") { // log.Printf("Got slab line: %s", line) if r.MatchString(line) == true { m := r.FindStringSubmatch(line) i, e1 := strconv.ParseInt(m[2], 10, 64) checkErr(e1) slabs[m[1]] = i } line, e = t.ReadString('\n') checkErr(e) } return slabs }