コード例 #1
0
 /**
  * Creates the actual Redis Client with a given name.
  * NOTE: the client is not yet connected to a server, although the connection parameters are set.
  *
  * @param string $name the name of the connection
  * @param array $config the connection parameters
  * @throws ConnectionParametersMissingException when no connection parameters are passed
  * @throws Exception when the selected client library is unknown
  * @return PhpRedisClient|PhpIRedisClient
  */
 private function createClient($name, array $config)
 {
     if (empty($config['host']) || empty($config['port'])) {
         throw new ConnectionParametersMissingException('invalid config, host or port missing for: ' . $name);
     }
     // use the default library for 'regular'
     if ($config['type'] == 'regular') {
         $config['type'] = $this->defaultClientLibrary;
     }
     /** @var Connection */
     $inst = null;
     // different implementations possible
     switch ($config['type']) {
         case 'phpredis':
             $inst = new PhpRedisClient($name);
             break;
         case 'phpiredis':
             $inst = new PhpIRedisClient($name);
             break;
         default:
             throw new Exception('Unknown client library: ' . $config['type']);
     }
     // we set the connection parameters here, since this is the only place where we know the individual
     // connection parameters. the controller later calls connect() which uses the parameters set here.
     $inst->prepareConnect($config['host'], $config['port']);
     return $inst;
 }
コード例 #2
0
 public function testGetUniqueId()
 {
     $this->conn1->prepareConnect('host123');
     $this->conn2->prepareConnect('host14');
     $this->assertSame('host14:6379-host123:6379', $this->set->getUniqueId());
 }