mirror of https://github.com/tidwall/tile38.git
added PDELHOOKS
This commit is contained in:
parent
a0872036d4
commit
89cfedeb08
|
@ -389,7 +389,7 @@ func (c *Controller) handleInputCommand(conn *server.Conn, msg *server.Message,
|
|||
default:
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
case "set", "del", "drop", "fset", "flushdb", "sethook", "delhook", "expire", "persist":
|
||||
case "set", "del", "drop", "fset", "flushdb", "sethook", "pdelhook", "delhook", "expire", "persist":
|
||||
// write operations
|
||||
write = true
|
||||
c.mu.Lock()
|
||||
|
@ -479,6 +479,8 @@ func (c *Controller) command(msg *server.Message, w io.Writer) (res string, d co
|
|||
res, d, err = c.cmdSetHook(msg)
|
||||
case "delhook":
|
||||
res, d, err = c.cmdDelHook(msg)
|
||||
case "pdelhook":
|
||||
res, d, err = c.cmdPDelHook(msg)
|
||||
case "expire":
|
||||
res, d, err = c.cmdExpire(msg)
|
||||
case "persist":
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -196,6 +197,44 @@ func (c *Controller) cmdDelHook(msg *server.Message) (res string, d commandDetai
|
|||
return
|
||||
}
|
||||
|
||||
func (c *Controller) cmdPDelHook(msg *server.Message) (res string, d commandDetailsT, err error) {
|
||||
start := time.Now()
|
||||
vs := msg.Values[1:]
|
||||
|
||||
var pattern string
|
||||
var ok bool
|
||||
if vs, pattern, ok = tokenval(vs); !ok || pattern == "" {
|
||||
return "", d, errInvalidNumberOfArguments
|
||||
}
|
||||
if len(vs) != 0 {
|
||||
return "", d, errInvalidNumberOfArguments
|
||||
}
|
||||
|
||||
count := 0
|
||||
for name := range c.hooks {
|
||||
match, _ := glob.Match(pattern, name)
|
||||
if match {
|
||||
if h, ok := c.hooks[name]; ok {
|
||||
h.Close()
|
||||
if hm, ok := c.hookcols[h.Key]; ok {
|
||||
delete(hm, h.Name)
|
||||
}
|
||||
delete(c.hooks, h.Name)
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
d.timestamp = time.Now()
|
||||
|
||||
switch msg.OutputType {
|
||||
case server.JSON:
|
||||
return server.OKMessage(msg, start), d, nil
|
||||
case server.RESP:
|
||||
return ":" + strconv.FormatInt(int64(count), 10) + "\r\n", d, nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Controller) cmdHooks(msg *server.Message) (res string, err error) {
|
||||
start := time.Now()
|
||||
vs := msg.Values[1:]
|
||||
|
|
|
@ -1120,5 +1120,15 @@
|
|||
}
|
||||
],
|
||||
"group": "webhook"
|
||||
},
|
||||
"PDELHOOK": {
|
||||
"summary": "Removes all hooks matching a pattern",
|
||||
"arguments":[
|
||||
{
|
||||
"name": "pattern",
|
||||
"type": "pattern"
|
||||
}
|
||||
],
|
||||
"group": "webhook"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1282,5 +1282,15 @@ var commandsJSON = `{
|
|||
}
|
||||
],
|
||||
"group": "webhook"
|
||||
},
|
||||
"PDELHOOK": {
|
||||
"summary": "Removes all hooks matching a pattern",
|
||||
"arguments":[
|
||||
{
|
||||
"name": "pattern",
|
||||
"type": "pattern"
|
||||
}
|
||||
],
|
||||
"group": "webhook"
|
||||
}
|
||||
}`
|
||||
|
|
Loading…
Reference in New Issue