@@ -189,6 +189,12 @@ class Credis_Client {
189189 */
190190 protected $ host ;
191191
192+ /**
193+ * Scheme of the Redis server (tcp, tls, unix)
194+ * @var string
195+ */
196+ protected $ scheme ;
197+
192198 /**
193199 * Port on which the Redis server is running
194200 * @var integer
@@ -310,12 +316,17 @@ public function __construct($host = '127.0.0.1', $port = 6379, $timeout = null,
310316 {
311317 $ this ->host = (string ) $ host ;
312318 $ this ->port = (int ) $ port ;
319+ $ this ->scheme = null ;
313320 $ this ->timeout = $ timeout ;
314321 $ this ->persistent = (string ) $ persistent ;
315322 $ this ->standalone = ! extension_loaded ('redis ' );
316323 $ this ->authPassword = $ password ;
317324 $ this ->selectedDb = (int )$ db ;
318325 $ this ->convertHost ();
326+ if ($ this ->scheme == 'tls ' ) {
327+ // PHP Redis extension doesn't work with TLS
328+ $ this ->standalone = true ;
329+ }
319330 }
320331
321332 public function __destruct ()
@@ -402,24 +413,30 @@ public function setCloseOnDestruct($flag)
402413 }
403414 protected function convertHost ()
404415 {
405- if (preg_match ('#^(tcp|unix)://(.*)$# ' , $ this ->host , $ matches )) {
406- if ($ matches [1 ] == 'tcp ' ) {
416+ if (preg_match ('#^(tcp|tls|unix)://(.*)$# ' , $ this ->host , $ matches )) {
417+ if ($ matches [1 ] == 'tcp ' || $ matches [1 ] == 'tls ' ) {
418+ $ this ->scheme = $ matches [1 ];
407419 if ( ! preg_match ('#^([^:]+)(:([0-9]+))?(/(.+))?$# ' , $ matches [2 ], $ matches )) {
408- throw new CredisException ('Invalid host format; expected tcp ://host[:port][/persistence_identifier] ' );
420+ throw new CredisException ('Invalid host format; expected ' . $ this -> scheme . ' ://host[:port][/persistence_identifier] ' );
409421 }
410422 $ this ->host = $ matches [1 ];
411423 $ this ->port = (int ) (isset ($ matches [3 ]) ? $ matches [3 ] : 6379 );
412424 $ this ->persistent = isset ($ matches [5 ]) ? $ matches [5 ] : '' ;
413425 } else {
414426 $ this ->host = $ matches [2 ];
415427 $ this ->port = NULL ;
428+ $ this ->scheme = 'unix ' ;
416429 if (substr ($ this ->host ,0 ,1 ) != '/ ' ) {
417430 throw new CredisException ('Invalid unix socket format; expected unix:///path/to/redis.sock ' );
418431 }
419432 }
420433 }
421434 if ($ this ->port !== NULL && substr ($ this ->host ,0 ,1 ) == '/ ' ) {
422435 $ this ->port = NULL ;
436+ $ this ->scheme = 'unix ' ;
437+ }
438+ if (!$ this ->scheme ) {
439+ $ this ->scheme = 'tcp ' ;
423440 }
424441 }
425442 /**
@@ -436,8 +453,8 @@ public function connect()
436453 if ($ this ->standalone ) {
437454 $ flags = STREAM_CLIENT_CONNECT ;
438455 $ remote_socket = $ this ->port === NULL
439- ? ' unix :// ' .$ this ->host
440- : ' tcp :// ' .$ this ->host .': ' .$ this ->port ;
456+ ? $ this -> scheme . ' :// ' .$ this ->host
457+ : $ this -> scheme . ' :// ' .$ this ->host .': ' .$ this ->port ;
441458 if ($ this ->persistent && $ this ->port !== NULL ) {
442459 // Persistent connections to UNIX sockets are not supported
443460 $ remote_socket .= '/ ' .$ this ->persistent ;
0 commit comments