代码拉取完成,页面将自动刷新
// Commands from https://redis.io/commands#server
package miniredis
import (
"strconv"
"strings"
"time"
"github.com/alicebob/miniredis/server"
)
func commandsServer(m *Miniredis) {
m.srv.Register("DBSIZE", m.cmdDbsize)
m.srv.Register("FLUSHALL", m.cmdFlushall)
m.srv.Register("FLUSHDB", m.cmdFlushdb)
m.srv.Register("TIME", m.cmdTime)
}
// DBSIZE
func (m *Miniredis) cmdDbsize(c *server.Peer, cmd string, args []string) {
if len(args) > 0 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
c.WriteInt(len(db.keys))
})
}
// FLUSHALL
func (m *Miniredis) cmdFlushall(c *server.Peer, cmd string, args []string) {
if len(args) > 0 && strings.ToLower(args[0]) == "async" {
args = args[1:]
}
if len(args) > 0 {
setDirty(c)
c.WriteError(msgSyntaxError)
return
}
if !m.handleAuth(c) {
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
m.flushAll()
c.WriteOK()
})
}
// FLUSHDB
func (m *Miniredis) cmdFlushdb(c *server.Peer, cmd string, args []string) {
if len(args) > 0 && strings.ToLower(args[0]) == "async" {
args = args[1:]
}
if len(args) > 0 {
setDirty(c)
c.WriteError(msgSyntaxError)
return
}
if !m.handleAuth(c) {
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
m.db(ctx.selectedDB).flush()
c.WriteOK()
})
}
// TIME: time values are returned in string format instead of int
func (m *Miniredis) cmdTime(c *server.Peer, cmd string, args []string) {
if len(args) > 0 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
}
if !m.handleAuth(c) {
return
}
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
now := m.now
if now.IsZero() {
now = time.Now()
}
nanos := now.UnixNano()
seconds := nanos / 1000000000
microseconds := (nanos / 1000) % 1000000
c.WriteLen(2)
c.WriteBulk(strconv.FormatInt(seconds, 10))
c.WriteBulk(strconv.FormatInt(microseconds, 10))
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。