commandCalls returns the per-command call counts reported by INFO commandstats, keyed by command name (e.g. "unwatch").
(client *redis.Client)
| 64 | // commandCalls returns the per-command call counts reported by |
| 65 | // INFO commandstats, keyed by command name (e.g. "unwatch"). |
| 66 | func commandCalls(client *redis.Client) map[string]int64 { |
| 67 | info, err := client.Info(ctx, "commandstats").Result() |
| 68 | Expect(err).NotTo(HaveOccurred()) |
| 69 | |
| 70 | calls := make(map[string]int64) |
| 71 | for _, line := range strings.Split(info, "\n") { |
| 72 | line = strings.TrimSpace(line) |
| 73 | const prefix = "cmdstat_" |
| 74 | if !strings.HasPrefix(line, prefix) { |
| 75 | continue |
| 76 | } |
| 77 | name, rest, ok := strings.Cut(line[len(prefix):], ":") |
| 78 | if !ok { |
| 79 | continue |
| 80 | } |
| 81 | // rest looks like: calls=3,usec=10,usec_per_call=3.33,... |
| 82 | fields := strings.Split(rest, ",") |
| 83 | if len(fields) == 0 { |
| 84 | continue |
| 85 | } |
| 86 | kv := strings.SplitN(fields[0], "=", 2) |
| 87 | if len(kv) != 2 || kv[0] != "calls" { |
| 88 | continue |
| 89 | } |
| 90 | n, err := strconv.ParseInt(kv[1], 10, 64) |
| 91 | Expect(err).NotTo(HaveOccurred()) |
| 92 | calls[name] = n |
| 93 | } |
| 94 | return calls |
| 95 | } |
| 96 | |
| 97 | // pipelineErrInjector returns a fixed error for the MULTI/EXEC batch without |
| 98 | // executing it, simulating a server error reported before EXEC runs (such as |
no test coverage detected