|
15 | 15 |
|
16 | 16 | namespace phpFastCache\Drivers\Redis; |
17 | 17 |
|
18 | | -use phpFastCache\Core\Pool\{DriverBaseTrait, ExtendedCacheItemPoolInterface}; |
| 18 | +use phpFastCache\Core\Pool\{ |
| 19 | + DriverBaseTrait, ExtendedCacheItemPoolInterface |
| 20 | +}; |
19 | 21 | use phpFastCache\Entities\DriverStatistic; |
20 | 22 | use phpFastCache\Exceptions\{ |
21 | 23 | phpFastCacheInvalidArgumentException, phpFastCacheLogicException |
@@ -53,18 +55,27 @@ protected function driverConnect(): bool |
53 | 55 | $clientConfig = $this->getConfig(); |
54 | 56 | $this->instance = $this->instance ?: new RedisClient(); |
55 | 57 |
|
56 | | - if (!$this->instance->connect($clientConfig[ 'host' ], (int)$clientConfig[ 'port' ], (float)$clientConfig[ 'timeout' ])) { |
57 | | - return false; |
| 58 | + /** |
| 59 | + * If path is provided we consider it as an UNIX Socket |
| 60 | + */ |
| 61 | + if ($clientConfig[ 'path' ]) { |
| 62 | + $isConnected = $this->instance->connect($clientConfig[ 'path' ]); |
58 | 63 | } else { |
| 64 | + $isConnected = $this->instance->connect($clientConfig[ 'host' ], (int)$clientConfig[ 'port' ], (int)$clientConfig[ 'timeout' ]); |
| 65 | + } |
| 66 | + |
| 67 | + if (!$isConnected && $clientConfig[ 'path' ]) { |
| 68 | + return false; |
| 69 | + } else if (!$clientConfig[ 'path' ]) { |
59 | 70 | if ($clientConfig[ 'password' ] && !$this->instance->auth($clientConfig[ 'password' ])) { |
60 | 71 | return false; |
61 | 72 | } |
62 | | - if ($clientConfig[ 'database' ]) { |
63 | | - $this->instance->select((int)$clientConfig[ 'database' ]); |
64 | | - } |
| 73 | + } |
65 | 74 |
|
66 | | - return true; |
| 75 | + if ($clientConfig[ 'database' ]) { |
| 76 | + $this->instance->select((int)$clientConfig[ 'database' ]); |
67 | 77 | } |
| 78 | + return true; |
68 | 79 | } |
69 | 80 | } |
70 | 81 |
|
@@ -120,7 +131,7 @@ protected function driverDelete(CacheItemInterface $item): bool |
120 | 131 | * Check for Cross-Driver type confusion |
121 | 132 | */ |
122 | 133 | if ($item instanceof Item) { |
123 | | - return (bool) $this->instance->del($item->getKey()); |
| 134 | + return (bool)$this->instance->del($item->getKey()); |
124 | 135 | } else { |
125 | 136 | throw new phpFastCacheInvalidArgumentException('Cross-Driver type confusion detected'); |
126 | 137 | } |
@@ -152,7 +163,7 @@ public function getStats(): DriverStatistic |
152 | 163 | return (new DriverStatistic()) |
153 | 164 | ->setData(implode(', ', array_keys($this->itemInstances))) |
154 | 165 | ->setRawData($info) |
155 | | - ->setSize((int) $info[ 'used_memory' ]) |
| 166 | + ->setSize((int)$info[ 'used_memory' ]) |
156 | 167 | ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", |
157 | 168 | $info[ 'redis_version' ], $date->format(DATE_RFC2822))); |
158 | 169 | } |
|
0 commit comments