mirror of
https://github.com/predis/predis.git
synced 2026-08-25 20:09:41 +00:00
4e6ed3f26d
This is a starting point to add a documentation of the whole set of APIs and classes of Predis. The next step will be to actually improve and extend it.
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Predis\Protocol\Text;
|
|
|
|
use Predis\Commands\ICommand;
|
|
use Predis\Protocol\ICommandSerializer;
|
|
|
|
/**
|
|
* Implements a pluggable command serializer using the standard wire protocol
|
|
* defined by Redis.
|
|
*
|
|
* @link http://redis.io/topics/protocol
|
|
* @author Daniele Alessandri <suppakilla@gmail.com>
|
|
*/
|
|
class TextCommandSerializer implements ICommandSerializer
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function serialize(ICommand $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;
|
|
}
|
|
}
|