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

#66 distribute the read operation on Redis Cache #132

Merged
merged 9 commits into from Jan 4, 2018

Conversation

ryusoft
Copy link
Contributor

@ryusoft ryusoft commented Dec 28, 2017

For supporting Read Replica in Cache usage

Q A
Is bugfix? no
New feature? yes
Breaks BC? no
Tests pass? yes/no
Fixed issues #66 multiple server support

@samdark samdark added type:enhancement Enhancement pr:request for unit tests Unit tests are needed. labels Dec 28, 2017
@yii-bot
Copy link

yii-bot commented Dec 28, 2017

Thank you for putting effort in the improvement of the Yii framework.
We have reviewed your pull request.

In order for the framework and your solution to remain stable in the future, we have a unit test requirement in place. Therefore we can only accept your pull request if it is covered by unit tests.

Could you add these please?

Thanks!

P.S. If you have any questions about the creation of unit tests? Don't hesitate to ask for support. More information about unit tests

This is an automated comment, triggered by adding the label pr:request for unit tests.

Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

All good but need a changelog and fixes for the small issues I've mentioned.

Cache.php Outdated
@@ -67,6 +88,21 @@ class Cache extends \yii\caching\Cache
*/
public $redis = 'redis';

/**
* @var bool
Copy link
Member

Choose a reason for hiding this comment

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

Missing @since tag and description.

Cache.php Outdated
/**
* @var array
*/
public $replicas = [];
Copy link
Member

Choose a reason for hiding this comment

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

Missing @since tag and description.

Cache.php Outdated
public $replicas = [];

/**
* @var Connection
Copy link
Member

Choose a reason for hiding this comment

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

Missing description.

Cache.php Outdated
* @inheritdoc
* @return Connection
*/
protected function getReplica()
Copy link
Member

Choose a reason for hiding this comment

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

Looks like a new method. Thus, @inheritdoc doesn't make sense. Missing @since tag and description.

Cache.php Outdated
$config['class'] = 'yii\redis\Connection';
}

//--- if hostname same, no need re-open connection
Copy link
Member

Choose a reason for hiding this comment

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

// If hostname is the same, there is no need re-open connection

@samdark samdark removed the pr:request for unit tests Unit tests are needed. label Dec 29, 2017
@samdark samdark added this to the 2.0.8 milestone Dec 29, 2017
@cebe
Copy link
Member

cebe commented Dec 30, 2017

I have simplified the code a bit and added more docs. Instance::ensure() implements most of what was implemented here, so we can just use it to create the instance. Skipping the connection when the host is the same does not make sense as there can be different ports and db settings.

@cebe
Copy link
Member

cebe commented Dec 30, 2017

seems I broke the test... :-/

$cache->enableReplicas = true;

$cache->replicas = [
['class' => 'yii\db\Connection'],
Copy link
Member

Choose a reason for hiding this comment

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

this should expect an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial intention of not using Instance::ensure() is not to break the application if replica is not properly configured, will update the test to expect exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exception expect to be handled by UnitTest in Instance Class on Instance::ensure() function, therefore I removed the test for invalid config.

ryusoft added 3 commits January 1, 2018 10:02
… class, so ignore the test for replica since we applied ensure function
… class, so ignore the test for replica since we applied ensure function
@samdark samdark requested a review from cebe January 1, 2018 13:22
@cebe cebe self-assigned this Jan 4, 2018
@cebe cebe merged commit b5fbd94 into yiisoft:master Jan 4, 2018
@cebe
Copy link
Member

cebe commented Jan 4, 2018

Thank you!

@blind3dd
Copy link

nice!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants