From e1be8a06a88548f625dcef47be093557953837fa Mon Sep 17 00:00:00 2001 From: Roman Kovalenko Date: Fri, 14 Aug 2015 11:01:21 +0300 Subject: [PATCH] Opportunity of connection via unix socket. When we have option useSocket, but the value is different from true and we cant get connection class - use default connection class. --- library/Rediska.php | 2 ++ library/Rediska/Connection.php | 7 ++++++- library/Rediska/Connection/UnixSocket.php | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 library/Rediska/Connection/UnixSocket.php diff --git a/library/Rediska.php b/library/Rediska.php index 46f6c4e..6e0df39 100644 --- a/library/Rediska.php +++ b/library/Rediska.php @@ -251,6 +251,8 @@ public function addServer($host, $port = Rediska_Connection::DEFAULT_PORT, array if (isset($options['useSocket'])) { if ($options['useSocket'] == true) { $connectionClass = static::CONNECTION_SOCKET_CLASS; + } else { + $connectionClass = static::CONNECTION_CLASS; } unset($options['useSocket']); } else { diff --git a/library/Rediska/Connection.php b/library/Rediska/Connection.php index b361cb3..ad2daa4 100644 --- a/library/Rediska/Connection.php +++ b/library/Rediska/Connection.php @@ -64,7 +64,7 @@ class Rediska_Connection extends Rediska_Options public function connect() { if (!$this->isConnected()) { - $socketAddress = 'tcp://' . $this->getHost() . ':' . $this->getPort(); + $socketAddress = $this->getSocketAddress(); if ($this->_options['persistent']) { $flag = STREAM_CLIENT_PERSISTENT | STREAM_CLIENT_CONNECT; @@ -136,6 +136,11 @@ public function connect() } } + public function getSocketAddress() + { + return 'tcp://' . $this->getHost() . ':' . $this->getPort(); + } + /** * Disconnect * diff --git a/library/Rediska/Connection/UnixSocket.php b/library/Rediska/Connection/UnixSocket.php new file mode 100644 index 0000000..ce361bc --- /dev/null +++ b/library/Rediska/Connection/UnixSocket.php @@ -0,0 +1,22 @@ +getHost(); + } +}