added PDELHOOKS

This commit is contained in:
Josh Baker 2016-09-11 19:20:53 -07:00
parent a0872036d4
commit 89cfedeb08
4 changed files with 62 additions and 1 deletions

View File

@ -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":

View File

@ -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:]

View File

@ -1120,5 +1120,15 @@
}
],
"group": "webhook"
},
"PDELHOOK": {
"summary": "Removes all hooks matching a pattern",
"arguments":[
{
"name": "pattern",
"type": "pattern"
}
],
"group": "webhook"
}
}

View File

@ -1282,5 +1282,15 @@ var commandsJSON = `{
}
],
"group": "webhook"
},
"PDELHOOK": {
"summary": "Removes all hooks matching a pattern",
"arguments":[
{
"name": "pattern",
"type": "pattern"
}
],
"group": "webhook"
}
}`