本文整理汇总了PHP中Redis::multi方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::multi方法的具体用法?PHP Redis::multi怎么用?PHP Redis::multi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::multi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setTimeouts
/**
* Stubbable method for setting timeouts on new keys
*
* @param array<\sndsgd\rate\LimitInterface> The limits to set timeouts for
*/
protected function setTimeouts(array $limits)
{
$pipe = $this->redis->multi(\Redis::PIPELINE);
foreach ($limits as $limit) {
$pipe->setTimeout($limit->getHash(), $limit->getDuration());
}
$pipe->exec();
}
示例2: pushMulti
/**
* 将批量数据加入队列开头
* @注意:当加入的数据量较大,比如超过10KB时,建议使用pipeline方式
* @注意:当提交的数据条数较多时,$pipeline为FALSE效率更高
* @param array $arrValues array('v1','v2') 按照数组的顺序,第一个元素将首先被加入队列,最后一个元素将最后加入队列
* @param bool $pipeline 默认为FALSE。当为TRUE时,通过PIPELINE的模式提交,为FALSE时,通过原生的方式提交。
* @return long 成功返回TRUE(可能是0),失败时返回FALSE
*/
public function pushMulti($arrValues, $pipeline = FALSE)
{
if ($pipeline) {
if (!$this->rd->isConnected()) {
if (!$this->reconnRedis()) {
return FALSE;
}
}
$this->rd->multi(\Redis::PIPELINE);
foreach ($arrValues as $v) {
$this->rd->lPush($this->k, $v);
}
$re = $this->rd->exec();
return TRUE;
} else {
array_unshift($arrValues, $this->k);
try {
return call_user_func_array(array($this->rd, 'lPush'), $arrValues);
} catch (\RedisException $e) {
if ($this->reconnRedis()) {
return call_user_func_array(array($this->rd, 'lPush'), $arrValues);
}
}
}
return FALSE;
}
示例3: enqueueRequests
public function enqueueRequests()
{
if (!$this->has_requests) {
return "No requests to send";
}
$finished = "Error connecting to redis";
try {
$redis = new Redis();
$redis->pconnect(REDIS_ADDRESS);
$multi = $redis->multi();
//Executing all posts to Redis in one multi batch
foreach ($this->data_requests as $key => $request) {
$uuid = $request->getUUID();
$multi->lPush(PENDING_QUEUE, $uuid);
$multi->hSet(VALUES_HASH, $uuid, $request->getFormattedURL());
$multi->hSet(VALUES_HASH, $uuid . ':method', $this->endpoint->method);
$multi->hSet(STATS_HASH, $uuid . ':start', $this->start_time);
}
$ret = $multi->exec();
$finished = "Postback Delivered";
//Seach results for any errors from Redis commands
foreach ($ret as $idx => $result) {
if (!$result) {
$finished = "Redis call failed: " . $idx;
}
}
} catch (Exception $e) {
return "Error posting to Redis";
}
return $finished;
}
示例4: disable_feature
/**
* Disable a dark launch feature
* @param $feature string - The name of the feature
*/
public function disable_feature($feature_name)
{
$multi = $this->redis->multi();
$this->redis->del("{$this->feature_namespace()}:feature:{$feature_name}");
$this->redis->srem("{$this->feature_namespace()}:features", $feature_name);
$multi->exec();
}
示例5: removeIdentifierEntriesAndRelations
/**
* Helper method for flushByTag()
* Gets list of identifiers and tags and removes all relations of those tags
*
* Scales O(1) with number of cache entries
* Scales O(n^2) with number of tags
*
* @param array $identifiers List of identifiers to remove
* @param array $tags List of tags to be handled
* @return void
*/
protected function removeIdentifierEntriesAndRelations(array $identifiers, array $tags)
{
// Set a temporary entry which holds all identifiers that need to be removed from
// the tag to identifiers sets
$uniqueTempKey = 'temp:' . uniqid('', TRUE);
$prefixedKeysToDelete = array($uniqueTempKey);
$prefixedIdentifierToTagsKeysToDelete = array();
foreach ($identifiers as $identifier) {
$prefixedKeysToDelete[] = self::IDENTIFIER_DATA_PREFIX . $identifier;
$prefixedIdentifierToTagsKeysToDelete[] = self::IDENTIFIER_TAGS_PREFIX . $identifier;
}
foreach ($tags as $tag) {
$prefixedKeysToDelete[] = self::TAG_IDENTIFIERS_PREFIX . $tag;
}
$tagToIdentifiersSetsToRemoveIdentifiersFrom = $this->redis->sUnion($prefixedIdentifierToTagsKeysToDelete);
// Remove the tag to identifier set of the given tags, they will be removed anyway
$tagToIdentifiersSetsToRemoveIdentifiersFrom = array_diff($tagToIdentifiersSetsToRemoveIdentifiersFrom, $tags);
// Diff all identifiers that must be removed from tag to identifiers sets off from a
// tag to identifiers set and store result in same tag to identifiers set again
$queue = $this->redis->multi(\Redis::PIPELINE);
foreach ($identifiers as $identifier) {
$queue->sAdd($uniqueTempKey, $identifier);
}
foreach ($tagToIdentifiersSetsToRemoveIdentifiersFrom as $tagToIdentifiersSet) {
$queue->sDiffStore(self::TAG_IDENTIFIERS_PREFIX . $tagToIdentifiersSet, self::TAG_IDENTIFIERS_PREFIX . $tagToIdentifiersSet, $uniqueTempKey);
}
$queue->delete(array_merge($prefixedKeysToDelete, $prefixedIdentifierToTagsKeysToDelete));
$queue->exec();
}
示例6: isFinished
/**
* @param string|int $taskId
* @return bool
*/
public function isFinished($taskId)
{
$this->redis->multi();
$this->redis->hExists($this->getTaskKey(), $taskId);
$this->redis->hExists($this->getTaskResultKey(), $taskId);
list($taskExists, $taskResultExists) = $this->redis->exec();
return !$taskExists && $taskResultExists;
}
示例7: multi
/**
* 开启事务
*/
public function multi() {
try {
return $this->_redis->multi(Redis::MULTI);
} catch (Exception $e) {
$this->_error = $e->getMessage();
return false;
}
}
示例8: multi
/**
* @param string $key
* @return \Redis
*/
protected function multi($key)
{
if ($this->redis instanceof \RedisArray) {
$host = $this->redis->_target($key);
return $this->redis->multi($host);
}
return $this->redis->multi();
}
示例9: disable_feature
/**
* Disable a dark launch feature
* @param $feature string - The name of the feature
*/
public function disable_feature($feature_name)
{
$feature_name = str_replace('_', '-', $feature_name);
$multi = $this->redis->multi();
$this->redis->hdel("{$this->_feature_namespace()}:feature", $feature_name);
$this->redis->srem("{$this->_feature_namespace()}:features", $feature_name);
$multi->exec();
}
示例10: 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);
}
});
}
}
示例11: getKeyInfoObject
/**
* @param string $key
*
* @return ProvidesKeyInformation
*/
public function getKeyInfoObject($key)
{
list($type, $ttl) = $this->redis->multi()->type($key)->pttl($key)->exec();
if ($type == \Redis::REDIS_HASH) {
$subItems = $this->redis->hKeys($key);
} else {
$subItems = [];
}
return new KeyInfo($key, $type, $ttl, $subItems);
}
示例12: deleteKeys
/**
* 批量删除Redis Key
*
* @param array $keys 键数组
*/
public function deleteKeys($keys)
{
if (empty($keys)) {
return false;
}
$pipeLine = $this->connect->multi();
foreach ($keys as $key) {
$pipeLine->del($key);
}
$pipeLine->exec();
return true;
}
示例13: defer
public function defer($name, $params = array(), $callback = null)
{
if ($this->_redis === null) {
$this->_connect();
}
if (empty($this->_queue)) {
$this->_redis->multi(\Redis::PIPELINE);
}
$this->_queue[] = array('callback' => $callback, 'params' => $params);
if ($this->_profiler) {
$this->_profiler->log($name, $params);
}
return call_user_func_array(array($this->_redis, $name), $params);
}
示例14: requeueOldWorkingMessages
private function requeueOldWorkingMessages($type)
{
$messageIds = array_unique($this->redis->lRange($this->getMessageRunKey($type), 0, -1));
foreach ($messageIds as $messageId) {
$time = $this->redis->hGet($this->getMessageStartTimeKey($type), $messageId);
if (!empty($time) && time() > $this->messageTimeout + (int) $time) {
$this->redis->multi();
$this->redis->rPush($this->getMessageQueueKey($type), $messageId);
$this->redis->lRem($this->getMessageRunKey($type), $messageId, 1);
$this->redis->hDel($this->getMessageStartTimeKey($type), $messageId);
$this->redis->exec();
}
}
}
示例15: freeze
/**
* Freezes this cache backend.
*
* All data in a frozen backend remains unchanged and methods which try to add
* or modify data result in an exception thrown. Possible expiry times of
* individual cache entries are ignored.
*
* A frozen backend can only be thawn by calling the flush() method.
*
* @throws \RuntimeException
* @return void
*/
public function freeze()
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
}
do {
$entriesKey = $this->buildKey('entries');
$this->redis->watch($entriesKey);
$entries = $this->redis->lRange($entriesKey, 0, -1);
$this->redis->multi();
foreach ($entries as $entryIdentifier) {
$this->redis->persist($this->buildKey('entry:' . $entryIdentifier));
}
$this->redis->set($this->buildKey('frozen'), 1);
$result = $this->redis->exec();
} while ($result === false);
$this->frozen = true;
}