redis-rb / redis-client

Simple low level client for Redis 6+
MIT License
125 stars 60 forks source link

Add Instance level middlewares #53

Closed casperisfine closed 2 years ago

casperisfine commented 2 years ago

Fix: https://github.com/redis-rb/redis-client/pull/52

There are some use case for middlewares that only applies to a specific connection.

You could implement key namespacing as a middleware for instance, or use it to ban some commands etc, without impacting libraries that use redis-client too.

This can also be used to implement the Semian adapter as a middleware without any monkey patch.

I re-recorded the benchmark, and with this implementation there's no measurable perf impact.

The one downside of this implementation is that it makes it a bit harder for a middleware to be instantiated with some kind of configuration parameters, but it's not impossible at all.

Co-Authored-By: @gremerritt

gremerritt commented 2 years ago

Thanks for working on this 🙌

casperisfine commented 2 years ago

Ok, I found a few more uses cases for this, so I think it's valuable.