• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sharded类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中redis.clients.util.Sharded的典型用法代码示例。如果您正苦于以下问题:Java Sharded类的具体用法?Java Sharded怎么用?Java Sharded使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sharded类属于redis.clients.util包,在下文中一共展示了Sharded类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: JedisShardInfo

import redis.clients.util.Sharded; //导入依赖的package包/类
public JedisShardInfo(String host, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
		HostnameVerifier hostnameVerifier) {
	super(Sharded.DEFAULT_WEIGHT);
	URI uri = URI.create(host);
	if (JedisURIHelper.isValid(uri)) {
		this.host = uri.getHost();
		this.port = uri.getPort();
		this.password = JedisURIHelper.getPassword(uri);
		this.db = JedisURIHelper.getDBIndex(uri);
		this.ssl = uri.getScheme().equals("rediss");
		this.sslSocketFactory = sslSocketFactory;
		this.sslParameters = sslParameters;
		this.hostnameVerifier = hostnameVerifier;
	} else {
		this.host = host;
		this.port = Protocol.DEFAULT_PORT;
	}
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:JedisShardInfo.java


示例2: testMasterSlaveShardingConsistency

import redis.clients.util.Sharded; //导入依赖的package包/类
@Test
public void testMasterSlaveShardingConsistency() {
  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);

  List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
  otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
  otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1));
  otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2));
  Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards,
      Hashing.MURMUR_HASH);

  for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
    JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
    assertEquals(shards.indexOf(jedisShardInfo), otherShards.indexOf(jedisShardInfo2));
  }

}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:24,代码来源:ShardedJedisTest.java


示例3: testMasterSlaveShardingConsistencyWithShardNaming

import redis.clients.util.Sharded; //导入依赖的package包/类
@Test
public void testMasterSlaveShardingConsistencyWithShardNaming() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, "HOST1:1234"));
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1, "HOST2:1234"));
  shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, "HOST3:1234"));
  Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
      Hashing.MURMUR_HASH);

  List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
  otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, "HOST2:1234"));
  otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1, "HOST3:1234"));
  otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2, "HOST1:1234"));
  Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards,
      Hashing.MURMUR_HASH);

  for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
    JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
    assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName());
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:23,代码来源:ShardedJedisTest.java


示例4: testMD5Sharding

import redis.clients.util.Sharded; //导入依赖的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


示例5: testMurmurSharding

import redis.clients.util.Sharded; //导入依赖的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


示例6: JedisShardInfo

import redis.clients.util.Sharded; //导入依赖的package包/类
public JedisShardInfo(String host) {
  super(Sharded.DEFAULT_WEIGHT);
  URI uri = URI.create(host);
  if (JedisURIHelper.isValid(uri)) {
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.password = JedisURIHelper.getPassword(uri);
    this.db = JedisURIHelper.getDBIndex(uri);
  } else {
    this.host = host;
    this.port = Protocol.DEFAULT_PORT;
  }
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:14,代码来源:JedisShardInfo.java


示例7: JedisShardInfo

import redis.clients.util.Sharded; //导入依赖的package包/类
public JedisShardInfo(String host) {
super(Sharded.DEFAULT_WEIGHT);
URI uri = URI.create(host);
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.password = uri.getUserInfo().split(":", 2)[1];
} else {
    this.host = host;
    this.port = Protocol.DEFAULT_PORT;
}
   }
 
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:13,代码来源:JedisShardInfo.java


示例8: createJedisPool

import redis.clients.util.Sharded; //导入依赖的package包/类
private ShardedJedisPool createJedisPool(final RedisConfig conf) {
    Assert.notNull(conf);
    try {
        final String[] hostAndports = conf.getHostNames().split(";");
        final List<String> redisHosts = Lists.newArrayList();
        final List<Integer> redisPorts = Lists.newArrayList();
        for (int i = 0; i < hostAndports.length; i++) {
            final String[] hostPort = hostAndports[i].split(":");
            redisHosts.add(hostPort[0]);
            redisPorts.add(Integer.valueOf(hostPort[1]));
        }

        final List<JedisShardInfo> shards = Lists.newArrayList();
        for (int i = 0; i < redisHosts.size(); i++) {
            final String host = (String) redisHosts.get(i);
            final Integer port = (Integer) redisPorts.get(i);
            Integer timeout = conf.getTimeOut();
            if (timeout == null || timeout < 0) {
                timeout = DEFAULT_TIMEOUT;
            }
            
            JedisShardInfo si = new JedisShardInfo(host, port.intValue(), timeout);
            shards.add(si);
        }

        return new ShardedJedisPool(getJedisPoolConfig(conf), shards, Hashing.MURMUR_HASH, Sharded.DEFAULT_KEY_TAG_PATTERN);
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:31,代码来源:RedisClientPool.java


示例9: JedisShardInfo

import redis.clients.util.Sharded; //导入依赖的package包/类
public JedisShardInfo(String host) {
	super(Sharded.DEFAULT_WEIGHT);

	URI uri = URI.create(host);
	if (uri.getScheme() != null && uri.getScheme().equals("redis")) { // 验证使用"Redis协议"
		this.host = uri.getHost();
		this.port = uri.getPort();
		this.password = uri.getUserInfo().split(":", 2)[1];
	} else {
		this.host = host;
		this.port = Protocol.DEFAULT_PORT;
	}
}
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:14,代码来源:JedisShardInfo.java


示例10: testMD5Sharding

import redis.clients.util.Sharded; //导入依赖的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


示例11: testMurmurSharding

import redis.clients.util.Sharded; //导入依赖的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


示例12: testMasterSlaveShardingConsistency

import redis.clients.util.Sharded; //导入依赖的package包/类
@Test
   public void testMasterSlaveShardingConsistency() {
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);

List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
otherShards.add(new JedisShardInfo("otherhost",
	Protocol.DEFAULT_PORT + 1));
otherShards.add(new JedisShardInfo("otherhost",
	Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
	otherShards, Hashing.MURMUR_HASH);

for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
	    .toString(i));
    JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
	    .toString(i));
    assertEquals(shards.indexOf(jedisShardInfo),
	    otherShards.indexOf(jedisShardInfo2));
}

   }
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:29,代码来源:ShardedJedisTest.java


示例13: testMasterSlaveShardingConsistencyWithShardNaming

import redis.clients.util.Sharded; //导入依赖的package包/类
@Test
   public void testMasterSlaveShardingConsistencyWithShardNaming() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT,
	"HOST1:1234"));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1,
	"HOST2:1234"));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2,
	"HOST3:1234"));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
	shards, Hashing.MURMUR_HASH);

List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT,
	"HOST2:1234"));
otherShards.add(new JedisShardInfo("otherhost",
	Protocol.DEFAULT_PORT + 1, "HOST3:1234"));
otherShards.add(new JedisShardInfo("otherhost",
	Protocol.DEFAULT_PORT + 2, "HOST1:1234"));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
	otherShards, Hashing.MURMUR_HASH);

for (int i = 0; i < 1000; i++) {
    JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
	    .toString(i));
    JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
	    .toString(i));
    assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName());
}
   }
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:31,代码来源:ShardedJedisTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Preference类代码示例发布时间:2022-05-23
下一篇:
Java ParameterizedCachedValueProvider类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap