Skip to content

Validate keys when a raw connection is checked out with #with #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

KJTsanaktsidis
Copy link
Contributor

If a raw connection is obtained via #with, this commit causes that connection to in fact be wrapped in a delegator. The delegator will enforce that any keys used with the raw connection belong to the slot that the #with call was pinned to.


This is a replacement for #314 which takes your feedback into account:

  • There is a config option for whether or not slot validation is enabled
  • The validation is achieved through proxying, rather than subclassing

I do want to give a bit of insight into why I designed it this way, using SimpleDelegator and dynamically detecting which methods to respond to and such. IMO there are two kinds of simplicity we can have here - a simple implementation, which means the code in here is simple, or a simple interface, which means we present an API which does what people expect and is hard to misuse.

In my opinion, it's more important for the interface to be simple, than for the implementation to be simple. In this case, if we're proxying an object, a "simple, unsurprising interface" is that it has exactly the same methods which the underlying object has. That means not missing any methods which RedisClient has (SimpleDelegator takes care of that for us), and not adding any additional methods which e.g. RedisClient:Multi doesn't normally have (i.e. the check for define_singleton_method if respond_to?(method).

It makes the inside of the PinnedConnectionDelegator implementation a little more complex, but it makes it less surprising to use for callers, which I think is the most important thing.

If a raw connection is obtained via #with, this commit causes that
connection to in fact be wrapped in a delegator. The delegator will
enforce that any keys used with the raw connection belong to the slot
that the #with call was pinned to.
@supercaracal supercaracal self-requested a review February 8, 2024 02:13
@KJTsanaktsidis KJTsanaktsidis deleted the ktsanaktsidis/validate_keys_2 branch February 19, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant