-
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][Connector-v2] Redis support select db #5570
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -48,6 +48,13 @@ public enum HashKeyParseMode { | |||||
.withDescription( | ||||||
"redis authentication password, you need it when you connect to an encrypted cluster"); | ||||||
|
||||||
public static final Option<Integer> DB_NUM = | ||||||
Options.key("db_num") | ||||||
.intType() | ||||||
.defaultValue(0) | ||||||
.withDescription( | ||||||
"redis database index id, It is connected to db 0 by default"); | ||||||
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 |
||||||
|
||||||
public static final Option<String> USER = | ||||||
Options.key("user") | ||||||
.stringType() | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,7 @@ public class RedisParameters implements Serializable { | |||||||||
private String host; | ||||||||||
private int port; | ||||||||||
private String auth = ""; | ||||||||||
private Integer dbNum; | ||||||||||
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 |
||||||||||
private String user = ""; | ||||||||||
private String keysPattern; | ||||||||||
private String keyField; | ||||||||||
|
@@ -58,6 +59,10 @@ public void buildWithConfig(Config config) { | |||||||||
if (config.hasPath(RedisConfig.AUTH.key())) { | ||||||||||
this.auth = config.getString(RedisConfig.AUTH.key()); | ||||||||||
} | ||||||||||
// set db_num | ||||||||||
if (config.hasPath(RedisConfig.DB_NUM.key())) { | ||||||||||
this.dbNum = config.getInt(RedisConfig.DB_NUM.key()); | ||||||||||
} | ||||||||||
// set user | ||||||||||
if (config.hasPath(RedisConfig.USER.key())) { | ||||||||||
this.user = config.getString(RedisConfig.USER.key()); | ||||||||||
|
@@ -115,6 +120,9 @@ public Jedis buildJedis() { | |||||||||
if (StringUtils.isNotBlank(user)) { | ||||||||||
jedis.aclSetUser(user); | ||||||||||
} | ||||||||||
if (dbNum != null && dbNum > 0) { | ||||||||||
jedis.select(dbNum); | ||||||||||
} | ||||||||||
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 |
||||||||||
return jedis; | ||||||||||
case CLUSTER: | ||||||||||
HashSet<HostAndPort> nodes = new HashSet<>(); | ||||||||||
|
@@ -148,7 +156,11 @@ public Jedis buildJedis() { | |||||||||
} else { | ||||||||||
jedisCluster = new JedisCluster(nodes); | ||||||||||
} | ||||||||||
return new JedisWrapper(jedisCluster); | ||||||||||
JedisWrapper jedisWrapper = new JedisWrapper(jedisCluster); | ||||||||||
if (dbNum != null && dbNum > 0) { | ||||||||||
jedisWrapper.select(dbNum); | ||||||||||
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. The same as above. |
||||||||||
} | ||||||||||
return jedisWrapper; | ||||||||||
default: | ||||||||||
// do nothing | ||||||||||
throw new RedisConnectorException( | ||||||||||
|
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.