本文整理汇总了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();
}
示例2: fork
public function fork()
{
$id = pcntl_fork();
if (!$id) {
$this->redis->disconnect();
$this->redis->connect();
}
return $id;
}
示例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());
}
}
示例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()}");
}
}
示例5: checkConnection
/**
* @return bool
*/
public function checkConnection()
{
if (!$this->predis->isConnected()) {
try {
$this->predis->connect();
return true;
} catch (ConnectionException $e) {
return false;
}
}
return true;
}
示例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);
}
}
示例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());
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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());
}
}
示例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);
}
示例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;
}
示例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);
}