@@ -11,8 +11,8 @@ use redis::aio::{MultiplexedConnection, PubSub};
1111use redis:: cluster:: ClusterClient ;
1212use redis:: cluster_async:: ClusterConnection ;
1313use redis:: {
14- AsyncCommands , Client , ClientTlsConfig , ConnectionAddr , ConnectionInfo , RedisConnectionInfo ,
15- RedisError , TlsCertificates ,
14+ AsyncCommands , Client , ClientTlsConfig , ConnectionAddr , ConnectionInfo , IntoConnectionInfo ,
15+ RedisConnectionInfo , RedisError , TlsCertificates ,
1616} ;
1717use std:: fs:: read;
1818
@@ -56,25 +56,27 @@ impl Redis {
5656pub fn open_single (
5757 info : & nextcloud_config_parser:: RedisConnectionInfo ,
5858) -> Result < Client , RedisError > {
59- let redis = RedisConnectionInfo {
60- db : info. db ,
61- username : info. username . clone ( ) ,
62- password : info. password . clone ( ) ,
63- protocol : Default :: default ( ) ,
64- } ;
59+ let mut redis = RedisConnectionInfo :: default ( ) . set_db ( info. db ) ;
60+ if let Some ( username) = info. username . as_deref ( ) {
61+ redis = redis. set_username ( username) ;
62+ }
63+ if let Some ( password) = info. password . as_deref ( ) {
64+ redis = redis. set_password ( password) ;
65+ }
6566 let connection_info = build_connection_info ( info. addr . clone ( ) , redis, info. tls_params . as_ref ( ) ) ;
6667 Ok ( match info. tls_params . as_ref ( ) {
6768 None => Client :: open ( connection_info) ?,
6869 Some ( tls_params) => {
6970 // the redis library doesn't let us set both `danger_accept_invalid_hostnames` and certificates without this mess:
7071 // `Client::build_with_tls` doesn't use the `danger_accept_invalid_hostnames` from the passed in info
7172 // so we first use it to get build the certificates then take the connection info from it so we can configure it further
72- let mut connection_info =
73+ let connection_info =
7374 Client :: build_with_tls ( connection_info, build_tls_certificates ( tls_params) ?) ?
7475 . get_connection_info ( )
7576 . clone ( ) ;
7677 connection_info
77- . addr
78+ . addr ( )
79+ . clone ( )
7880 . set_danger_accept_invalid_hostnames ( tls_params. accept_invalid_hostname ) ;
7981 Client :: open ( connection_info) ?
8082 }
@@ -86,48 +88,43 @@ fn build_connection_info(
8688 redis : RedisConnectionInfo ,
8789 tls : Option < & RedisTlsParams > ,
8890) -> ConnectionInfo {
89- match ( addr, tls) {
91+ let addr = match ( addr, tls) {
9092 (
9193 RedisConnectionAddr :: Tcp {
9294 host,
9395 port,
9496 tls : false ,
9597 } ,
9698 _,
97- ) => ConnectionInfo {
98- addr : ConnectionAddr :: Tcp ( host, port) ,
99- redis,
100- } ,
99+ ) => ConnectionAddr :: Tcp ( host, port) ,
101100 (
102101 RedisConnectionAddr :: Tcp {
103102 host,
104103 port,
105104 tls : true ,
106105 } ,
107106 tls_params,
108- ) => ConnectionInfo {
109- addr : ConnectionAddr :: TcpTls {
110- host,
111- port,
112- insecure : tls_params. map ( |tls| tls. insecure ) . unwrap_or_default ( ) ,
113- tls_params : None ,
114- } ,
115- redis,
107+ ) => ConnectionAddr :: TcpTls {
108+ host,
109+ port,
110+ insecure : tls_params. map ( |tls| tls. insecure ) . unwrap_or_default ( ) ,
111+ tls_params : None ,
116112 } ,
117- ( RedisConnectionAddr :: Unix { path } , _) => ConnectionInfo {
118- addr : ConnectionAddr :: Unix ( path ) ,
119- redis ,
120- } ,
121- }
113+ ( RedisConnectionAddr :: Unix { path } , _) => ConnectionAddr :: Unix ( path ) ,
114+ } ;
115+ addr . into_connection_info ( )
116+ . unwrap ( )
117+ . set_redis_settings ( redis )
122118}
123119
124120fn open_cluster ( info : & RedisClusterConnectionInfo ) -> Result < ClusterClient , RedisError > {
125- let redis = RedisConnectionInfo {
126- db : info. db ,
127- username : info. username . clone ( ) ,
128- password : info. password . clone ( ) ,
129- protocol : Default :: default ( ) ,
130- } ;
121+ let mut redis = RedisConnectionInfo :: default ( ) . set_db ( info. db ) ;
122+ if let Some ( username) = info. username . as_deref ( ) {
123+ redis = redis. set_username ( username) ;
124+ }
125+ if let Some ( password) = info. password . as_deref ( ) {
126+ redis = redis. set_password ( password) ;
127+ }
131128 let mut builder =
132129 ClusterClient :: builder ( info. addr . iter ( ) . map ( |addr| {
133130 build_connection_info ( addr. clone ( ) , redis. clone ( ) , info. tls_params . as_ref ( ) )
0 commit comments