Skip to content

[Cache] Added RedisAdapter #17441

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
wants to merge 1 commit into from
Closed

[Cache] Added RedisAdapter #17441

wants to merge 1 commit into from

Conversation

aurimasniekis
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

I have added RedisAdapter. I haven't hardcoded that it would use phpredis extension version client because there is many other clients which provide same API so to support them I left open. For test purpose I wrote a FakeRedis client implementation which acts like real just stores everything in array.

If we choose to use extension version I will remove FakeRedis and add variable requirement for \Redis type. But we will need redis instance on tests... Or somehow find way to mock it (We will need extend all cache/integration-test tests because of mocking)

@aurimasniekis
Copy link
Contributor Author

Have 0 idea why it failed on HHVM... Maybe someone could inspect with HHVM knowledge?

*/
protected function doClear()
{
return $this->redis->flushDB();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this consider the namespace? I mean like this it would flush all keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redis does not support delete with prefix or etc... I could do get keys and when do foreach but you know...

P.S. APCU does also clear all cache...

@xabbuh
Copy link
Member

xabbuh commented Jan 19, 2016

I would have said that php-cache/integration-tests@e851dc1 should have been the required change to for HHVM to call the destructor.

@nicolas-grekas Do you have any idea?

@nicolas-grekas
Copy link
Member

@xabbuh no, and in fact I skipped this test on HHVM...

@xabbuh
Copy link
Member

xabbuh commented Jan 19, 2016

Sorry, do you mean no as "no idea" or as "no that commit should not fix it"?

@nicolas-grekas
Copy link
Member

As "no idea" :-)

@aurimasniekis
Copy link
Contributor Author

Maybe someone could help as I don't have HHVM on any machine to try debug it... 😞

* @param string $namespace
* @param int $defaultLifetime
*/
public function __construct($redisConnection, $namespace = '', $defaultLifetime = 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not typehinting the $redisConnection argument with \Redis type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you read my pull request description?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, sorry my bad! I didn't read the description...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

phpredis, PRedis, ReactPHP Redis they all use same function names but there is no general Interface for them all that's why I left it open... I know it's bad but what I could I do... Maybe create some kind of wrapper which adds interface I don't know 😞

Copy link
Member

Choose a reason for hiding this comment

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

The type of this argument in the constructor docblock must reflect that you can pass different objects (by either listing all of them or by documenting what a passed object must be able to do).

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, but I do not want to include all 3rd party libraries just to show possible types, but documentation is a better thing I think. Or I will be creating a library which will provide unified interface and wrapper which would wrap those objects and provide interface

Copy link
Member

Choose a reason for hiding this comment

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

Well you can just set the expected type to object and then add a sentence describing the requirement for an object being passed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@GCDS I think you should include all the possible types in the docblock if you intend to support all of them. PHPDoc is the right place to do it imo. Furthermore all the possible implementations should be tested. Otherwise we cannot really say we support them.

@nicolas-grekas
Copy link
Member

I'd like to know the exact list of targeted Redis client that should work with this adapter.
https://github.com/phpredis/phpredis works for sure,
any other that works for real?

@aurimasniekis
Copy link
Contributor Author

Just tried predis on test case the interface is ok but returns and logic does not work the same as phpredis... If the choose only to support phpredis we can't hardcode \Redis as type because then we will be unable to pass FakeRedis to constructor.

@dmaicher
Copy link
Contributor

dmaicher commented Feb 3, 2016

Working with a PHPUnit Mock instead of the FakeRedis should work though?

@aurimasniekis
Copy link
Contributor Author

@dmaicher I guess yeah, but the thing that class does not exists, and to mock fully working stuff its bit hardcore

@rybakit
Copy link
Contributor

rybakit commented Feb 3, 2016

@GCDS What about copy/pasting this: https://github.com/ukko/phpredis-phpdoc?

@jakzal
Copy link
Contributor

jakzal commented Feb 4, 2016

I don't think that tests run against the FakeRedis give us any value. How can we know that it actually works with PhpRedis or any other implementation? Also, even if it works now we won't know if it still works as soon as PhpRedis changes its implementation.

IMO we need an integration test for each of supported implementations. An integration test that would use the real redis client, not a fake/stub/mock.

@fabpot
Copy link
Member

fabpot commented Feb 29, 2016

@jakzal We had this discussion before and I totally agree. We must have integration tests with Redis here as we have some for LDAP for instance.

@nicolas-grekas
Copy link
Member

@GCDS redis.so is available by default on travis so we can easily use it in the test suite. Are you still ok to work on this PR? Do you need help?

@fabpot
Copy link
Member

fabpot commented Mar 10, 2016

@GCDS Do you have time to finish this PR by adding some tests?

@aurimasniekis
Copy link
Contributor Author

I will finish. If I understand correctly I just need update tests to use real Redis?

@fabpot
Copy link
Member

fabpot commented Mar 10, 2016

That's correct, tests must use a real Redis.

@aurimasniekis
Copy link
Contributor Author

Ok, I will come back home and finish the PR 👍

@aurimasniekis
Copy link
Contributor Author

I changed to use real Redis Instance also enabled Redis inside Travis config file. could you check if everything is ok? @fabpot

@fabpot
Copy link
Member

fabpot commented Mar 10, 2016

@GCDS Can you rebase on current master and fix the tests. Since you began the PR, the cache component evolved and it seems that your code is not accurate anymore. Thanks.

@nicolas-grekas
Copy link
Member

Included in #18172, thank you @GCDS

fabpot added a commit that referenced this pull request Mar 15, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Cache] Redis adapter

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17441
| License       | MIT
| Doc PR        | -

Commits
-------

6b7a1fc [Cache] Finish Redis adapter
4893cbc Added RedisAdapter
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.

10 participants