-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathcmd_object.go
More file actions
50 lines (41 loc) · 962 Bytes
/
cmd_object.go
File metadata and controls
50 lines (41 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package miniredis
import (
"fmt"
"strings"
"github.com/alicebob/miniredis/v2/server"
)
// commandsObject handles all object operations.
func commandsObject(m *Miniredis) {
m.srv.Register("OBJECT", m.cmdObject)
}
// OBJECT
func (m *Miniredis) cmdObject(c *server.Peer, cmd string, args []string) {
if !m.isValidCMD(c, cmd, args, atLeast(1)) {
return
}
switch sub := strings.ToLower(args[0]); sub {
case "idletime":
m.cmdObjectIdletime(c, args[1:])
default:
setDirty(c)
c.WriteError(fmt.Sprintf(msgFObjectUsage, sub))
}
}
// OBJECT IDLETIME
func (m *Miniredis) cmdObjectIdletime(c *server.Peer, args []string) {
if len(args) != 1 {
setDirty(c)
c.WriteError(errWrongNumber("object|idletime"))
return
}
key := args[0]
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
t, ok := db.lru[key]
if !ok {
c.WriteNull()
return
}
c.WriteInt(int(db.master.effectiveNow().Sub(t).Seconds()))
})
}