当前位置: 首页>>代码示例>>PHP>>正文


PHP Redis::multi方法代码示例

本文整理汇总了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();
 }
开发者ID:sndsgd,项目名称:rate,代码行数:13,代码来源:RedisLimiter.php

示例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;
 }
开发者ID:seepre,项目名称:api.seepre.com,代码行数:34,代码来源:RedQueue.php

示例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;
 }
开发者ID:mwunsch4,项目名称:PostbackDelivery,代码行数:31,代码来源:endpointRequest.php

示例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();
 }
开发者ID:stevenharradine,项目名称:php-dark-launch,代码行数:11,代码来源:Dark_Launch.php

示例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();
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:40,代码来源:RedisBackend.php

示例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;
 }
开发者ID:drealecs,项目名称:thread-worker,代码行数:12,代码来源:RedisQueue.php

示例7: multi

	/**
	 * 开启事务
	 */
	public function multi() {
		try {
			return $this->_redis->multi(Redis::MULTI);
		} catch (Exception $e) {
			$this->_error = $e->getMessage();
			return false;
		}
	}
开发者ID:neil-chen,项目名称:NeilChen,代码行数:11,代码来源:RedisCache.class.php

示例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();
 }
开发者ID:lingualeo,项目名称:php-cache,代码行数:12,代码来源:RedisCache.php

示例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();
 }
开发者ID:kkwoker,项目名称:php-dark-launch,代码行数:12,代码来源:Dark_Launch.php

示例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);
             }
         });
     }
 }
开发者ID:ajoaugustine,项目名称:tracker,代码行数:21,代码来源:RedisHandler.php

示例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);
 }
开发者ID:hollodotme,项目名称:readis,代码行数:15,代码来源:ServerManager.php

示例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;
 }
开发者ID:ZhuJingfa,项目名称:HuiLib,代码行数:17,代码来源:Redis.php

示例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);
 }
开发者ID:bjlzt,项目名称:EasyRedis,代码行数:14,代码来源:Manager.php

示例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();
         }
     }
 }
开发者ID:parallel-php,项目名称:parallel-task,代码行数:14,代码来源:RedisQueue.php

示例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;
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:30,代码来源:RedisBackend.php


注:本文中的Redis::multi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。