mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-16 04:29:15 +00:00
Add redis support for distributed caching
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
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 len(args) == 0 {
|
||||
setDirty(c)
|
||||
c.WriteError(errWrongNumber(cmd))
|
||||
return
|
||||
}
|
||||
if !m.handleAuth(c) {
|
||||
return
|
||||
}
|
||||
if m.checkPubsub(c, cmd) {
|
||||
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()))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user