Skip to content
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

Ability to inject Redis client in redis storage #7

Closed
martinssipenko opened this issue Nov 1, 2019 · 6 comments
Closed

Ability to inject Redis client in redis storage #7

martinssipenko opened this issue Nov 1, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@martinssipenko
Copy link

Rigth now \Redis client is constructed within __construct method of Prometheus\Storage\Redis class. What thoughts do you have on adding ability to inject \Redis into storage class? This would allow to reuse already existing connection from framework.

I'm happy to contribute the code change if/when it's decided to do it and what would be the best approach to do it.

@NoelDavies
Copy link

I'm down for that if others are open to it - the only thing is it's a huge method signature change and would not be backwards compat. So we'd have to solve this in one of the following ways (open to others, these are just the ideas I can see):

  • Create a public static factory (named constructor) for this, and have that constructed through that
  • Bump the version (don't like this idea)
  • Create a standalone factory with the same original signature and pass the existing client as an optional argument.

@NoelDavies NoelDavies added the enhancement New feature or request label Nov 1, 2019
@martinssipenko
Copy link
Author

I personally like the names constructor option. Let me try it out and I'll send some code your way when I have something to show.

@martinssipenko
Copy link
Author

Just noticed that $this->openConnection(); is being called in all methods. This would gave to change in case Redis is injected as the connection would have been established already.

I see two options here:

  • Move the call to __construct.
  • Add an if statement in openConnection method that would check against private property, if it's set openConnection would exit early.

WDYT?

@martinssipenko
Copy link
Author

Here is a draft PR: #8

@NoelDavies
Copy link

NoelDavies commented Nov 1, 2019

The existing connection would still have to be injected, but nice find!

@martinssipenko
Copy link
Author

Closed by #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants