本文整理汇总了PHP中Predis\ClientInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface类的具体用法?PHP ClientInterface怎么用?PHP ClientInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClientInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* {@inheritdoc}
*/
public function __construct(ClientInterface $client)
{
if (!$client->getCommandFactory()->supportsCommands(array('multi', 'exec', 'discard'))) {
throw new ClientException("'MULTI', 'EXEC' and 'DISCARD' are not supported by the current command factory.");
}
parent::__construct($client);
}
示例2: __construct
/**
* {@inheritdoc}
*/
public function __construct(ClientInterface $client)
{
if (!$client->getProfile()->supportsCommands(array('multi', 'exec', 'discard'))) {
throw new ClientException("The current profile does not support 'MULTI', 'EXEC' and 'DISCARD'.");
}
parent::__construct($client);
}
示例3: createExecutor
/**
* Returns a pipeline executor depending on the kind of the underlying
* connection and the passed options.
*
* @param ClientInterface $client Client instance used by the context.
* @return PipelineExecutorInterface
*/
protected function createExecutor(ClientInterface $client)
{
$options = $client->getOptions();
if (isset($options->exceptions)) {
return new StandardExecutor($options->exceptions);
}
return new StandardExecutor();
}
示例4: assertClient
/**
* Checks if the passed client instance satisfies the required conditions
* needed to initialize a monitor consumer.
*
* @param ClientInterface $client Client instance used by the consumer.
*
* @throws NotSupportedException
*/
private function assertClient(ClientInterface $client)
{
if ($client->getConnection() instanceof AggregateConnectionInterface) {
throw new NotSupportedException('Cannot initialize a monitor consumer over aggregate connections.');
}
if ($client->getProfile()->supportsCommand('MONITOR') === false) {
throw new NotSupportedException("The current profile does not support 'MONITOR'.");
}
}
示例5: checkCapabilities
/**
* Checks if the passed client instance satisfies the required conditions
* needed to initialize a monitor context.
*
* @param ClientInterface $client Client instance used by the context.
*/
private function checkCapabilities(ClientInterface $client)
{
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
throw new NotSupportedException('Cannot initialize a monitor context when using aggregated connections');
}
if ($client->getProfile()->supportsCommand('monitor') === false) {
throw new NotSupportedException('The current profile does not support the MONITOR command');
}
}
示例6: checkCapabilities
/**
* Checks if the passed client instance satisfies the required conditions
* needed to initialize a Publish / Subscribe context.
*
* @param ClientInterface $client Client instance used by the context.
*/
private function checkCapabilities(ClientInterface $client)
{
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
throw new NotSupportedException('Cannot initialize a PUB/SUB context when using aggregated connections');
}
$commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
if ($client->getProfile()->supportsCommands($commands) === false) {
throw new NotSupportedException('The current profile does not support PUB/SUB related commands');
}
}
示例7: checkCapabilities
/**
* Checks if the client instance satisfies the required conditions needed to
* initialize a PUB/SUB consumer.
*
* @param ClientInterface $client Client instance used by the consumer.
*
* @throws NotSupportedException
*/
private function checkCapabilities(ClientInterface $client)
{
if ($client->getConnection() instanceof AggregateConnectionInterface) {
throw new NotSupportedException('Cannot initialize a PUB/SUB consumer over aggregate connections.');
}
$commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
if ($client->getCommandFactory()->supportsCommands($commands) === false) {
throw new NotSupportedException('PUB/SUB commands are not supported by the current command factory.');
}
}
示例8: configure
/**
* Configures the transaction using the provided options.
*
* @param ClientInterface $client Underlying client instance.
* @param array $options Array of options for the transaction.
* */
protected function configure(ClientInterface $client, array $options)
{
if (isset($options['exceptions'])) {
$this->exceptions = (bool) $options['exceptions'];
} else {
$this->exceptions = $client->getOptions()->exceptions;
}
if (isset($options['cas'])) {
$this->modeCAS = (bool) $options['cas'];
}
if (isset($options['watch']) && ($keys = $options['watch'])) {
$this->watchKeys = $keys;
}
if (isset($options['retry'])) {
$this->attempts = (int) $options['retry'];
}
}
示例9: broadcast
/**
* Broadcast the given event.
*
* @param array $channels
* @param string $event
* @param array $payload
* @return void
*/
public function broadcast(array $channels, $event, array $payload = [])
{
$socket = isset($payload['socket']) ? $payload['socket'] : null;
$payload = json_encode(['event' => $event, 'data' => $payload, 'socket' => $socket]);
foreach ($this->formatChannels($channels) as $channel) {
$this->redis->publish($channel, $payload);
}
}
示例10: has
/**
* @inheritdoc
*/
public function has(AggregateIdInterface $id, $version)
{
if (!$this->redis->hexists(static::KEY_NAMESPACE, (string) $id)) {
return false;
}
$snapshot = $this->serializer->deserialize($this->redis->hget(static::KEY_NAMESPACE, (string) $id), 'array', 'json');
return $snapshot['version'] === $version;
}
示例11: cacheSet
/**
* Set the cache for a token.
*
* @param $key
* @param string $value
* @param null $expiration
*/
protected function cacheSet($key, $value, $expiration = null)
{
$this->client->set($key, $value);
if (!empty($expiration)) {
$this->ttl = $expiration;
}
$this->client->expire($key, $this->ttl);
}
示例12: doEnqueue
/**
*
* @throws QueueIsDraining If the Queue is Drainable
*
* @param string $message
* @param array $options Message options (override Queue options):
*
* @return string Unique ID along the queue
*/
protected function doEnqueue($message, $options = [])
{
// Score has form <priority>.<timestamp>
$score = isset($options['score']) ? $options['score'] : 0;
if ($priority = $this->getOption('priority', false, $options)) {
$score += $priority;
}
$this->redis->zAdd($this->queueKey, $score, $message);
}
示例13: release
/**
* Releases the lock, if it has not been released already
*/
public function release()
{
if ($this->released) {
return;
}
// Only release the lock if it hasn't expired
if ($this->expire >= time()) {
$this->redis->del($this->key);
}
$this->released = true;
}
示例14: deleteGlob
private function deleteGlob($pattern)
{
$keys = $this->client->keys($pattern);
$options = $this->client->getOptions();
if (isset($options->prefix)) {
$length = strlen($options->prefix->getPrefix());
$keys = array_map(function ($key) use($length) {
return substr($key, $length);
}, $keys);
}
if (count($keys) === 0) {
return;
}
$this->client->del($keys);
}
示例15: removeIndexId
/**
* Remove an ID from an index
* @param string $id
* @param string $index
* @return void
*/
protected function removeIndexId(string $id, string $index)
{
if ($this->redis->scard($index) == 1) {
return $this->redis->del($index);
}
return $this->redis->srem($index, $id);
}