mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
| datasource | package | from | to | | ---------- | -------------------------------- | ------- | ------- | | go | github.com/alicebob/miniredis/v2 | v2.35.0 | v2.36.0 | Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com> Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package miniredis
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/alicebob/miniredis/v2/server"
|
|
)
|
|
|
|
const (
|
|
clientsSectionName = "clients"
|
|
clientsSectionContent = "# Clients\nconnected_clients:%d\r\n"
|
|
|
|
statsSectionName = "stats"
|
|
statsSectionContent = "# Stats\ntotal_connections_received:%d\r\ntotal_commands_processed:%d\r\n"
|
|
)
|
|
|
|
// Command 'INFO' from https://redis.io/commands/info/
|
|
func (m *Miniredis) cmdInfo(c *server.Peer, cmd string, args []string) {
|
|
if !m.isValidCMD(c, cmd, args, between(0, 1)) {
|
|
return
|
|
}
|
|
var result string
|
|
if len(args) == 0 {
|
|
result = fmt.Sprintf(clientsSectionContent, m.Server().ClientsLen()) + fmt.Sprintf(statsSectionContent, m.Server().TotalConnections(), m.Server().TotalCommands())
|
|
c.WriteBulk(result)
|
|
return
|
|
}
|
|
|
|
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
|
|
switch section := strings.ToLower(args[0]); section {
|
|
case clientsSectionName:
|
|
result = fmt.Sprintf(clientsSectionContent, m.Server().ClientsLen())
|
|
case statsSectionName:
|
|
result = fmt.Sprintf(statsSectionContent, m.Server().TotalConnections(), m.Server().TotalCommands())
|
|
default:
|
|
setDirty(c)
|
|
c.WriteError(fmt.Sprintf("section (%s) is not supported", section))
|
|
return
|
|
}
|
|
c.WriteBulk(result)
|
|
})
|
|
}
|