當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。