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

provide predis native configuration option #88

Merged
merged 7 commits into from
Oct 1, 2018

Conversation

scones
Copy link
Contributor

@scones scones commented Jun 11, 2018

the current wrapper class does not allow for a deviation from "one redis server" configuration variant of predis.

As Resque in itself is a technology one usually uses in more complex setups, the need for a more complex redis-setup arises.
The provided predis version does have all these options, but the wrapper is too limited.

This patch allows for direct configuration of predis via the predis section in the config.yml
it effectively overrides anything configured in the redis section, so one has to chose.

I provided a sentinel example for that.

In addition i added the following things for a brighter future:

  • Dockerfile file for testing
  • docker-compose.yml file for testing
  • a basic editorconfig
  • 2 tests (Redis with legacy initialization, Redis with override initialization)
  • a .gitattributes file

if this gets merged i also have the tools to work on the handler thing again (#85 )

best regards,
scones

@scones
Copy link
Contributor Author

scones commented Jun 11, 2018

upon rereading the issues:
this solves #63

@xelan
Copy link
Collaborator

xelan commented Jun 13, 2018

Thank you very much for this nice PR, @scones! I'll have a more detailed look in a few days. In general, the concept to leverage the full potential of the underlying predis library sounds great. Although you also still support the legacy configuration, I'd think this should land in the 3.0 release. What is your opinion on that?

Unfortunately, I didn't get any response from @mjphaynes yet concerning issue #78. However, we could postpone that decision to 4.0 and continue now with this PR, PR #82 and PR #85 for php-resque 3.0.

@xelan
Copy link
Collaborator

xelan commented Jun 13, 2018

By the way, could you please also add a short description in the docs? Thank you very much 😄

@scones
Copy link
Contributor Author

scones commented Jun 13, 2018

changing the major version would indicate a major change in interfaces or a complete rewrite.
Neither is done with this request. I wrote it as compatible with all existing installations on purpose.

You can merge it as soon as you find it good. ;)

also: what to add to the docs? i edited the config.yml with the dummy configs. How to configure the predis client is not in the scope of the docs from php-resque, but the job of predis.

best regards

@xelan
Copy link
Collaborator

xelan commented Jun 13, 2018

Thanks. I like the general approach and will review and (probably) merge soon 👍 . Two small things I saw for now:

The Dockerfile you add is for development and testing with PHP 5.3, right? Maybe we should add a general docker readme (docker.md?) in the docs folder on how to run php-resque in Docker with best practices (see #66).

Could you please use camelCase for variable and property names instead of snake_case? We try to comply with PSR-2 for new code (although there are still a few legacy code parts).

Thank you very much!
Best regards
Andreas

@scones
Copy link
Contributor Author

scones commented Jun 13, 2018

The Dockerfile is for php 5.3, yes. But it is intended as testing environment.
I wouldn't know if it is suitable for productive use. Thus there is no warranty.

I will rename the variables.

@scones
Copy link
Contributor Author

scones commented Jun 13, 2018

done

@xelan
Copy link
Collaborator

xelan commented Jun 16, 2018

Great, thank you @scones 👍
I'll have a look on Monday.

Best regards
Andreas

@xelan xelan added this to the 2.2 milestone Jun 19, 2018
@xelan
Copy link
Collaborator

xelan commented Jun 19, 2018

I'll leave a few notes via the review system here 😄
Could you afterwards please rebase your commit messages (we normally use imperative form, first letter uppercase, no branch name, e.g. "Pass the predis config options through directly") and maybe squash them logically?

Thank you very much!

config.yml Outdated
@@ -11,7 +11,7 @@

include: examples/autoload.php # A file to include on each command


# # The manual legacy way
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether manual is the right expression here. Maybe just "The legacy way, which only supports a subset of Redis options"?


RUN apt-get install -yqq git-core

RUN pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i remember correctly, we use phpiredis instead of the quite problematic and unmaintained PHP redis extension. See #42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, but this configuration let me run the tests.
which is all this container is for: run the tests in any environment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's maybe add a comment at the beginning of the Dockerfile that it is for development and testing with the minimum deps, but not suitable as a template for production. What do you think?

We plan to add/link a fully-fledged Docker example with a minimal but complete worker for a real-world application later on anyway.

RUN docker-php-ext-install pcntl


CMD composer install -v && tail -f /dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is fail -f /dev/null supposed to do in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tail -f attaches itself to a stream and listens. with /dev/null as a stream there will be no output, but the stream stays open.

in combination it keeps the CMD running without producing spam.
Thus the docker container won't shut down after it booted up, but stays active.

);

// setup password
if (isset($config['password']) && !empty($config['password'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty includes a check for isset() so it is not necessary to do both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, force of habbit.
i tend to implement such stuff explicit and more readable

}

// create Predis client
$this->redis = new Predis\Client($params, $options);
$this->redis = $this->initializePredisClient($predisParams, $predisOptions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to extract the intitalization!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was necessary to make the initialization testable, as it it cumbersome to mock foreign objects.

@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Resque\Tests\Heplers\Utils;
namespace Resque\Tests\Helpers;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing that 👍

@scones scones force-pushed the master branch 3 times, most recently from ffe59f3 to bb65341 Compare June 20, 2018 11:37
@scones
Copy link
Contributor Author

scones commented Jun 20, 2018

everything updated.
some of your reviews got lost in the process tho.

@xelan
Copy link
Collaborator

xelan commented Jun 27, 2018

Thank you very much 👍
I'll test it in an example application with different settings within the next days. Then it'll land in 2.2 if everything is fine.

Best regards
Andreas

@xelan
Copy link
Collaborator

xelan commented Jul 16, 2018

  • Tests A: default config, virtual machine
  • Tests B: legacy config, virtual machine
  • Tests C: native config, virtual machine
  • Tests D: default config, docker swarm
  • Tests E: legacy config, docker swarm
  • Tests F: native config, docker swarm

@scones
Copy link
Contributor Author

scones commented Jul 16, 2018

unless there is more text to that, i will assume these checkboxes mean: tests in progress :)

@xelan
Copy link
Collaborator

xelan commented Jul 16, 2018

Exactly 😀 I'll update here and post an additional comment when all tests are done. What would you think about my three notes?

@scones
Copy link
Contributor Author

scones commented Jul 17, 2018

what notes?

# # "options" is the second parameter to Predis\Client
# predis:
# config:
# - "tcp://10.0.0.1:12345"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the config template should use the standard Redis port (6379) as well. Otherwise, this might confuse users.

# - "tcp://10.0.0.3:12345"
# options:
# service: "some_redis_cluster_name"
# replication: "sentinel"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would add a comment inside the template that advanced Predis features like password, database index, replication etc are supported, but optional. Otherwise, newbies might struggle as they can't find out why it doesn't work if they try to copy and adapt the example 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the note above would suggest the existence of a valid documentation of settings.
such a thing should not be done in a config file.

thus you are asking for a feature, which is unrelated to this pull request.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, so I'd just link to the Predis documentation instead of duplicating it on our own.

If someone wants to use advanced features they can do so, but the defaults in the config template should IMHO match the ones in the legacy configuration to avoid confusion.


RUN apt-get install -yqq git-core

RUN pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's maybe add a comment at the beginning of the Dockerfile that it is for development and testing with the minimum deps, but not suitable as a template for production. What do you think?

We plan to add/link a fully-fledged Docker example with a minimal but complete worker for a real-world application later on anyway.

@xelan
Copy link
Collaborator

xelan commented Jul 17, 2018

Ah sorry, just saw that GitHub doesn't show my review comments to others until I explicitely publish them 😀

@scones
Copy link
Contributor Author

scones commented Jul 17, 2018

  • the docker image is not referenced by any of the documentation.
  • it actually is viable for productive use, just not good at it (outdated php, no actual task or service provided)

thus it just exists there, without users knowing why. I can only assume, that users who seek an (undocumented) Dockerfile, will know enough about docker to understand what it's doing.
Worst case scenario: they write a bug report for an (yet) unsupported feature.

@xelan xelan merged commit 29f331c into mjphaynes:master Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants