Example #1
0
 /**
  * Returns the wrapped Redis client instance.
  *
  * This method is called from AbstractRedisWrapper, who uses it to call the desired method directly
  * on the wrapped redis, rather than using call_user_func().
  * The command and key are passed into the method to allow for some logic within the implementations
  * of this method.
  *
  * @param string $command the current command
  * @param string|null $key the current key if available, null otherwise. Commands that operate on
  * multiple keys will pass their keys as a comma separated string.
  * @return Redis
  */
 protected function getWrappedRedis($command, $key = null)
 {
     // we are doing a linear search here with in_array(), if this proves too slow, we could change
     // over to an associative array which has the commands as key and the connections as values.
     // this method would then shorten too: return $this->clients[self::$commands[$command]];
     // see whether it's a read command or whether we are in multi mode
     // due to complications with mixed read and write commands in multi mode, we decided to use only
     // the write connection when its active
     if (!$this->inMultiMode && $this->commandHelper->isReadCommand($command)) {
         return $this->getClientByKey('r');
     }
     // everything that's not a read command is a write command. this is also our fallback, so we don't
     // do an additional search over $this->commandHelper
     return $this->getClientByKey('w');
 }
Example #2
0
 public function testCommands()
 {
     $ch = new CommandHelper();
     $this->assertTrue($ch->isReadCommand('get'));
     $this->assertTrue($ch->isReadCommand('GET'));
     $this->assertTrue($ch->isReadCommand('smembers'));
     $this->assertTrue($ch->isReadCommand('sMembers'));
     $this->assertFalse($ch->isWriteCommand('get'));
     $this->assertFalse($ch->isWriteCommand('sMembers'));
     $this->assertTrue($ch->isWriteCommand('set'));
     $this->assertTrue($ch->isWriteCommand('SET'));
     $this->assertTrue($ch->isWriteCommand('lpush'));
     $this->assertTrue($ch->isWriteCommand('lPush'));
     $this->assertFalse($ch->isReadCommand('set'));
     $this->assertFalse($ch->isReadCommand('lPush'));
 }