@@ -1695,19 +1695,23 @@ redis_sock_create(char *host, int host_len, unsigned short port,
16951695PHP_REDIS_API int redis_sock_connect (RedisSock * redis_sock TSRMLS_DC )
16961696{
16971697 struct timeval tv , read_tv , * tv_ptr = NULL ;
1698- zend_string * persistent_id = NULL ;
1699- char host [1024 ];
1700- const char * fmtstr = "%s:%d" ;
1698+ zend_string * persistent_id = NULL , * estr = NULL ;
1699+ char host [1024 ], * pos , * address , * schema = NULL ;
1700+ const char * fmtstr = "%s://%s: %d" ;
17011701 int host_len , usocket = 0 , err = 0 , tcp_flag = 1 ;
17021702 ConnectionPool * p = NULL ;
1703- zend_string * estr = NULL ;
17041703
17051704 if (redis_sock -> stream != NULL ) {
17061705 redis_sock_disconnect (redis_sock , 0 TSRMLS_CC );
17071706 }
17081707
1709- if (ZSTR_VAL (redis_sock -> host )[0 ] == '/' && redis_sock -> port < 1 ) {
1710- host_len = snprintf (host , sizeof (host ), "unix://%s" , ZSTR_VAL (redis_sock -> host ));
1708+ address = ZSTR_VAL (redis_sock -> host );
1709+ if ((pos = strstr (address , "://" )) != NULL ) {
1710+ schema = estrndup (address , pos - address );
1711+ address = pos + sizeof ("://" ) - 1 ;
1712+ }
1713+ if (redis_sock -> port < 1 ) {
1714+ host_len = snprintf (host , sizeof (host ), "unix://%s" , address );
17111715 usocket = 1 ;
17121716 } else {
17131717 if (redis_sock -> port == 0 )
@@ -1716,11 +1720,12 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
17161720#ifdef HAVE_IPV6
17171721 /* If we've got IPv6 and find a colon in our address, convert to proper
17181722 * IPv6 [host]:port format */
1719- if (strchr (ZSTR_VAL ( redis_sock -> host ) , ':' ) != NULL ) {
1720- fmtstr = "[%s]:%d" ;
1723+ if (strchr (address , ':' ) != NULL ) {
1724+ fmtstr = "%s:// [%s]:%d" ;
17211725 }
17221726#endif
1723- host_len = snprintf (host , sizeof (host ), fmtstr , ZSTR_VAL (redis_sock -> host ), redis_sock -> port );
1727+ host_len = snprintf (host , sizeof (host ), fmtstr , schema ? schema : "tcp" , address , redis_sock -> port );
1728+ if (schema ) efree (schema );
17241729 }
17251730
17261731 if (redis_sock -> persistent ) {
0 commit comments