當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::connect方法代碼示例

本文整理匯總了PHP中Predis\Client::connect方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::connect方法的具體用法?PHP Client::connect怎麽用?PHP Client::connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Predis\Client的用法示例。


在下文中一共展示了Client::connect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param $sourceConfig connection URI string (tcp://10.0.0.1:6379)
  * @param $destinationConfig connection URI string (tcp://10.0.0.1:6379)
  * @throws Predis\Connection\ConnectionException
  */
 public function __construct($sourceConfig, $destinationConfig)
 {
     $this->source = new Client($sourceConfig);
     $this->destination = new Client($destinationConfig);
     $this->source->connect();
     $this->destination->connect();
 }
開發者ID:becquerel,項目名稱:redis-copy,代碼行數:12,代碼來源:RedisCopy.php

示例2: fork

 public function fork()
 {
     $id = pcntl_fork();
     if (!$id) {
         $this->redis->disconnect();
         $this->redis->connect();
     }
     return $id;
 }
開發者ID:halaei,項目名稱:redis-hyper-queue,代碼行數:9,代碼來源:IntegrationTestCase.php

示例3: connect

 /**
  * Creates a connect to Redis or Sentinel using the Predis\Client object.  It proxies the connecting and converts
  * specific client exceptions to more generic adapted ones in PSRedis
  *
  * @throws \PSRedis\Exception\ConnectionError
  */
 public function connect()
 {
     try {
         $this->predisClient = $this->predisClientFactory->createClient($this->clientType, $this->getPredisClientParameters());
         $this->predisClient->connect();
         $this->isConnected = $this->predisClient->isConnected();
     } catch (ConnectionException $e) {
         throw new ConnectionError($e->getMessage());
     }
 }
開發者ID:hemingw,項目名稱:PSRedis,代碼行數:16,代碼來源:PredisClientAdapter.php

示例4: init

 public function init()
 {
     $settings = Config::get('ajumamoro:broker');
     unset($settings['driver']);
     $this->redis = new \Predis\Client($settings);
     try {
         $this->redis->connect();
     } catch (\Predis\CommunicationException $ex) {
         throw new BrokerConnectionException("Failed to connect to redis broker: {$ex->getMessage()}");
     }
 }
開發者ID:ekowabaka,項目名稱:ajumamoro,代碼行數:11,代碼來源:RedisBroker.php

示例5: checkConnection

 /**
  * @return bool
  */
 public function checkConnection()
 {
     if (!$this->predis->isConnected()) {
         try {
             $this->predis->connect();
             return true;
         } catch (ConnectionException $e) {
             return false;
         }
     }
     return true;
 }
開發者ID:gerifield,項目名稱:little-red-queue,代碼行數:15,代碼來源:LittleRedQueue.php

示例6: list

 function __construct($url)
 {
     try {
         list($user, $passwd, $host, $port, $db) = self::parseRedisUrl($url);
         $this->_redis = new Client(array('host' => $host, 'port' => $port));
     } catch (\Exception $e) {
         throw new RedisBundleException($e);
     }
     try {
         $this->_redis->connect();
         $this->_redis->select($db);
     } catch (\Predis\Connection\ConnectionException $e) {
         throw new RedisBundleException($e);
     }
 }
開發者ID:haberberger,項目名稱:redisstoragebundle,代碼行數:15,代碼來源:RedisStorage.php

示例7: testDispatcherLoopAgainstRedisServer

 /**
  * @group connected
  */
 public function testDispatcherLoopAgainstRedisServer()
 {
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT, 'database' => REDIS_SERVER_DBNUM, 'read_write_timeout' => 2);
     $producer = new Client($parameters, REDIS_SERVER_VERSION);
     $producer->connect();
     $consumer = new Client($parameters, REDIS_SERVER_VERSION);
     $consumer->connect();
     $dispatcher = new DispatcherLoop($consumer);
     $function01 = $this->getMock('stdClass', array('__invoke'));
     $function01->expects($this->exactly(2))->method('__invoke')->with($this->logicalOr($this->equalTo('01:argument'), $this->equalTo('01:quit')))->will($this->returnCallback(function ($arg) use($dispatcher) {
         if ($arg === '01:quit') {
             $dispatcher->stop();
         }
     }));
     $function02 = $this->getMock('stdClass', array('__invoke'));
     $function02->expects($this->once())->method('__invoke')->with('02:argument');
     $function03 = $this->getMock('stdClass', array('__invoke'));
     $function03->expects($this->never())->method('__invoke');
     $dispatcher->attachCallback('function:01', $function01);
     $dispatcher->attachCallback('function:02', $function02);
     $dispatcher->attachCallback('function:03', $function03);
     $producer->publish('function:01', '01:argument');
     $producer->publish('function:02', '02:argument');
     $producer->publish('function:01', '01:quit');
     $dispatcher->run();
     $this->assertTrue($consumer->ping());
 }
開發者ID:keneanung,項目名稱:gw2spidy,代碼行數:30,代碼來源:DispatcherLoopTest.php

示例8: testHandleLogWithGoodMessageNotImplementingJobInterface

 public function testHandleLogWithGoodMessageNotImplementingJobInterface()
 {
     $worker = new WorkerPresence();
     $worker->setMemory(12345);
     $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $worker->toJson());
     $loop = LoopFactory::create();
     $options = array('eventloop' => $loop, 'on_error' => array($this, 'throwRedisError'));
     $redisSync = new PredisSync('tcp://127.0.0.1:6379');
     $redisSync->connect();
     $resolver = $this->getResolver();
     $resolver->expects($this->once())->method('ack');
     $done = false;
     $phpunit = $this;
     $redis = new PredisAsync('tcp://127.0.0.1:6379', $options);
     $redis->connect(function () use($resolver, $phpunit, $redis, $frame, $redisSync, &$done, $worker) {
         $component = new LogBuilderComponent();
         $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done, $worker) {
             $redis->disconnect();
             $phpunit->assertEquals($worker->toJson(), $redisSync->get($hashId));
             $phpunit->assertTrue($redisSync->sismember('garbages', $hashId));
             $done = true;
         });
     });
     $loop->run();
     $this->assertTrue($done);
 }
開發者ID:gloubster,項目名稱:server,代碼行數:26,代碼來源:LogBuilderComponentTest.php

示例9: getClient

 /**
  * Returns a new client instance.
  *
  * @return Client
  */
 protected function getClient()
 {
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT, 'iterable_multibulk' => true, 'read_write_timeout' => 2);
     $client = new Client($parameters, REDIS_SERVER_VERSION);
     $client->connect();
     $client->select(REDIS_SERVER_DBNUM);
     $client->flushdb();
     return $client;
 }
開發者ID:keneanung,項目名稱:gw2spidy,代碼行數:14,代碼來源:MultiBulkResponseTupleTest.php

示例10: __construct

 /**
  * ### Tries to connect to the configured redis database
  *
  * RedisCache constructor.
  */
 public function __construct()
 {
     $client = new Client(['scheme' => 'tcp', 'host' => Config::get('cache', 'redis_server.host'), 'port' => Config::get('cache', 'redis_server.port'), 'database' => Config::get('cache', 'redis_server.database')]);
     try {
         $client->connect();
     } catch (\Exception $e) {
         throw new RedisException('Connection to redis server failed. Please check your settings.');
     }
     $this->conn = $client;
 }
開發者ID:JanFoerste,項目名稱:blivy-website,代碼行數:15,代碼來源:RedisCache.php

示例11: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $client = new Client();
     try {
         $client->connect();
         $client->disconnect();
         self::$supported = true;
     } catch (ConnectionException $e) {
         self::$supported = false;
     }
 }
開發者ID:kormik,項目名稱:manager,代碼行數:12,代碼來源:PredisStoreGeneratorTest.php

示例12: setUp

 public function setUp()
 {
     // connect to a redis daemon
     $predis = new Predis(array('host' => $_ENV['redis_host'], 'port' => $_ENV['redis_port']));
     // set it
     $this->storage = new Redis($predis, 'test_user_token', 'test_user_state');
     try {
         $predis->connect();
     } catch (\Predis\Connection\ConnectionException $e) {
         $this->markTestSkipped('No redis instance available: ' . $e->getMessage());
     }
 }
開發者ID:Flesh192,項目名稱:magento,代碼行數:12,代碼來源:RedisTest.php

示例13: setUp

 public function setUp()
 {
     if (!class_exists('Predis\\Client')) {
         $this->markTestSkipped('The ' . __CLASS__ . ' requires Predis to be available');
     }
     try {
         $client = new Client();
         $client->connect();
         $client->flushdb();
     } catch (ConnectionException $e) {
         $this->markTestSkipped('The ' . __CLASS__ . ' requires the use of a Redis Server');
     }
     $this->storage = new RedisStorage($client);
 }
開發者ID:battlerattle,項目名稱:shuffle-bag,代碼行數:14,代碼來源:RedisStorageTest.php

示例14: getClient

 /**
  * Returns a new client instance.
  *
  * @param Boolean $connect Flush selected database before returning the client.
  * @return Client
  */
 protected function getClient($flushdb = true)
 {
     $profile = $this->getProfile();
     if (!$profile->supportsCommand($id = $this->getExpectedId())) {
         $this->markTestSkipped("The profile {$profile->getVersion()} does not support command {$id}");
     }
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT);
     $options = array('profile' => $profile);
     $client = new Client($parameters, $options);
     $client->connect();
     $client->select(REDIS_SERVER_DBNUM);
     if ($flushdb) {
         $client->flushdb();
     }
     return $client;
 }
開發者ID:surjit,項目名稱:node-redis-php-chat-app,代碼行數:22,代碼來源:CommandTestCase.php

示例15: test_published_messages_fire_event_listeners_when_rechech_called

 public function test_published_messages_fire_event_listeners_when_rechech_called()
 {
     $redis = new Client();
     $pubsub = new RedisPubSub($redis);
     try {
         $redis->connect();
     } catch (ConnectionException $e) {
         $this->markTestSkipped("Test skipped because no Redis server is running on default ports");
     }
     $value = null;
     $pubsub->on('foo', function ($data) use(&$value) {
         $value = $data;
     });
     $pubsub->publish('foo', 'bar');
     $pubsub->recheck('foo');
     $this->assertEquals('bar', $value);
 }
開發者ID:adamnicholson,項目名稱:kyew,代碼行數:17,代碼來源:RedisPubSubTest.php


注:本文中的Predis\Client::connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。