php Predis-Command-CommandInterface类(方法)实例源码

下面列出了php Predis-Command-CommandInterface 类(方法)源码代码实例,从而了解它的用法。

作者:xzande    项目:predis-asyn   
/**
  * {@inheritdoc}
  */
 public function executeCommand(CommandInterface $command, callable $callback)
 {
     if ($this->buffer->isEmpty() && ($stream = $this->getResource())) {
         $this->loop->addWriteStream($stream, $this->writableCallback);
     }
     $request = $this->serializer->getRequestMessage($command->getId(), $command->getArguments());
     $this->buffer->append($request);
     $this->commands->enqueue([$command, $callback]);
 }

作者:xzande    项目:predis-asyn   
/**
  * {@inheritdoc}
  */
 public function executeCommand(CommandInterface $command, callable $callback)
 {
     if ($this->buffer->isEmpty() && ($stream = $this->getResource())) {
         $this->loop->addWriteStream($stream, $this->writableCallback);
     }
     $cmdargs = $command->getArguments();
     array_unshift($cmdargs, $command->getId());
     $this->buffer->append(phpiredis_format_command($cmdargs));
     $this->commands->enqueue([$command, $callback]);
 }

作者:kchhainaron    项目:chantuch   
/**
  * Handles a response object.
  *
  * @param  ConnectionInterface     $connection
  * @param  CommandInterface        $command
  * @param  ResponseObjectInterface $response
  * @return mixed
  */
 protected function onResponseObject(ConnectionInterface $connection, CommandInterface $command, ResponseObjectInterface $response)
 {
     if ($response instanceof ResponseErrorInterface) {
         return $this->onResponseError($connection, $response);
     }
     if ($response instanceof Iterator) {
         return $command->parseResponse(iterator_to_array($response));
     }
     return $response;
 }

作者:GeorgeBroadle    项目:caffeine-vendo   
/**
  * @param string|CommandInterface $command   Expected command ID or instance.
  * @param array                   $arguments Expected command arguments.
  */
 public function __construct($command = null, array $arguments = null)
 {
     if ($command instanceof CommandInterface) {
         $this->commandID = strtoupper($command->getId());
         $this->arguments = $arguments ?: $command->getArguments();
     } else {
         $this->commandID = strtoupper($command);
         $this->arguments = $arguments;
     }
 }

作者:flachesi    项目:predi   
private function storeDebug(CommandInterface $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;
 }

作者:cdand    项目:code-li   
/**
  * {@inheritdoc}
  */
 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";
     foreach ($arguments as $argument) {
         $arglen = strlen($argument);
         $buffer .= "\${$arglen}\r\n{$argument}\r\n";
     }
     return $buffer;
 }

作者:rodrigopbe    项目:on   
/**
  * {@inheritdoc}
  */
 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, $reqlen--; $i < $reqlen; $i++) {
         $argument = $arguments[$i];
         $arglen = strlen($argument);
         $buffer .= "\${$arglen}\r\n{$argument}\r\n";
     }
     return $buffer;
 }

作者:surji    项目:node-redis-php-chat-ap   
/**
  * {@inheritdoc}
  */
 public function writeCommand(CommandInterface $command)
 {
     $cmdargs = $command->getArguments();
     array_unshift($cmdargs, $command->getId());
     $this->write(phpiredis_format_command($cmdargs));
 }

作者:sohel4    项目:wordpress_4_1_   
/**
  * Checks if a SORT command is a readable operation by parsing the arguments
  * array of the specified commad instance.
  *
  * @param CommandInterface $command Command instance.
  *
  * @return bool
  */
 protected function isSortReadOnly(CommandInterface $command)
 {
     $arguments = $command->getArguments();
     return ($c = count($arguments)) === 1 ? true : $arguments[$c - 2] !== 'STORE';
 }

作者:kchhainaron    项目:chantuch   
/**
  * {@inheritdoc}
  */
 public function process(CommandInterface $command)
 {
     if ($command instanceof PrefixableCommandInterface && $command->getArguments()) {
         $command->prefixKeys($this->prefix);
     }
 }

作者:rubensaysh    项目:predi   
/**
  * {@inheritdoc}
  */
 public function getHash(CommandInterface $command)
 {
     $hash = $command->getHash();
     if (!isset($hash) && isset($this->commands[$cmdID = $command->getId()])) {
         if (null !== ($key = call_user_func($this->commands[$cmdID], $command))) {
             $hash = $this->hashGenerator->hash($key);
             $command->setHash($hash);
         }
     }
     return $hash;
 }

作者:creativeprogrammin    项目:NodeJS-Helpe   
/**
  * Checks if the specified command is supported by this connection class.
  *
  * @param CommandInterface $command Command instance.
  *
  * @return string
  *
  * @throws NotSupportedException
  */
 protected function getCommandId(CommandInterface $command)
 {
     switch ($commandID = $command->getId()) {
         case 'AUTH':
         case 'SELECT':
         case 'MULTI':
         case 'EXEC':
         case 'WATCH':
         case 'UNWATCH':
         case 'DISCARD':
         case 'MONITOR':
             throw new NotSupportedException("Command '{$commandID}' is not allowed by Webdis.");
         default:
             return $commandID;
     }
 }

作者:flachesi    项目:predi   
/**
  * Applies the specified prefix to the key of a MIGRATE command.
  *
  * @param CommandInterface $command Command instance.
  * @param string           $prefix  Prefix string.
  */
 public static function migrate(CommandInterface $command, $prefix)
 {
     if ($arguments = $command->getArguments()) {
         $arguments[2] = "{$prefix}{$arguments[2]}";
         $command->setRawArguments($arguments);
     }
 }

作者:sandeeprajori    项目:predi   
/**
  * Handles -ERR responses returned by Redis.
  *
  * @param CommandInterface       $command  Redis command that generated the error.
  * @param ErrorResponseInterface $response Instance of the error response.
  *
  * @throws ServerException
  * @return mixed
  *
  */
 protected function onErrorResponse(CommandInterface $command, ErrorResponseInterface $response)
 {
     if ($command instanceof ScriptCommand && $response->getErrorType() === 'NOSCRIPT') {
         $eval = $this->createCommand('EVAL');
         $eval->setRawArguments($command->getEvalArguments());
         $response = $this->executeCommand($eval);
         if (!$response instanceof ResponseInterface) {
             $response = $command->parseResponse($response);
         }
         return $response;
     }
     if ($this->options->exceptions) {
         throw new ServerException($response->getMessage());
     }
     return $response;
 }

作者:Thomv    项目:turbin   
protected function getTestCaseBuffer(CommandInterface $instance)
    {
        $id = $instance->getId();
        $fqn = get_class($instance);
        $fqnParts = explode('\\', $fqn);
        $class = array_pop($fqnParts) . "Test";
        $realm = $this->getTestRealm();
        $buffer = <<<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\\Command;

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 PrefixableCommandInterface) {
            $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());
    }

    /**
     * @group disconnected
     */
    public function testPrefixKeysIgnoredOnEmptyArguments()
//.........这里部分代码省略.........

作者:nvanh198    项目:predi   
/**
  * Handles -ERR responses returned by Redis.
  *
  * @param CommandInterface $command The command that generated the error.
  * @param ResponseErrorInterface $response The error response instance.
  * @return mixed
  */
 protected function onResponseError(CommandInterface $command, ResponseErrorInterface $response)
 {
     if ($command instanceof ScriptedCommand && $response->getErrorType() === 'NOSCRIPT') {
         $eval = $this->createCommand('eval');
         $eval->setRawArguments($command->getEvalArguments());
         return $this->executeCommand($eval);
     }
     if ($this->options->exceptions === true) {
         throw new ServerException($response->getMessage());
     }
     return $response;
 }

作者:cdand    项目:code-li   
/**
  * Applies the specified prefix to the key of a GEORADIUS command.
  *
  * @param CommandInterface $command Command instance.
  * @param string           $prefix  Prefix string.
  */
 public static function georadius(CommandInterface $command, $prefix)
 {
     if ($arguments = $command->getArguments()) {
         $arguments[0] = "{$prefix}{$arguments[0]}";
         $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4;
         if (($count = count($arguments)) > $startIndex) {
             for ($i = $startIndex; $i < $count; ++$i) {
                 switch (strtoupper($arguments[$i])) {
                     case 'STORE':
                     case 'STOREDIST':
                         $arguments[$i] = "{$prefix}{$arguments[++$i]}";
                         break;
                 }
             }
         }
         $command->setRawArguments($arguments);
     }
 }

作者:rubensaysh    项目:predi   
/**
  * {@inheritdoc}
  */
 public function writeCommand(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";
     }
     $this->writeBytes($buffer);
 }

作者:tillkrus    项目:redis-object-cach   
/**
  * Checks if a GEORADIUS command is a readable operation by parsing the
  * arguments array of the specified commad instance.
  *
  * @param CommandInterface $command Command instance.
  *
  * @return bool
  */
 protected function isGeoradiusReadOnly(CommandInterface $command)
 {
     $arguments = $command->getArguments();
     $argc = count($arguments);
     $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4;
     if ($argc > $startIndex) {
         for ($i = $startIndex; $i < $argc; ++$i) {
             $argument = strtoupper($arguments[$i]);
             if ($argument === 'STORE' || $argument === 'STOREDIST') {
                 return false;
             }
         }
     }
     return true;
 }

作者:goodww    项目:predi   
/**
  * Applies the specified prefix to the keys of Z[INTERSECTION|UNION]STORE.
  *
  * @param CommandInterface $command Command instance.
  * @param string           $prefix  Prefix string.
  */
 public static function zsetStore(CommandInterface $command, $prefix)
 {
     if ($arguments = $command->getArguments()) {
         $arguments[0] = "{$prefix}{$arguments[0]}";
         $length = (int) $arguments[1] + 2;
         for ($i = 2; $i < $length; $i++) {
             $arguments[$i] = "{$prefix}{$arguments[$i]}";
         }
         $command->setRawArguments($arguments);
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号