|
18 | 18 | use RedisClient\Protocol\ProtocolInterface;
|
19 | 19 | use RedisClient\Protocol\RedisProtocol;
|
20 | 20 |
|
21 |
| -/** |
22 |
| - * Class RedisClient |
23 |
| - * @package RedisClient |
24 |
| - */ |
| 21 | + |
25 | 22 | abstract class AbstractRedisClient {
|
26 | 23 |
|
27 | 24 | const VERSION = '1.0.0';
|
@@ -106,28 +103,6 @@ protected function executeCommand(array $command, array $params = null, $parserI
|
106 | 103 | return $response;
|
107 | 104 | }
|
108 | 105 |
|
109 |
| - /** |
110 |
| - * @param string[] $structure |
111 |
| - * @return mixed |
112 |
| - * @throws ErrorResponseException |
113 |
| - */ |
114 |
| - public function executeRaw($structure) { |
115 |
| - $response = $this->getProtocol()->send($structure); |
116 |
| - if ($response instanceof ErrorResponseException) { |
117 |
| - throw $response; |
118 |
| - } |
119 |
| - return $response; |
120 |
| - } |
121 |
| - |
122 |
| - /** |
123 |
| - * @param string $stringCommand |
124 |
| - * @return mixed |
125 |
| - * @throws ErrorResponseException |
126 |
| - */ |
127 |
| - public function executeRawString($stringCommand) { |
128 |
| - return $this->executeRaw(explode(' ', $stringCommand)); |
129 |
| - } |
130 |
| - |
131 | 106 | /**
|
132 | 107 | * @inheritdoc
|
133 | 108 | */
|
@@ -196,4 +171,76 @@ protected function executePipeline(PipelineInterface $Pipeline) {
|
196 | 171 | return $Pipeline->parseResponse($responses);
|
197 | 172 | }
|
198 | 173 |
|
| 174 | + /** |
| 175 | + * @param string[] $structure |
| 176 | + * @return mixed |
| 177 | + * @throws ErrorResponseException |
| 178 | + */ |
| 179 | + public function executeRaw($structure) { |
| 180 | + $response = $this->getProtocol()->send($structure); |
| 181 | + if ($response instanceof ErrorResponseException) { |
| 182 | + throw $response; |
| 183 | + } |
| 184 | + return $response; |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * @param string $command |
| 189 | + * @return mixed |
| 190 | + */ |
| 191 | + public function executeRawString($command) { |
| 192 | + return $this->executeRaw($this->parseRawString($command)); |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * @param string $command |
| 197 | + * @return string[] |
| 198 | + */ |
| 199 | + public function parseRawString($command) { |
| 200 | + $structure = []; |
| 201 | + $line = ''; $quotes = false; |
| 202 | + for ($i = 0, $length = strlen($command); $i <= $length; ++$i) { |
| 203 | + if ($i === $length) { |
| 204 | + if (isset($line[0])) { |
| 205 | + $structure[] = $line; |
| 206 | + $line = ''; |
| 207 | + } |
| 208 | + break; |
| 209 | + } |
| 210 | + if ($command[$i] === '"' && $i && $command[$i - 1] !== '\\') { |
| 211 | + $quotes = !$quotes; |
| 212 | + if (!$quotes && !isset($line[0]) && $i + 1 === $length) { |
| 213 | + $structure[] = $line; |
| 214 | + $line = ''; |
| 215 | + } |
| 216 | + } else if ($command[$i] === ' ' && !$quotes) { |
| 217 | + if (isset($command[$i + 1]) && trim($command[$i + 1])) { |
| 218 | + if (count($structure) || isset($line[0])) { |
| 219 | + $structure[] = $line; |
| 220 | + $line = ''; |
| 221 | + } |
| 222 | + } |
| 223 | + } else { |
| 224 | + $line .= $command[$i]; |
| 225 | + } |
| 226 | + } |
| 227 | + array_walk($structure, function(&$line) { |
| 228 | + $line = str_replace('\\"', '"', $line); |
| 229 | + }); |
| 230 | + return $structure; |
| 231 | + } |
| 232 | + |
| 233 | + /** |
| 234 | + * @param string $name |
| 235 | + * @param array $arguments |
| 236 | + * @return mixed |
| 237 | + * @throws \Exception |
| 238 | + */ |
| 239 | + public function __call($name , array $arguments) { |
| 240 | + if ($method = $this->getMethodNameForReservedWord($name)) { |
| 241 | + return call_user_func_array([$this, $method], $arguments); |
| 242 | + } |
| 243 | + throw new \Exception('Call to undefined method '. static::class. '::'. $name); |
| 244 | + } |
| 245 | + |
199 | 246 | }
|
0 commit comments