本文整理汇总了PHP中Predis\Client::multiExec方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::multiExec方法的具体用法?PHP Client::multiExec怎么用?PHP Client::multiExec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::multiExec方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: close
/**
* {@inheritdoc}
*/
public function close()
{
$buffer =& $this->buffer;
$this->redis->multiExec(function ($multi) use($buffer) {
foreach ($buffer as $record) {
$multi->rpush('monolog', $record);
}
});
}
示例2: getMany
/**
* @param ModelInterface $model
* @param array $ids
* @return array
*/
public function getMany(ModelInterface $model, array $ids = [])
{
$table = $this->getTableName($model);
$this->db->multiExec();
$data = [];
if (empty($ids)) {
$keys = $this->db->keys($table . ':*');
foreach ($keys as $key) {
$json = $this->db->get($key);
$data[] = $model->fromRaw(json_decode($json));
}
} else {
foreach ($ids as $id) {
$data[] = $this->getById($model, $id);
}
}
return $data;
}
示例3: close
/**
* {@inheritdoc}
*/
public function close()
{
if ($this->redis instanceof \Redis) {
$multi = $this->redis->multi();
foreach ($this->buffer as $record) {
$multi->rpush($this->key, $record);
}
$multi->exec();
} else {
$key =& $this->key;
$buffer =& $this->buffer;
$this->redis->multiExec(function ($multi) use($key, $buffer) {
foreach ($buffer as $record) {
$multi->rpush($key, $record);
}
});
}
}
示例4: incrementAndCount
/**
* Calls the increment() and count() function using a single MULTI/EXEC block.
*
* @param string $subject A unique identifier, for example a session id or an IP
* @param int $interval Interval in seconds
*
* @return int
*/
public function incrementAndCount($subject, $interval)
{
$bucket = $this->getBucket();
$subject = $this->key . ':' . $subject;
$count = (int) floor($interval / $this->bucketInterval);
$multi = $this->client->multiExec();
$this->addMultiExecIncrement($multi, $subject, $bucket);
$this->addMultiExecCount($multi, $subject, $bucket, $count);
return array_sum(array_slice($multi->exec(), 4));
}
示例5: swapItems
/**
* {@inheritdoc}
*/
public function swapItems($firstIndex, $secondIndex)
{
$this->initializeRedis();
$key = $this->getKeyForItemList();
$options = array('cas' => true, 'watch' => $key, 'retry' => 3);
$this->redis->multiExec($options, function ($tx) use($key, $firstIndex, $secondIndex) {
$firstItem = $tx->lindex($key, $firstIndex);
$secondItem = $tx->lindex($key, $secondIndex);
$tx->multi();
$tx->lset($key, $firstIndex, $secondItem);
$tx->lset($key, $secondIndex, $firstItem);
});
}
示例6: removeTags
/**
* @param string $id
* @param string[] $tags
* @return bool
*/
public function removeTags($id, array $tags)
{
if (count($tags) > 0) {
$transaction = $this->redis->multiExec();
$commandArgs = $tags;
array_unshift($commandArgs, $this->getTagsForIdKey($id));
$command = $this->redis->createCommand('srem', $commandArgs);
$transaction->executeCommand($command);
foreach ($tags as $tag) {
$command = $this->redis->createCommand('srem', array($this->getIdsForTagKey($tag), $id));
$transaction->executeCommand($command);
}
$responses = $transaction->exec();
foreach ($responses as $response) {
if ($response instanceof ResponseErrorInterface) {
return false;
}
}
}
return true;
}
示例7: testMultiExecWithArrayAndCallableExecutesMultiExec
/**
* @group disconnected
*/
public function testMultiExecWithArrayAndCallableExecutesMultiExec()
{
// NOTE: we use CAS since testing the actual MULTI/EXEC context
// here is not the point.
$options = array('cas' => true, 'retry' => 3);
$connection = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
$connection->expects($this->once())->method('executeCommand')->will($this->returnValue(new ResponseQueued()));
$txCallback = function ($tx) {
$tx->ping();
};
$callable = $this->getMock('stdClass', array('__invoke'));
$callable->expects($this->once())->method('__invoke')->will($this->returnCallback($txCallback));
$client = new Client($connection);
$client->multiExec($options, $callable);
}