@@ -232,6 +232,8 @@ pub struct RedisConnectionInfo {
232232 pub protocol : ProtocolVersion ,
233233 /// Optionally a client name that should be used for connection
234234 pub client_name : Option < String > ,
235+ /// Optionally a library name that should be used for connection
236+ pub lib_name : Option < String > ,
235237 /// Optionally a pubsub subscriptions that should be used for connection
236238 pub pubsub_subscriptions : Option < PubSubSubscriptionInfo > ,
237239}
@@ -391,6 +393,7 @@ fn url_to_tcp_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
391393 _ => ProtocolVersion :: RESP2 ,
392394 } ,
393395 client_name : None ,
396+ lib_name : None ,
394397 pubsub_subscriptions : None ,
395398 } ,
396399 } )
@@ -424,6 +427,7 @@ fn url_to_unix_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
424427 _ => ProtocolVersion :: RESP2 ,
425428 } ,
426429 client_name : None ,
430+ lib_name : None ,
427431 pubsub_subscriptions : None ,
428432 } ,
429433 } )
@@ -925,13 +929,15 @@ pub fn connect(
925929 setup_connection ( con, & connection_info. redis )
926930}
927931
928- pub ( crate ) fn client_set_info_pipeline ( ) -> Pipeline {
932+ pub ( crate ) fn client_set_info_pipeline ( lib_name : Option < & str > ) -> Pipeline {
929933 let mut pipeline = crate :: pipe ( ) ;
934+ let lib_name_value = lib_name. unwrap_or ( "UnknownClient" ) ;
935+ let final_lib_name = option_env ! ( "GLIDE_NAME" ) . unwrap_or ( lib_name_value) ;
930936 pipeline
931937 . cmd ( "CLIENT" )
932938 . arg ( "SETINFO" )
933939 . arg ( "LIB-NAME" )
934- . arg ( std :: env! ( "GLIDE_NAME" ) )
940+ . arg ( final_lib_name )
935941 . ignore ( ) ;
936942 pipeline
937943 . cmd ( "CLIENT" )
@@ -993,7 +999,8 @@ fn setup_connection(
993999
9941000 // result is ignored, as per the command's instructions.
9951001 // https://redis.io/commands/client-setinfo/
996- let _: RedisResult < ( ) > = client_set_info_pipeline ( ) . query ( & mut rv) ;
1002+ let _: RedisResult < ( ) > =
1003+ client_set_info_pipeline ( connection_info. lib_name . as_deref ( ) ) . query ( & mut rv) ;
9971004
9981005 Ok ( rv)
9991006}
@@ -1726,6 +1733,34 @@ pub fn get_resp3_hello_command_error(err: RedisError) -> RedisError {
17261733mod tests {
17271734 use super :: * ;
17281735
1736+ #[ test]
1737+ fn test_client_set_info_pipeline_default_lib_name ( ) {
1738+ let pipeline = client_set_info_pipeline ( None ) ;
1739+ let packed_commands = pipeline. get_packed_pipeline ( ) ;
1740+ let cmd_str = String :: from_utf8_lossy ( & packed_commands) ;
1741+
1742+ // Should contain CLIENT SETINFO LIB-NAME
1743+ assert ! ( cmd_str. contains( "CLIENT" ) ) ;
1744+ assert ! ( cmd_str. contains( "SETINFO" ) ) ;
1745+ assert ! ( cmd_str. contains( "LIB-NAME" ) ) ;
1746+
1747+ // When GLIDE_NAME is set, it should use that value
1748+ // When GLIDE_NAME is not set and lib_name is None, it should use "UnknownClient"
1749+ // Since we can't control GLIDE_NAME in this test, we just verify the structure
1750+ assert ! ( cmd_str. contains( "Glide" ) || cmd_str. contains( "UnknownClient" ) ) ;
1751+ }
1752+
1753+ #[ test]
1754+ fn test_client_set_info_pipeline_logic ( ) {
1755+ // Test the logic directly by simulating what happens when GLIDE_NAME is not set
1756+ let lib_name_value = None . unwrap_or ( "UnknownClient" ) ;
1757+ assert_eq ! ( lib_name_value, "UnknownClient" ) ;
1758+
1759+ // Test with provided lib_name
1760+ let lib_name_value = Some ( "CustomClient" ) . unwrap_or ( "UnknownClient" ) ;
1761+ assert_eq ! ( lib_name_value, "CustomClient" ) ;
1762+ }
1763+
17291764 #[ test]
17301765 fn test_parse_redis_url ( ) {
17311766 let cases = vec ! [
@@ -1840,6 +1875,7 @@ mod tests {
18401875 password: None ,
18411876 protocol: ProtocolVersion :: RESP2 ,
18421877 client_name: None ,
1878+ lib_name: None ,
18431879 pubsub_subscriptions: None ,
18441880 } ,
18451881 } ,
0 commit comments