本文整理汇总了PHP中Predis\Profile\ServerProfile::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerProfile::get方法的具体用法?PHP ServerProfile::get怎么用?PHP ServerProfile::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Profile\ServerProfile
的用法示例。
在下文中一共展示了ServerProfile::get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidationAcceptsProfileInstancesAsValue
/**
* @group disconnected
*/
public function testValidationAcceptsProfileInstancesAsValue()
{
$value = ServerProfile::get('2.0');
$options = $this->getMock('Predis\\Option\\ClientOptionsInterface');
$option = new ClientProfile();
$profile = $option->filter($options, $value);
$this->assertInstanceOf('Predis\\Profile\\ServerProfileInterface', $profile);
$this->assertEquals('2.0', $profile->getVersion());
$this->assertNull($profile->getProcessor());
}
示例2: filter
/**
* {@inheritdoc}
*/
public function filter(ClientOptionsInterface $options, $value)
{
if (is_string($value)) {
$value = ServerProfile::get($value);
if (isset($options->prefix)) {
$value->setProcessor($options->prefix);
}
}
if (is_callable($value)) {
$value = call_user_func($value, $options, $this);
}
if (!$value instanceof ServerProfileInterface) {
throw new \InvalidArgumentException('Invalid value for the profile option');
}
return $value;
}
示例3: testConstructorWithNullAndArrayArgument
/**
* @group disconnected
*/
public function testConstructorWithNullAndArrayArgument()
{
$factory = $this->getMock('Predis\\Connection\\ConnectionFactoryInterface');
$arg2 = array('profile' => '2.0', 'prefix' => 'prefix:', 'connections' => $factory);
$client = new Client(null, $arg2);
$profile = $client->getProfile();
$this->assertSame($profile->getVersion(), ServerProfile::get('2.0')->getVersion());
$this->assertInstanceOf('Predis\\Command\\Processor\\KeyPrefixProcessor', $profile->getProcessor());
$this->assertSame('prefix:', $profile->getProcessor()->getPrefix());
$this->assertSame($factory, $client->getConnectionFactory());
}
示例4: testToString
/**
* @group disconnected
*/
public function testToString()
{
$this->assertEquals('2.0', (string) ServerProfile::get('2.0'));
}
示例5: getProfile
/**
* Return the server profile used during the tests.
*
* @return ServerProfileInterface
*/
protected function getProfile()
{
return ServerProfile::get(REDIS_SERVER_VERSION);
}
示例6: testClosingContextWithFalseSendsUnsubscriptions
/**
* @group disconnected
*/
public function testClosingContextWithFalseSendsUnsubscriptions()
{
$profile = ServerProfile::get(REDIS_SERVER_VERSION);
$classUnsubscribe = $profile->getCommandClass('unsubscribe');
$classPunsubscribe = $profile->getCommandClass('punsubscribe');
$connection = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
$client = $this->getMock('Predis\\Client', array('disconnect'), array($connection));
$options = array('subscribe' => 'channel:foo', 'psubscribe' => 'channels:*');
$pubsub = new PubSubContext($client, $options);
$connection->expects($this->exactly(2))->method('writeCommand')->with($this->logicalOr($this->isInstanceOf($classUnsubscribe), $this->isInstanceOf($classPunsubscribe)));
$pubsub->closeContext(false);
}
示例7: getScript
local hashes = {}
for _, key in pairs(KEYS) do
table.insert(hashes, key)
table.insert(hashes, redis.call('hgetall', key))
end
return hashes
EOS;
public function getScript()
{
return self::BODY;
}
}
// ------------------------------------------------------------------------- //
$parameters = array('tcp://127.0.0.1:6379/?alias=master', 'tcp://127.0.0.1:6380/?alias=slave');
$options = array('profile' => function ($options) {
$profile = ServerProfile::get('2.6');
$profile->defineCommand('hmgetall', 'HashMultipleGetAll');
return $profile;
}, 'replication' => function ($options) {
$replication = new MasterSlaveReplication();
$replication->setScriptReadOnly(HashMultipleGetAll::BODY);
return $replication;
});
// ------------------------------------------------------------------------- //
$client = new Predis\Client($parameters, $options);
// Execute the following commands on the master server using redis-cli:
// $ ./redis-cli HMSET metavars foo bar hoge piyo
// $ ./redis-cli HMSET servers master host1 slave host2
$hashes = $client->hmgetall('metavars', 'servers');
$replication = $client->getConnection();
$stillOnSlave = $replication->getCurrent() === $replication->getConnectionById('slave');
示例8: testConstructorWithNullAndArrayArgument
/**
* @group disconnected
* @todo How should we test for the error callback?
*/
public function testConstructorWithNullAndArrayArgument()
{
$options = array('profile' => '2.0', 'prefix' => 'prefix:', 'eventloop' => $loop = $this->getEventLoop(), 'on_error' => $callback = function ($client, $error) {
});
$client = new Client(null, $options);
$profile = $client->getProfile();
$this->assertSame($profile->getVersion(), ServerProfile::get('2.0')->getVersion());
$this->assertInstanceOf('Predis\\Command\\Processor\\KeyPrefixProcessor', $profile->getProcessor());
$this->assertSame('prefix:', $profile->getProcessor()->getPrefix());
$this->assertSame($loop, $client->getEventLoop());
}
示例9: getProfile
/**
* Returns a new instance of server profile.
*
* @param string $version Redis profile.
* @return ServerProfileInterface
*/
protected function getProfile($version = null)
{
return ServerProfile::get($version ?: REDIS_SERVER_VERSION);
}
示例10: testIterationRewindable
/**
* @group disconnected
*/
public function testIterationRewindable()
{
$client = $this->getMock('Predis\\Client', array('getProfile', 'zscan'));
$client->expects($this->any())->method('getProfile')->will($this->returnValue(ServerProfile::get('2.8')));
$client->expects($this->exactly(2))->method('zscan')->with('key:zset', 0, array())->will($this->returnValue(array(0, array(array('member:1st', 1.0), array('member:2nd', 2.0)))));
$iterator = new SortedSetKey($client, 'key:zset');
$iterator->rewind();
$this->assertTrue($iterator->valid());
$this->assertSame(1.0, $iterator->current());
$this->assertSame('member:1st', $iterator->key());
$iterator->rewind();
$this->assertTrue($iterator->valid());
$this->assertSame(1.0, $iterator->current());
$this->assertSame('member:1st', $iterator->key());
$iterator->next();
$this->assertTrue($iterator->valid());
$this->assertSame(2.0, $iterator->current());
$this->assertSame('member:2nd', $iterator->key());
$iterator->next();
$this->assertFalse($iterator->valid());
}
示例11: testCanSetReadOnlyFlagForEvalScripts
/**
* @group disconnected
*/
public function testCanSetReadOnlyFlagForEvalScripts()
{
$profile = ServerProfile::get('dev');
$cmdEval = $profile->createCommand('eval', array($script = "return redis.call('info');"));
$cmdEvalSha = $profile->createCommand('evalsha', array($scriptSHA1 = sha1($script)));
$master = $this->getMockConnection('tcp://host1?alias=master');
$master->expects($this->never())->method('executeCommand');
$slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
$slave1->expects($this->exactly(2))->method('executeCommand')->with($this->logicalOr($cmdEval, $cmdEvalSha));
$replication = new MasterSlaveReplication();
$replication->add($master);
$replication->add($slave1);
$replication->setScriptReadOnly($script);
$replication->executeCommand($cmdEval);
$replication->executeCommand($cmdEvalSha);
}
示例12: testIterationRewindable
/**
* @group disconnected
*/
public function testIterationRewindable()
{
$client = $this->getMock('Predis\\Client', array('getProfile', 'scan'));
$client->expects($this->any())->method('getProfile')->will($this->returnValue(ServerProfile::get('2.8')));
$client->expects($this->exactly(2))->method('scan')->with(0, array())->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
$iterator = new Keyspace($client);
$iterator->rewind();
$this->assertTrue($iterator->valid());
$this->assertSame('key:1st', $iterator->current());
$this->assertSame(0, $iterator->key());
$iterator->rewind();
$this->assertTrue($iterator->valid());
$this->assertSame('key:1st', $iterator->current());
$this->assertSame(0, $iterator->key());
$iterator->next();
$this->assertTrue($iterator->valid());
$this->assertSame(1, $iterator->key());
$this->assertSame('key:2nd', $iterator->current());
$iterator->next();
$this->assertFalse($iterator->valid());
}
示例13: loadPredisClient
/**
* Loads a redis client using predis.
*
* @param array $client A client configuration
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function loadPredisClient(array $client, ContainerBuilder $container)
{
if (null === $client['options']['cluster']) {
unset($client['options']['cluster']);
}
// predis connection parameters have been renamed in v0.8
$client['options']['async_connect'] = $client['options']['connection_async'];
$client['options']['timeout'] = $client['options']['connection_timeout'];
$client['options']['persistent'] = $client['options']['connection_persistent'];
$client['options']['exceptions'] = $client['options']['throw_errors'];
unset($client['options']['connection_async']);
unset($client['options']['connection_timeout']);
unset($client['options']['connection_persistent']);
unset($client['options']['throw_errors']);
$connectionAliases = array();
$connectionCount = count($client['dsns']);
foreach ($client['dsns'] as $i => $dsn) {
/** @var \Snc\RedisBundle\DependencyInjection\Configuration\RedisDsn $dsn */
if (!($connectionAlias = $dsn->getAlias())) {
$connectionAlias = 1 === $connectionCount ? $client['alias'] : $client['alias'] . ($i + 1);
}
$connectionAliases[] = $connectionAlias;
$connection = $client['options'];
$connection['logging'] = $client['logging'];
$connection['alias'] = $connectionAlias;
if (null !== $dsn->getSocket()) {
$connection['scheme'] = 'unix';
$connection['path'] = $dsn->getSocket();
} else {
$connection['scheme'] = 'tcp';
$connection['host'] = $dsn->getHost();
$connection['port'] = $dsn->getPort();
}
if (null !== $dsn->getDatabase()) {
$connection['database'] = $dsn->getDatabase();
}
$connection['password'] = $dsn->getPassword();
$connection['weight'] = $dsn->getWeight();
$this->loadPredisConnectionParameters($client['alias'], $connection, $container);
}
// TODO can be shared between clients?!
$profileId = sprintf('snc_redis.client.%s_profile', $client['alias']);
$profileDef = new Definition(get_class(\Predis\Profile\ServerProfile::get($client['options']['profile'])));
// TODO get_class alternative?
$profileDef->setPublic(false);
$profileDef->setScope(ContainerInterface::SCOPE_CONTAINER);
if (null !== $client['options']['prefix']) {
$processorId = sprintf('snc_redis.client.%s_processor', $client['alias']);
$processorDef = new Definition('Predis\\Command\\Processor\\KeyPrefixProcessor');
$processorDef->setArguments(array($client['options']['prefix']));
$container->setDefinition($processorId, $processorDef);
$profileDef->addMethodCall('setProcessor', array(new Reference($processorId)));
}
$container->setDefinition($profileId, $profileDef);
$client['options']['profile'] = new Reference($profileId);
$optionId = sprintf('snc_redis.client.%s_options', $client['alias']);
$optionDef = new Definition($container->getParameter('snc_redis.client_options.class'));
$optionDef->setPublic(false);
$optionDef->setScope(ContainerInterface::SCOPE_CONTAINER);
$optionDef->addArgument($client['options']);
$container->setDefinition($optionId, $optionDef);
$clientDef = new Definition($container->getParameter('snc_redis.client.class'));
$clientDef->setScope(ContainerInterface::SCOPE_CONTAINER);
if (1 === $connectionCount) {
$clientDef->addArgument(new Reference(sprintf('snc_redis.connection.%s_parameters', $connectionAliases[0])));
} else {
$connections = array();
foreach ($connectionAliases as $alias) {
$connections[] = new Reference(sprintf('snc_redis.connection.%s_parameters', $alias));
}
$clientDef->addArgument($connections);
}
$clientDef->addArgument(new Reference($optionId));
$container->setDefinition(sprintf('snc_redis.%s', $client['alias']), $clientDef);
$container->setAlias(sprintf('snc_redis.%s_client', $client['alias']), sprintf('snc_redis.%s', $client['alias']));
}
示例14: getOptions
/**
* Returns a new instance of client options.
*
* @return ClientOptions
* @param array $override Override default options.
*/
protected function getOptions($override = null)
{
$options = new ClientOptions(array_merge(array('profile' => ServerProfile::get(REDIS_SERVER_VERSION), 'eventloop' => $this->getEventLoop())), $override ?: array());
return $options;
}