Esempio n. 1
0
 public function __call($name, $args)
 {
     if (strtolower($name) == 'on' && isset($args[0])) {
         $this->_rediska->on($args[0]);
         $this->_oneTimeConnection = $this->_specifiedConnection->getConnection();
         return $this;
     }
     if ($this->_oneTimeConnection) {
         $connection = $this->_oneTimeConnection;
         $this->_oneTimeConnection = null;
     } else {
         $connection = $this->_defaultConnection;
     }
     if ($connection !== null) {
         $this->_specifiedConnection->setConnection($connection);
     } else {
         $this->_specifiedConnection->resetConnection();
     }
     $command = $this->_rediska->getCommand($name, $args);
     if (!$command->isAtomic()) {
         throw new Rediska_Exception("Command '{$name}' doesn't work properly (not atomic) in pipeline on multiple servers");
     }
     $this->_commands[] = $command;
     $this->_specifiedConnection->resetConnection();
     return $this;
 }
Esempio n. 2
0
 /**
  * Get all Rediska connection instances
  * 
  * @throws Rediska_Connection_Exception
  * @return array
  */
 public function getConnections()
 {
     if ($this->_specifiedConnection->getConnection()) {
         return array($this->_specifiedConnection->getConnection());
     } else {
         return array_values($this->_connections);
     }
 }
Esempio n. 3
0
 /**
  * Magic method for add command to pipeline
  *
  * @param string $name Command name
  * @param array  $args Arguments
  * @return Rediska_Pipeline
  */
 public function __call($name, $args)
 {
     if (strtolower($name) == 'on' && isset($args[0])) {
         $this->_rediska->on($args[0]);
         $this->_oneTimeConnection = $this->_specifiedConnection->getConnection();
         return $this;
     }
     // TODO: Implement transaction and config
     if (in_array(strtolower($name), array('transaction', 'config'))) {
         throw new Rediska_Exception("{$name} in pipeline not implemented yet.");
     }
     if (in_array(strtolower($name), array('monitor', 'subscribe'))) {
         throw new Rediska_Transaction_Exception("You can't use '{$name}' in pipeline");
     }
     return $this->_addCommand($name, $args);
 }
Esempio n. 4
0
 /**
  * Get Redis server configuration
  *
  * @param $aliasOrConnection Server alias or Rediska_Connection object
  * @return Rediska_Config
  */
 public function config($aliasOrConnection = null)
 {
     if ($aliasOrConnection instanceof Rediska_Connection) {
         $connection = $aliasOrConnection;
     } elseif ($aliasOrConnection !== null) {
         $connection = $this->getConnectionByAlias($aliasOrConnection);
     } elseif ($this->_specifiedConnection->getConnection()) {
         $connection = $this->_specifiedConnection->getConnection();
     } else {
         $connections = $this->getConnections();
         if (count($connections) == 1) {
             $connection = $connections[0];
         } else {
             throw new Rediska_Transaction_Exception('You must specify connection by $aliasOrConnection argument!');
         }
     }
     return new Rediska_Config($this, $connection);
 }