-
Notifications
You must be signed in to change notification settings - Fork 8k
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
add redis implement of datasource #102
add redis implement of datasource #102
Conversation
Codecov Report
@@ Coverage Diff @@
## master #102 +/- ##
===========================================
+ Coverage 45.74% 46.24% +0.5%
- Complexity 556 589 +33
===========================================
Files 114 118 +4
Lines 3817 4063 +246
Branches 531 559 +28
===========================================
+ Hits 1746 1879 +133
- Misses 1857 1950 +93
- Partials 214 234 +20
Continue to review full report at Codecov.
|
|
||
private String ruleKey; | ||
|
||
public RedisDataSource(RedisClient client, String ruleKey, String channel, ConfigParser<String, T> parser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the constructor should not directly accept a RedisClient
as users don't have to know the internal client here. Users can provide host and port, then we create the client internal. So even if we changed the Redis client library, users don't have to care about that.
The constructor can be like this:
public RedisDataSource(String host, int port, String ruleKey, String channel, ConfigParser<String, T> parser)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. it should be decoupled. but when build RedisClient
with lettuce. it has different mode to build like this:
Standalone mode build:
RedisURI masterUri = RedisURI.Builder.redis("master-host", 6379).build();
Sentinel mode build:
RedisURI sentinelUri = RedisURI.Builder.sentinel("sentinel-host", 26379, "master-name").build();
case i build a own constructor to compatible to all:
MyRedisURI{host,port,password,RedisConnectionType,ClientResources}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's okay, you can implement a universal RedisConfig
class including these attributes, then users can pass a RedisConfig
to the constructor.
...atasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/RedisDataSource.java
Outdated
Show resolved
Hide resolved
...atasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/RedisDataSource.java
Outdated
Show resolved
Hide resolved
...atasource-redis/src/main/java/com/alibaba/csp/sentinel/datasource/redis/RedisDataSource.java
Show resolved
Hide resolved
|
||
@Override | ||
public void message(String channel, String message) { | ||
getProperty().updateValue(parser.parse(message)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add a log here like this:
RecordLog.info(String.format("[RedisDataSource] New property value received for (%s:%d, %s): %s", host, port, channel, message));
@@ -0,0 +1,111 @@ | |||
package com.alibaba.csp.sentinel.datasource.redis; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add license header here.
} | ||
|
||
@Test | ||
public void pub_msg_and_receive_success() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name should follow camel-case naming style like: testPubMessageAndReceiveSuccess
.
...ource-redis/src/test/java/com/alibaba/csp/sentinel/datasource/redis/RedisDataSourceTest.java
Outdated
Show resolved
Hide resolved
Using pub-sub feature is a good idea, but for consistency users should publish the value and save the value to the
We cannot ensure users will do that, but it's better to mention it in the document, and provide a helper publisher to do that. |
Hi, any progress on this? |
yes. I will finish it at this weekend. |
I'm done |
Nice! It may take some time to review the code. I'll do the review these days. |
Hi, please re-sign the CLA as there may be some update on it. |
* @param masterId sentinel master id | ||
* @return New builder with Sentinel host/port. | ||
*/ | ||
public static RedisConnectionConfig.Builder sentinel(String host, int port, String masterId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to rename sentinel
to redisSentinel
as our project's name is also Sentinel, so the name of the method may be confusing.
Thanks for your contribution! I'll rearrange some code later. |
- This implementation uses Lettuce as the internal client, and leverages Redis pub-sub feature to implement push mode data source. (by @tigerMoon)
- This implementation uses Lettuce as the internal client, and leverages Redis pub-sub feature to implement push mode data source. (by @tigerMoon)
Describe what this PR does / why we need it
Add Redis implementation of Datasource
Does this pull request fix one issue?
Resolves #37
Describe how you did it
Use Lettuce Redis client and Redis pub/sub feature.
Describe how to verify it
Run the test cases.
Special notes for reviews
no