-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Improve][Redis] Redis reader use scan cammnd instead of keys, single mode reader/writer support batch #7087
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1163f8d
[improve][redis]using scan replace keys operation command
FuYouJ d80cf03
[improve][redis]issue#7030 when scan cursor return 0,maybe current sc…
FuYouJ 9d858dd
[improve][redis]issue#7030,issue#7085,redis reader writer support batch
FuYouJ 6f9a93f
[improve][redis]issue#7030,issue#7085,redis reader writer support batch
FuYouJ 632319f
[improve][redis]update docs
FuYouJ 7a588d3
Merge branch 'dev' into feature_redis
FuYouJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ Used to read data from Redis. | |||||
| host | string | yes | - | | ||||||
| port | int | yes | - | | ||||||
| keys | string | yes | - | | ||||||
| batch_size | int | yes | 10 | | ||||||
| data_type | string | yes | - | | ||||||
| user | string | no | - | | ||||||
| auth | string | no | - | | ||||||
|
@@ -113,6 +114,10 @@ each kv that in hash key it will be treated as a row and send it to upstream. | |||||
|
||||||
keys pattern | ||||||
|
||||||
### batch_size [int] | ||||||
|
||||||
indicates the number of keys to attempt to return per iteration.default 10 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
|
||||||
**Tips:Redis source connector support fuzzy key matching, user needs to ensure that the matched keys are the same type** | ||||||
|
||||||
### data_type [string] | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...dis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/client/RedisClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.redis.client; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisDataType; | ||
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisParameters; | ||
|
||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.params.ScanParams; | ||
import redis.clients.jedis.resps.ScanResult; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public abstract class RedisClient extends Jedis { | ||
|
||
protected final RedisParameters redisParameters; | ||
|
||
protected final int batchSize; | ||
|
||
protected final Jedis jedis; | ||
|
||
protected RedisClient(RedisParameters redisParameters, Jedis jedis) { | ||
this.redisParameters = redisParameters; | ||
this.batchSize = redisParameters.getBatchSize(); | ||
this.jedis = jedis; | ||
} | ||
|
||
public ScanResult<String> scanKeys( | ||
String cursor, int batchSize, String keysPattern, RedisDataType type) { | ||
ScanParams scanParams = new ScanParams(); | ||
scanParams.match(keysPattern); | ||
scanParams.count(batchSize); | ||
return jedis.scan(cursor, scanParams, type.name()); | ||
} | ||
|
||
public abstract List<String> batchGetString(List<String> keys); | ||
|
||
public abstract List<List<String>> batchGetList(List<String> keys); | ||
|
||
public abstract List<Set<String>> batchGetSet(List<String> keys); | ||
|
||
public abstract List<Map<String, String>> batchGetHash(List<String> keys); | ||
|
||
public abstract List<List<String>> batchGetZset(List<String> keys); | ||
|
||
public abstract void batchWriteString( | ||
List<String> keys, List<String> values, long expireSeconds); | ||
|
||
public abstract void batchWriteList( | ||
List<String> keyBuffer, List<String> valueBuffer, long expireSeconds); | ||
|
||
public abstract void batchWriteSet( | ||
List<String> keyBuffer, List<String> valueBuffer, long expireSeconds); | ||
|
||
public abstract void batchWriteHash( | ||
List<String> keyBuffer, List<String> valueBuffer, long expireSeconds); | ||
|
||
public abstract void batchWriteZset( | ||
List<String> keyBuffer, List<String> valueBuffer, long expireSeconds); | ||
} |
138 changes: 138 additions & 0 deletions
138
.../main/java/org/apache/seatunnel/connectors/seatunnel/redis/client/RedisClusterClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.redis.client; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisDataType; | ||
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisParameters; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
|
||
import redis.clients.jedis.Jedis; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class RedisClusterClient extends RedisClient { | ||
public RedisClusterClient(RedisParameters redisParameters, Jedis jedis) { | ||
super(redisParameters, jedis); | ||
} | ||
|
||
@Override | ||
public List<String> batchGetString(List<String> keys) { | ||
if (CollectionUtils.isEmpty(keys)) { | ||
return new ArrayList<>(); | ||
} | ||
List<String> result = new ArrayList<>(keys.size()); | ||
for (String key : keys) { | ||
result.add(jedis.get(key)); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public List<List<String>> batchGetList(List<String> keys) { | ||
if (CollectionUtils.isEmpty(keys)) { | ||
return new ArrayList<>(); | ||
} | ||
List<List<String>> result = new ArrayList<>(keys.size()); | ||
for (String key : keys) { | ||
result.add(jedis.lrange(key, 0, -1)); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public List<Set<String>> batchGetSet(List<String> keys) { | ||
if (CollectionUtils.isEmpty(keys)) { | ||
return new ArrayList<>(); | ||
} | ||
List<Set<String>> result = new ArrayList<>(keys.size()); | ||
for (String key : keys) { | ||
result.add(jedis.smembers(key)); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public List<Map<String, String>> batchGetHash(List<String> keys) { | ||
if (CollectionUtils.isEmpty(keys)) { | ||
return new ArrayList<>(); | ||
} | ||
List<Map<String, String>> result = new ArrayList<>(keys.size()); | ||
for (String key : keys) { | ||
Map<String, String> map = jedis.hgetAll(key); | ||
map.put("hash_key", key); | ||
result.add(map); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public List<List<String>> batchGetZset(List<String> keys) { | ||
if (CollectionUtils.isEmpty(keys)) { | ||
return new ArrayList<>(); | ||
} | ||
List<List<String>> result = new ArrayList<>(keys.size()); | ||
for (String key : keys) { | ||
result.add(jedis.zrange(key, 0, -1)); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void batchWriteString(List<String> keys, List<String> values, long expireSeconds) { | ||
int size = keys.size(); | ||
for (int i = 0; i < size; i++) { | ||
RedisDataType.STRING.set(this, keys.get(i), values.get(i), expireSeconds); | ||
} | ||
} | ||
|
||
@Override | ||
public void batchWriteList(List<String> keys, List<String> values, long expireSeconds) { | ||
int size = keys.size(); | ||
for (int i = 0; i < size; i++) { | ||
RedisDataType.LIST.set(this, keys.get(i), values.get(i), expireSeconds); | ||
} | ||
} | ||
|
||
@Override | ||
public void batchWriteSet(List<String> keys, List<String> values, long expireSeconds) { | ||
int size = keys.size(); | ||
for (int i = 0; i < size; i++) { | ||
RedisDataType.SET.set(this, keys.get(i), values.get(i), expireSeconds); | ||
} | ||
} | ||
|
||
@Override | ||
public void batchWriteHash(List<String> keys, List<String> values, long expireSeconds) { | ||
int size = keys.size(); | ||
for (int i = 0; i < size; i++) { | ||
RedisDataType.HASH.set(this, keys.get(i), values.get(i), expireSeconds); | ||
} | ||
} | ||
|
||
@Override | ||
public void batchWriteZset(List<String> keys, List<String> values, long expireSeconds) { | ||
int size = keys.size(); | ||
for (int i = 0; i < size; i++) { | ||
RedisDataType.ZSET.set(this, keys.get(i), values.get(i), expireSeconds); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
Thank you. I was careless here