File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
main/java/io/vertx/redis/client/impl
test/java/io/vertx/redis/client/impl Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -80,8 +80,17 @@ public RedisURI(String connectionString) {
8080 try {
8181 final URI uri = new URI (connectionString );
8282
83- final String host = uri .getHost () == null ? DEFAULT_HOST : uri .getHost ();
84- final int port = uri .getPort () == -1 ? DEFAULT_PORT : uri .getPort ();
83+ boolean directRedisScheme = "rediss" .equals (uri .getScheme ()) || "redis" .equals (uri .getScheme ());
84+ if (directRedisScheme && uri .getHost () == null ) {
85+ throw new IllegalArgumentException ("Fail to parse connection string host" );
86+ }
87+ final String host = uri .getHost ();
88+
89+ if (directRedisScheme && uri .getPort () == -1 ) {
90+ throw new IllegalArgumentException ("Fail to parse connection string port" );
91+ }
92+ final int port = uri .getPort ();
93+
8594 final String path = (uri .getPath () == null || uri .getPath ().isEmpty ()) ? "/" : uri .getPath ();
8695
8796 // According to https://www.iana.org/assignments/uri-schemes/prov/redis there is no specified order of decision
Original file line number Diff line number Diff line change 11package io .vertx .redis .client .impl ;
22
33import org .junit .Assert ;
4+ import org .junit .Rule ;
45import org .junit .Test ;
6+ import org .junit .rules .ExpectedException ;
57
68/**
79 * @author <a href="mailto:artursletter@gmail.com">Artur Badretdinov</a>
810 */
911public class RedisURITest {
1012
13+ @ Rule
14+ public ExpectedException exceptionRule = ExpectedException .none ();
15+
1116 @ Test
1217 public void testHostAndPort () {
1318 RedisURI redisURI = new RedisURI ("redis://redis-1234.hosted.com:1234" );
@@ -82,4 +87,18 @@ public void testColon() {
8287 RedisURI redisURI = new RedisURI ("redis://:admin%3Aqwer@localhost:6379/1" );
8388 Assert .assertEquals ("admin:qwer" , redisURI .password ());
8489 }
90+
91+ @ Test
92+ public void testRightSyntax () {
93+ RedisURI redisURI = new RedisURI ("redis://your-redis-domain:6379" );
94+ Assert .assertEquals (6379 , redisURI .socketAddress ().port ());
95+ Assert .assertEquals ("your-redis-domain" , redisURI .socketAddress ().host ());
96+ }
97+
98+ @ Test
99+ public void testWrongSyntax () {
100+ exceptionRule .expect (IllegalArgumentException .class );
101+ exceptionRule .expectMessage ("Fail to parse connection string host" );
102+ new RedisURI ("redis://:your-redis-domain:6379" );
103+ }
85104}
You can’t perform that action at this time.
0 commit comments