Skip to content

Commit

Permalink
Needed to add a raw delet handler for analytics purges
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelycode committed Mar 20, 2015
1 parent 825ef4f commit e298cac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (m *MongoPurger) PurgeCache() {
log.Error("Problem inserting to mongo collection")
log.Error(err)
} else {
m.Store.DeleteKeys(keyNames)
m.Store.DeleteRawKeys(keyNames, "analytics-")
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions storage_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ func (r *RedisStorageManager) DeleteKeys(keys []string) bool {
for i, v := range keys {
asInterface[i] = interface{}(r.fixKey(v))
}

log.Info("Deleting: ", asInterface)
_, err := db.Do("DEL", asInterface...)
if err != nil {
log.Error("Error trying to delete keys:")
Expand All @@ -440,3 +442,32 @@ func (r *RedisStorageManager) DeleteKeys(keys []string) bool {

return true
}

// DeleteKeys will remove a group of keys in bulk without a prefix handler
func (r *RedisStorageManager) DeleteRawKeys(keys []string, prefix string) bool {
db := r.pool.Get()
defer db.Close()
if db == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.DeleteKeys(keys)
}

if len(keys) > 0 {
asInterface := make([]interface{}, len(keys))
for i, v := range keys {
asInterface[i] = interface{}(prefix + v)
}

log.Info("Deleting: ", asInterface)
_, err := db.Do("DEL", asInterface...)
if err != nil {
log.Error("Error trying to delete keys:")
log.Error(err)
}
} else {
log.Debug("RedisStorageManager called DEL - Nothing to delete")
}

return true
}

0 comments on commit e298cac

Please sign in to comment.