@@ -20,29 +20,19 @@ use unix_socket::UnixStream;
20
20
21
21
static DEFAULT_PORT : u16 = 6379 ;
22
22
23
- fn redis_scheme_type_mapper ( scheme : & str ) -> url:: SchemeType {
24
- match scheme {
25
- "redis" => url:: SchemeType :: Relative ( DEFAULT_PORT ) ,
26
- "unix" => url:: SchemeType :: FileLike ,
27
- _ => url:: SchemeType :: NonRelative ,
28
- }
29
- }
30
-
31
23
/// This function takes a redis URL string and parses it into a URL
32
24
/// as used by rust-url. This is necessary as the default parser does
33
25
/// not understand how redis URLs function.
34
- pub fn parse_redis_url ( input : & str ) -> url:: ParseResult < url:: Url > {
35
- let mut parser = url:: UrlParser :: new ( ) ;
36
- parser. scheme_type_mapper ( redis_scheme_type_mapper) ;
37
- match parser. parse ( input) {
26
+ pub fn parse_redis_url ( input : & str ) -> Result < url:: Url , ( ) > {
27
+ match url:: Url :: parse ( input) {
38
28
Ok ( result) => {
39
- if result. scheme == "redis" || result. scheme == "unix" {
29
+ if result. scheme ( ) == "redis" || result. scheme ( ) == "unix" {
40
30
Ok ( result)
41
31
} else {
42
- Err ( url :: ParseError :: InvalidScheme )
32
+ Err ( ( ) )
43
33
}
44
34
} ,
45
- Err ( err ) => Err ( err ) ,
35
+ Err ( _ ) => Err ( ( ) ) ,
46
36
}
47
37
}
48
38
@@ -97,12 +87,13 @@ impl<'a> IntoConnectionInfo for &'a str {
97
87
fn url_to_tcp_connection_info ( url : url:: Url ) -> RedisResult < ConnectionInfo > {
98
88
Ok ( ConnectionInfo {
99
89
addr : Box :: new ( ConnectionAddr :: Tcp (
100
- unwrap_or ! ( url. serialize_host( ) ,
101
- fail!( ( ErrorKind :: InvalidClientConfig , "Missing hostname" ) ) ) ,
90
+ match url. host ( ) {
91
+ Some ( host) => host. to_string ( ) ,
92
+ None => fail ! ( ( ErrorKind :: InvalidClientConfig , "Missing hostname" ) ) ,
93
+ } ,
102
94
url. port ( ) . unwrap_or ( DEFAULT_PORT )
103
95
) ) ,
104
- db : match url. serialize_path ( ) . unwrap_or ( "" . to_string ( ) )
105
- . trim_matches ( '/' ) {
96
+ db : match url. path ( ) . trim_matches ( '/' ) {
106
97
"" => 0 ,
107
98
path => unwrap_or ! ( path. parse:: <i64 >( ) . ok( ) ,
108
99
fail!( ( ErrorKind :: InvalidClientConfig , "Invalid database number" ) ) ) ,
@@ -118,8 +109,7 @@ fn url_to_unix_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
118
109
unwrap_or ! ( url. to_file_path( ) . ok( ) ,
119
110
fail!( ( ErrorKind :: InvalidClientConfig , "Missing path" ) ) ) ,
120
111
) ) ,
121
- db : match url. query_pairs ( ) . unwrap_or ( vec ! [ ] )
122
- . into_iter ( ) . filter ( |& ( ref key, _) | key == "db" ) . next ( ) {
112
+ db : match url. query_pairs ( ) . into_iter ( ) . filter ( |& ( ref key, _) | key == "db" ) . next ( ) {
123
113
Some ( ( _, db) ) => unwrap_or ! ( db. parse:: <i64 >( ) . ok( ) ,
124
114
fail!( ( ErrorKind :: InvalidClientConfig , "Invalid database number" ) ) ) ,
125
115
None => 0 ,
@@ -136,9 +126,9 @@ fn url_to_unix_connection_info(_: url::Url) -> RedisResult<ConnectionInfo> {
136
126
137
127
impl IntoConnectionInfo for url:: Url {
138
128
fn into_connection_info ( self ) -> RedisResult < ConnectionInfo > {
139
- if self . scheme == "redis" {
129
+ if self . scheme ( ) == "redis" {
140
130
url_to_tcp_connection_info ( self )
141
- } else if self . scheme == "unix" {
131
+ } else if self . scheme ( ) == "unix" {
142
132
url_to_unix_connection_info ( self )
143
133
} else {
144
134
fail ! ( ( ErrorKind :: InvalidClientConfig , "URL provided is not a redis URL" ) ) ;
0 commit comments