1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace Predis\Protocol\Text;
- use Predis\Command\CommandInterface;
- use Predis\Protocol\CommandSerializerInterface;
- class TextCommandSerializer implements CommandSerializerInterface
- {
-
- public function serialize(CommandInterface $command)
- {
- $commandId = $command->getId();
- $arguments = $command->getArguments();
- $cmdlen = strlen($commandId);
- $reqlen = count($arguments) + 1;
- $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandId}\r\n";
- for ($i = 0; $i < $reqlen - 1; $i++) {
- $argument = $arguments[$i];
- $arglen = strlen($argument);
- $buffer .= "\${$arglen}\r\n{$argument}\r\n";
- }
- return $buffer;
- }
- }
|