parent
a08c55bf2c
commit
5642fc42cc
@ -412,6 +412,15 @@ func (s *Server) cmdPDEL(msg *Message) (resp.Value, commandDetails, error) {
|
|||||||
return res, d, nil
|
return res, d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) cmdDROPop(key string) *collection.Collection {
|
||||||
|
col, _ := s.cols.Get(key)
|
||||||
|
if col != nil {
|
||||||
|
s.cols.Delete(key)
|
||||||
|
}
|
||||||
|
s.groupDisconnectCollection(key)
|
||||||
|
return col
|
||||||
|
}
|
||||||
|
|
||||||
// DROP key
|
// DROP key
|
||||||
func (s *Server) cmdDROP(msg *Message) (resp.Value, commandDetails, error) {
|
func (s *Server) cmdDROP(msg *Message) (resp.Value, commandDetails, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
@ -425,12 +434,7 @@ func (s *Server) cmdDROP(msg *Message) (resp.Value, commandDetails, error) {
|
|||||||
key := args[1]
|
key := args[1]
|
||||||
|
|
||||||
// >> Operation
|
// >> Operation
|
||||||
|
col := s.cmdDROPop(key)
|
||||||
col, _ := s.cols.Get(key)
|
|
||||||
if col != nil {
|
|
||||||
s.cols.Delete(key)
|
|
||||||
}
|
|
||||||
s.groupDisconnectCollection(key)
|
|
||||||
|
|
||||||
// >> Response
|
// >> Response
|
||||||
|
|
||||||
@ -542,6 +546,39 @@ func (s *Server) cmdFLUSHDB(msg *Message) (resp.Value, commandDetails, error) {
|
|||||||
// >> Operation
|
// >> Operation
|
||||||
|
|
||||||
// clear the entire database
|
// clear the entire database
|
||||||
|
|
||||||
|
// drop each collection
|
||||||
|
keys := s.cols.Keys()
|
||||||
|
for _, key := range keys {
|
||||||
|
s.cmdDROPop(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete all channels
|
||||||
|
var names []string
|
||||||
|
s.hooks.Ascend(nil, func(item any) bool {
|
||||||
|
hook := item.(*Hook)
|
||||||
|
if hook.channel {
|
||||||
|
names = append(names, hook.Name)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
for _, name := range names {
|
||||||
|
s.cmdDELHOOKop(name, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete all hooks
|
||||||
|
names = names[:0]
|
||||||
|
s.hooks.Ascend(nil, func(item any) bool {
|
||||||
|
hook := item.(*Hook)
|
||||||
|
if !hook.channel {
|
||||||
|
names = append(names, hook.Name)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
for _, name := range names {
|
||||||
|
s.cmdDELHOOKop(name, false)
|
||||||
|
}
|
||||||
|
|
||||||
s.cols.Clear()
|
s.cols.Clear()
|
||||||
s.groupHooks.Clear()
|
s.groupHooks.Clear()
|
||||||
s.groupObjects.Clear()
|
s.groupObjects.Clear()
|
||||||
|
@ -240,23 +240,11 @@ func byHookExpires(a, b interface{}) bool {
|
|||||||
return ha.Name < hb.Name
|
return ha.Name < hb.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) cmdDelHook(msg *Message) (
|
func (s *Server) cmdDELHOOKop(name string, channel bool) (updated bool) {
|
||||||
res resp.Value, d commandDetails, err error,
|
|
||||||
) {
|
|
||||||
channel := msg.Command() == "delchan"
|
|
||||||
start := time.Now()
|
|
||||||
vs := msg.Args[1:]
|
|
||||||
|
|
||||||
var name string
|
|
||||||
var ok bool
|
|
||||||
if vs, name, ok = tokenval(vs); !ok || name == "" {
|
|
||||||
return NOMessage, d, errInvalidNumberOfArguments
|
|
||||||
}
|
|
||||||
if len(vs) != 0 {
|
|
||||||
return NOMessage, d, errInvalidNumberOfArguments
|
|
||||||
}
|
|
||||||
hook, _ := s.hooks.Get(&Hook{Name: name}).(*Hook)
|
hook, _ := s.hooks.Get(&Hook{Name: name}).(*Hook)
|
||||||
if hook != nil && hook.channel == channel {
|
if hook == nil || hook.channel != channel {
|
||||||
|
return false
|
||||||
|
}
|
||||||
hook.Close()
|
hook.Close()
|
||||||
// remove hook from maps
|
// remove hook from maps
|
||||||
s.hooks.Delete(hook)
|
s.hooks.Delete(hook)
|
||||||
@ -280,8 +268,26 @@ func (s *Server) cmdDelHook(msg *Message) (
|
|||||||
hook)
|
hook)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.updated = true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) cmdDelHook(msg *Message) (
|
||||||
|
res resp.Value, d commandDetails, err error,
|
||||||
|
) {
|
||||||
|
channel := msg.Command() == "delchan"
|
||||||
|
start := time.Now()
|
||||||
|
vs := msg.Args[1:]
|
||||||
|
|
||||||
|
var name string
|
||||||
|
var ok bool
|
||||||
|
if vs, name, ok = tokenval(vs); !ok || name == "" {
|
||||||
|
return NOMessage, d, errInvalidNumberOfArguments
|
||||||
}
|
}
|
||||||
|
if len(vs) != 0 {
|
||||||
|
return NOMessage, d, errInvalidNumberOfArguments
|
||||||
|
}
|
||||||
|
|
||||||
|
d.updated = s.cmdDELHOOKop(name, channel)
|
||||||
d.timestamp = time.Now()
|
d.timestamp = time.Now()
|
||||||
|
|
||||||
switch msg.OutputType {
|
switch msg.OutputType {
|
||||||
@ -323,29 +329,7 @@ func (s *Server) cmdPDelHook(msg *Message) (
|
|||||||
if hook.channel != channel {
|
if hook.channel != channel {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hook.Close()
|
s.cmdDELHOOKop(hook.Name, channel)
|
||||||
// remove hook from maps
|
|
||||||
s.hooks.Delete(hook)
|
|
||||||
s.hooksOut.Delete(hook)
|
|
||||||
if !hook.expires.IsZero() {
|
|
||||||
s.hookExpires.Delete(hook)
|
|
||||||
}
|
|
||||||
// remove any hook / object connections
|
|
||||||
s.groupDisconnectHook(hook.Name)
|
|
||||||
// remove hook from spatial index
|
|
||||||
if hook.Fence != nil && hook.Fence.obj != nil {
|
|
||||||
rect := hook.Fence.obj.Rect()
|
|
||||||
s.hookTree.Delete(
|
|
||||||
[2]float64{rect.Min.X, rect.Min.Y},
|
|
||||||
[2]float64{rect.Max.X, rect.Max.Y},
|
|
||||||
hook)
|
|
||||||
if hook.Fence.detect["cross"] {
|
|
||||||
s.hookCross.Delete(
|
|
||||||
[2]float64{rect.Min.X, rect.Min.Y},
|
|
||||||
[2]float64{rect.Max.X, rect.Max.Y},
|
|
||||||
hook)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
d.updated = true
|
d.updated = true
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user