Here's a demo impelmentation with python/sqlite, which allows for multiple types of events (e.g. based on remote IP): https://github.com/sivann/simpleban. As it uses a DB index complexity should be O(LogN).