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


PHP ArrayUtils::consistentHashSort方法代码示例

本文整理汇总了PHP中ArrayUtils::consistentHashSort方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::consistentHashSort方法的具体用法?PHP ArrayUtils::consistentHashSort怎么用?PHP ArrayUtils::consistentHashSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils::consistentHashSort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getConnection

	/**
	 * Get a Redis object with a connection suitable for fetching the specified key
	 * @return Array (server, RedisConnRef) or (false, false)
	 */
	protected function getConnection( $key ) {
		if ( count( $this->servers ) === 1 ) {
			$candidates = $this->servers;
		} else {
			$candidates = $this->servers;
			ArrayUtils::consistentHashSort( $candidates, $key, '/' );
			if ( !$this->automaticFailover ) {
				$candidates = array_slice( $candidates, 0, 1 );
			}
		}

		foreach ( $candidates as $server ) {
			$conn = $this->redisPool->getConnection( $server );
			if ( $conn ) {
				return array( $server, $conn );
			}
		}
		return array( false, false );
	}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:23,代码来源:RedisBagOStuff.php

示例2: getConnection

 /**
  * Get a Redis object with a connection suitable for fetching the specified key
  * @param string $key
  * @return array (server, RedisConnRef) or (false, false)
  */
 protected function getConnection($key)
 {
     $candidates = array_keys($this->serverTagMap);
     if (count($this->servers) > 1) {
         ArrayUtils::consistentHashSort($candidates, $key, '/');
         if (!$this->automaticFailover) {
             $candidates = array_slice($candidates, 0, 1);
         }
     }
     while (($tag = array_shift($candidates)) !== null) {
         $server = $this->serverTagMap[$tag];
         $conn = $this->redisPool->getConnection($server);
         if (!$conn) {
             continue;
         }
         // If automatic failover is enabled, check that the server's link
         // to its master (if any) is up -- but only if there are other
         // viable candidates left to consider. Also, getMasterLinkStatus()
         // does not work with twemproxy, though $candidates will be empty
         // by now in such cases.
         if ($this->automaticFailover && $candidates) {
             try {
                 if ($this->getMasterLinkStatus($conn) === 'down') {
                     // If the master cannot be reached, fail-over to the next server.
                     // If masters are in data-center A, and slaves in data-center B,
                     // this helps avoid the case were fail-over happens in A but not
                     // to the corresponding server in B (e.g. read/write mismatch).
                     continue;
                 }
             } catch (RedisException $e) {
                 // Server is not accepting commands
                 $this->handleException($conn, $e);
                 continue;
             }
         }
         return array($server, $conn);
     }
     $this->setLastError(BagOStuff::ERR_UNREACHABLE);
     return array(false, false);
 }
开发者ID:rrameshs,项目名称:mediawiki,代码行数:45,代码来源:RedisBagOStuff.php

示例3: getConnection

 /**
  * @return Status Uses RediConnRef as value on success
  */
 protected function getConnection()
 {
     if (!isset($this->conn)) {
         $conn = false;
         $servers = $this->ring->getLocations($this->key, 3);
         ArrayUtils::consistentHashSort($servers, $this->key);
         foreach ($servers as $server) {
             $conn = $this->pool->getConnection($this->serversByLabel[$server], $this->logger);
             if ($conn) {
                 break;
             }
         }
         if (!$conn) {
             return Status::newFatal('pool-servererror', implode(', ', $servers));
         }
         $this->conn = $conn;
     }
     return Status::newGood($this->conn);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:22,代码来源:PoolCounterRedis.php

示例4: getTableByKey

 /**
  * Get the server index and table name for a given key
  * @param string $key
  * @return array Server index and table name
  */
 protected function getTableByKey($key)
 {
     if ($this->shards > 1) {
         $hash = hexdec(substr(md5($key), 0, 8)) & 0x7fffffff;
         $tableIndex = $hash % $this->shards;
     } else {
         $tableIndex = 0;
     }
     if ($this->numServers > 1) {
         $sortedServers = $this->serverNames;
         ArrayUtils::consistentHashSort($sortedServers, $key);
         reset($sortedServers);
         $serverIndex = key($sortedServers);
     } else {
         $serverIndex = 0;
     }
     return array($serverIndex, $this->getTableNameByShard($tableIndex));
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:23,代码来源:SqlBagOStuff.php

示例5: getConnection

 /**
  * Get a Redis object with a connection suitable for fetching the specified key
  * @param string $key
  * @return array (server, RedisConnRef) or (false, false)
  */
 protected function getConnection($key)
 {
     $candidates = array_keys($this->serverTagMap);
     if (count($this->servers) > 1) {
         ArrayUtils::consistentHashSort($candidates, $key, '/');
         if (!$this->automaticFailover) {
             $candidates = array_slice($candidates, 0, 1);
         }
     }
     foreach ($candidates as $tag) {
         $server = $this->serverTagMap[$tag];
         $conn = $this->redisPool->getConnection($server);
         if ($conn) {
             return array($server, $conn);
         }
     }
     $this->setLastError(BagOStuff::ERR_UNREACHABLE);
     return array(false, false);
 }
开发者ID:GoProjectOwner,项目名称:mediawiki,代码行数:24,代码来源:RedisBagOStuff.php

示例6: getConnection

 /**
  * Get a Redis object with a connection suitable for fetching the specified key
  * @param string $key
  * @return array (server, RedisConnRef) or (false, false)
  */
 protected function getConnection($key)
 {
     $candidates = array_keys($this->serverTagMap);
     if (count($this->servers) > 1) {
         ArrayUtils::consistentHashSort($candidates, $key, '/');
         if (!$this->automaticFailover) {
             $candidates = array_slice($candidates, 0, 1);
         }
     }
     foreach ($candidates as $tag) {
         $server = $this->serverTagMap[$tag];
         $conn = $this->redisPool->getConnection($server);
         if (!$conn) {
             continue;
         }
         try {
             $info = $conn->info();
             // Check if this server has an unreachable redis master
             if ($info['role'] === 'slave' && $info['master_link_status'] === 'down' && $this->automaticFailover) {
                 // If the master cannot be reached, fail-over to the next server.
                 // If masters are in data-center A, and slaves in data-center B,
                 // this helps avoid the case were fail-over happens in A but not
                 // to the corresponding server in B (e.g. read/write mismatch).
                 continue;
             }
         } catch (RedisException $e) {
             // Server is not accepting commands
             $this->handleException($conn, $e);
             continue;
         }
         return array($server, $conn);
     }
     $this->setLastError(BagOStuff::ERR_UNREACHABLE);
     return array(false, false);
 }
开发者ID:D66Ha,项目名称:mediawiki,代码行数:40,代码来源:RedisBagOStuff.php


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