當前位置: 首頁>>代碼示例>>Java>>正文


Java JedisShardInfo.getPort方法代碼示例

本文整理匯總了Java中redis.clients.jedis.JedisShardInfo.getPort方法的典型用法代碼示例。如果您正苦於以下問題:Java JedisShardInfo.getPort方法的具體用法?Java JedisShardInfo.getPort怎麽用?Java JedisShardInfo.getPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.JedisShardInfo的用法示例。


在下文中一共展示了JedisShardInfo.getPort方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMD5Sharding

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
@Test
public void testMD5Sharding() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
  Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards, Hashing.MD5);
  int shard_6379 = 0;
  int shard_6380 = 0;
  int shard_6381 = 0;
  for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
    switch (jedisShardInfo.getPort()) {
    case 6379:
      shard_6379++;
      break;
    case 6380:
      shard_6380++;
      break;
    case 6381:
      shard_6381++;
      break;
    default:
      fail("Attempting to use a non-defined shard!!:" + jedisShardInfo);
      break;
    }
  }
  assertTrue(shard_6379 > 300 && shard_6379 < 400);
  assertTrue(shard_6380 > 300 && shard_6380 < 400);
  assertTrue(shard_6381 > 300 && shard_6381 < 400);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:32,代碼來源:ShardedJedisTest.java

示例2: testMurmurSharding

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
@Test
public void testMurmurSharding() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
  Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
      Hashing.MURMUR_HASH);
  int shard_6379 = 0;
  int shard_6380 = 0;
  int shard_6381 = 0;
  for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
    switch (jedisShardInfo.getPort()) {
    case 6379:
      shard_6379++;
      break;
    case 6380:
      shard_6380++;
      break;
    case 6381:
      shard_6381++;
      break;
    default:
      fail("Attempting to use a non-defined shard!!:" + jedisShardInfo);
      break;
    }
  }
  assertTrue(shard_6379 > 300 && shard_6379 < 400);
  assertTrue(shard_6380 > 300 && shard_6380 < 400);
  assertTrue(shard_6381 > 300 && shard_6381 < 400);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:33,代碼來源:ShardedJedisTest.java

示例3: addShard

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
public boolean addShard(JedisShardInfo shard) {
	if (shard == null) {
		throw new IllegalArgumentException("want add a null shard");
	}
	for (JedisShardInfo jedisShardInfo : this.shards) {
		if (jedisShardInfo.getHost().equals(shard.getHost())
				&& jedisShardInfo.getPort() == shard.getPort()) {
			return true;
		}
	}
	return this.shards.add(shard);
}
 
開發者ID:OpeningO,項目名稱:JFinal-ext2,代碼行數:13,代碼來源:ShardRedisPlugin.java

示例4: checkEachRedisServerRunOk

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
@Test(description = "檢查每一台Redis服務器是否運行正常")
public void checkEachRedisServerRunOk() {
    List<JedisShardInfo> shards = RedisConfigUtils.parseRedisServerList(TestConfigUtils.getRedisServers(),
                                                                        TestConfigUtils.getTimeoutMillis());
    for (JedisShardInfo shardInfo : shards) {
        // try-with-resources, in Java SE 7 and later
        try (JedisPool pool = new JedisPool(new JedisPoolConfig(), shardInfo.getHost(), shardInfo.getPort(),
                                            shardInfo.getTimeout())) {
            // Jedis implements Closeable. Hence, the jedis instance will be auto-closed after the last statement.
            try (Jedis jedis = pool.getResource()) {
                assertEquals(jedis.ping(), "PONG");
            }
        }
    }
}
 
開發者ID:EdwardLee03,項目名稱:jedis-x,代碼行數:16,代碼來源:RedisServiceTest.java

示例5: onConstruct

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    String redisConnInfo;
    JedisShardInfo shardInfo = (JedisShardInfo)allArguments[0];
    redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort();
    objInst.setSkyWalkingDynamicField(redisConnInfo);
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:8,代碼來源:JedisConstructorWithShardInfoArgInterceptor.java

示例6: testMD5Sharding

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
@Test
   public void testMD5Sharding() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
	shards, Hashing.MD5);
int shard_6379 = 0;
int shard_6380 = 0;
int shard_6381 = 0;
for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
	    .toString(i));
    switch (jedisShardInfo.getPort()) {
    case 6379:
	shard_6379++;
	break;
    case 6380:
	shard_6380++;
	break;
    case 6381:
	shard_6381++;
	break;
    default:
	fail("Attempting to use a non-defined shard!!:"
		+ jedisShardInfo);
	break;
    }
}
assertTrue(shard_6379 > 300 && shard_6379 < 400);
assertTrue(shard_6380 > 300 && shard_6380 < 400);
assertTrue(shard_6381 > 300 && shard_6381 < 400);
   }
 
開發者ID:EdwardLee03,項目名稱:jedis-sr,代碼行數:35,代碼來源:ShardedJedisTest.java

示例7: testMurmurSharding

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
@Test
   public void testMurmurSharding() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
	shards, Hashing.MURMUR_HASH);
int shard_6379 = 0;
int shard_6380 = 0;
int shard_6381 = 0;
for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
	    .toString(i));
    switch (jedisShardInfo.getPort()) {
    case 6379:
	shard_6379++;
	break;
    case 6380:
	shard_6380++;
	break;
    case 6381:
	shard_6381++;
	break;
    default:
	fail("Attempting to use a non-defined shard!!:"
		+ jedisShardInfo);
	break;
    }
}
assertTrue(shard_6379 > 300 && shard_6379 < 400);
assertTrue(shard_6380 > 300 && shard_6380 < 400);
assertTrue(shard_6381 > 300 && shard_6381 < 400);
   }
 
開發者ID:EdwardLee03,項目名稱:jedis-sr,代碼行數:35,代碼來源:ShardedJedisTest.java

示例8: Redis

import redis.clients.jedis.JedisShardInfo; //導入方法依賴的package包/類
public Redis(JedisPoolConfig i_PoolConfig ,List<JedisShardInfo> i_JedisShardInfos)
{
    if ( JavaHelp.isNull(i_JedisShardInfos) )
    {
        throw new NullPointerException("HostAndPorts is null.");
    }
    
    shardInfoMap    = new ListMap<String ,JedisShardInfo>(i_JedisShardInfos.size() ,false);
    exceptionShards = new ListMap<String ,JedisShardInfo>(i_JedisShardInfos.size() ,false);
    
    for (JedisShardInfo v_Host : i_JedisShardInfos)
    {
        if ( JavaHelp.isNull(v_Host.getHost()) )
        {
            throw new NullPointerException("IP is null.");
        }
        
        if ( 0 >= v_Host.getPort() || v_Host.getPort() >= 65535 )
        {
            throw new VerifyError("Port is not 0~65535.");
        }
        
        if ( JavaHelp.isNull(v_Host.getName()) )
        {
            String         v_Name  = v_Host.getHost() + ":" + v_Host.getPort();
            JedisShardInfo v_Clone = new JedisShardInfo(v_Host.getHost() ,v_Host.getPort() ,v_Host.getTimeout() ,v_Name);
            v_Clone.setPassword(v_Host.getPassword());
            
            if ( shardInfoMap.containsKey(v_Name) )
            {
                throw new VerifyError("JedisShardInfo name[" + v_Name + "] is same.");
            }
            shardInfoMap.put(v_Name ,v_Clone);
        }
        else
        {
            if ( shardInfoMap.containsKey(v_Host.getName()) )
            {
                throw new VerifyError("JedisShardInfo name[" + v_Host.getName() + "] is same.");
            }
            shardInfoMap.put(v_Host.getName() ,v_Host);
        }
    }
    
    JedisPoolConfig v_PoolConfig = i_PoolConfig;
    if ( v_PoolConfig == null )
    {
        v_PoolConfig = new JedisPoolConfig();
        v_PoolConfig.setMaxTotal(1024);
        v_PoolConfig.setMaxIdle(10);
        v_PoolConfig.setMinIdle(1);
    }
    
    shardedPool = new ShardedJedisPool(v_PoolConfig ,JavaHelp.toList(shardInfoMap));
    
    if ( this.shardInfoMap.size() <= 1 )
    {
        this.runMode = RunMode.$Backup;
    }
    else
    {
        this.runMode = RunMode.$Shard;
    }
    
    this.redisKey    = new RedisKey(this);
    this.redisString = new RedisString(this);
    this.redisSet    = new RedisSet(this);
    this.redisHash   = new RedisHash(this);
    this.redisServer = new RedisServer(this);
    this.isKeyOrder  = true;
    this.rowKeyType  = RowKeyType.$TableName_ID;
    this.xjavaID     = "XID_REDIS_" + StringHelp.getUUID();
    XJava.putObject(this.xjavaID ,this);
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.Redis,代碼行數:75,代碼來源:Redis.java


注:本文中的redis.clients.jedis.JedisShardInfo.getPort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。