コード例 #1
0
 private function storeDebug(ICommand $command, $direction)
 {
     $firtsArg = $command->getArgument(0);
     $timestamp = round(microtime(true) - $this->tstart, 4);
     $debug = $command->getId();
     $debug .= isset($firtsArg) ? " {$firtsArg} " : ' ';
     $debug .= "{$direction} {$this}";
     $debug .= " [{$timestamp}s]";
     $this->debugBuffer[] = $debug;
 }
コード例 #2
0
 /**
  * {@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;
 }
コード例 #3
0
 /**
  * Checks if the specified command is supported by this connection class.
  *
  * @param ICommand $command The instance of a Redis command.
  * @return string
  */
 protected function getCommandId(ICommand $command)
 {
     switch ($commandId = $command->getId()) {
         case 'AUTH':
         case 'SELECT':
         case 'MULTI':
         case 'EXEC':
         case 'WATCH':
         case 'UNWATCH':
         case 'DISCARD':
             throw new \InvalidArgumentException("Disabled command: {$command->getId()}");
         default:
             return $commandId;
     }
 }
コード例 #4
0
 /**
  * Returns if the specified command performs a read-only operation
  * against a key stored on Redis.
  *
  * @param ICommand $command Instance of Redis command.
  * @return Boolean
  */
 protected function isReadOperation(ICommand $command)
 {
     if (isset($this->disallowed[$id = $command->getId()])) {
         throw new NotSupportedException("The command {$id} is not allowed in replication mode");
     }
     if (isset($this->readonly[$id])) {
         if (true === ($readonly = $this->readonly[$id])) {
             return true;
         }
         return call_user_func($readonly, $command);
     }
     if (($eval = $id === 'EVAL') || $id === 'EVALSHA') {
         $sha1 = $eval ? sha1($command->getArgument(0)) : $command->getArgument(0);
         if (isset($this->readonlySHA1[$sha1])) {
             if (true === ($readonly = $this->readonlySHA1[$sha1])) {
                 return true;
             }
             return call_user_func($readonly, $command);
         }
     }
     return false;
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function writeCommand(ICommand $command)
 {
     $cmdargs = $command->getArguments();
     array_unshift($cmdargs, $command->getId());
     $this->write(phpiredis_format_command($cmdargs));
 }
コード例 #6
0
    protected function getTestCaseBuffer(ICommand $instance)
    {
        $id = $instance->getId();
        $fqn = get_class($instance);
        $class = array_pop(explode('\\', $fqn)) . "Test";
        $realm = $this->getTestRealm();
        $buffer = <<<PHP
<?php

/*
 * This file is part of the Predis package.
 *
 * (c) Daniele Alessandri <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Predis\\Commands;

use \\PHPUnit_Framework_TestCase as StandardTestCase;

/**
 * @group commands
 * @group realm-{$realm}
 */
class {$class} extends CommandTestCase
{
    /**
     * {@inheritdoc}
     */
    protected function getExpectedCommand()
    {
        return '{$fqn}';
    }

    /**
     * {@inheritdoc}
     */
    protected function getExpectedId()
    {
        return '{$id}';
    }

    /**
     * @group disconnected
     */
    public function testFilterArguments()
    {
        \$this->markTestIncomplete('This test has not been implemented yet.');

        \$arguments = array(/* add arguments */);
        \$expected = array(/* add arguments */);

        \$command = \$this->getCommand();
        \$command->setArguments(\$arguments);

        \$this->assertSame(\$expected, \$command->getArguments());
    }

    /**
     * @group disconnected
     */
    public function testParseResponse()
    {
        \$this->markTestIncomplete('This test has not been implemented yet.');

        \$raw = null;
        \$expected = null;

        \$command = \$this->getCommand();

        \$this->assertSame(\$expected, \$command->parseResponse(\$raw));
    }

PHP;
        if ($instance instanceof IPrefixable) {
            $buffer .= <<<PHP

    /**
     * @group disconnected
     */
    public function testPrefixKeys()
    {
        \$this->markTestIncomplete('This test has not been implemented yet.');

        \$arguments = array(/* add arguments */);
        \$expected = array(/* add arguments */);

        \$command = \$this->getCommandWithArgumentsArray(\$arguments);
        \$command->prefixKeys('prefix:');

        \$this->assertSame(\$expected, \$command->getArguments());
    }

PHP;
        }
        return "{$buffer}}\n";
    }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function writeCommand(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";
     }
     $this->writeBytes($buffer);
 }
コード例 #8
0
ファイル: PredisCluster.php プロジェクト: GunioRobot/predis
 /**
  * {@inheritdoc}
  */
 public function getConnection(ICommand $command)
 {
     $cmdHash = $command->getHash($this->_distributor);
     if (isset($cmdHash)) {
         return $this->_distributor->get($cmdHash);
     }
     throw new ClientException(sprintf("Cannot send '%s' commands to a cluster of connections", $command->getId()));
 }
コード例 #9
0
ファイル: PredisCluster.php プロジェクト: Tjorriemorrie/app
 /**
  * {@inheritdoc}
  */
 public function getConnection(ICommand $command)
 {
     $cmdHash = $command->getHash($this->distributor);
     if (isset($cmdHash)) {
         return $this->distributor->get($cmdHash);
     }
     $message = sprintf("Cannot send '%s' commands to a cluster of connections", $command->getId());
     throw new NotSupportedException($message);
 }