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


Java Hashing类代码示例

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


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

示例1: testMasterSlaveShardingConsistency

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

示例2: testMasterSlaveShardingConsistencyWithShardNaming

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

示例3: testMD5Sharding

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

示例4: testMurmurSharding

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

示例5: init

import redis.clients.util.Hashing; //导入依赖的package包/类
public void init() {

		try {
			String[] hosts = servers.trim().split("\\|");

			List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();

			for (String host : hosts) {
				String[] ss = host.split(":");
				//升级 redis  构造变化
				JedisShardInfo shard = new JedisShardInfo(ss[0], Integer.parseInt(ss[1]), DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, 1);
				shards.add(shard);
			}

			JedisPoolConfig config = new JedisPoolConfig();
			config.setMaxIdle(MAX_ACTIVE);
			config.setMinIdle(MAX_IDLE);
			config.setMaxWaitMillis(MAX_WAIT);
			config.setMaxTotal(MAX_TOTAL);

			pool = new ShardedJedisPool(config, shards, Hashing.MURMUR_HASH);
		} catch (NumberFormatException e) {
			System.out.println("redis客户端初始化连接异常!!!!!!!!!  链接参数:" + servers
					+ " " + DEFAULT_TIMEOUT + " " + app);
			logger.error("redis:{},exception:{}.", servers + " "
					+ DEFAULT_TIMEOUT + " " + app, e.getMessage());
		}
	}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:29,代码来源:RedisCacheClient.java

示例6: initPool

import redis.clients.util.Hashing; //导入依赖的package包/类
@Override
public Pool<ShardedJedis> initPool() throws Exception {
    if (Check.isNullOrEmpty(getServers())) {
        throw new IllegalArgumentException("未指定redis服务器地址");
    }
    String[] hosts = getServers().trim().split("\\|");
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    for (String host : hosts) {
        String[] ss = host.split(":");
        //升级 redis  构造变化
        JedisShardInfo shard = new JedisShardInfo(ss[0], Integer.parseInt(ss[1]), connectTimeout, socketTimeout, 1);
        shards.add(shard);
    }
    return new ShardedJedisPool(getPoolConfig(), shards, Hashing.MURMUR_HASH);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:16,代码来源:RedisShardedCacheClient.java

示例7: connect

import redis.clients.util.Hashing; //导入依赖的package包/类
private void connect() {
    if (StringUtils.isEmpty(server.getHost())) {
        shardJedis = new ShardedJedis(constructShardInfo(server.getUrl(),
            poolConfig), Hashing.MURMUR_HASH, null);
    } else {
        shardJedis = new ShardedJedis(constructShardInfo(server.getHost(),
            server.getPort(), poolConfig), Hashing.MURMUR_HASH, null);
    }
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:10,代码来源:NaviShardJedisDriver.java

示例8: initPool

import redis.clients.util.Hashing; //导入依赖的package包/类
/**
 * 根据newMasterRoute路由表信息初始化连接池
 * 
 * @param newMasterRoute
 */
private void initPool(Map<String, HostAndPort> newMasterRoute) {
    if (!equals(localMasterRoute, newMasterRoute)) {
        List<JedisShardInfo> shardMasters = makeShardInfoList(newMasterRoute);
        initPool(poolConfig, new ShardedJedisFactory(shardMasters, Hashing.MURMUR_HASH, null));
        localMasterRoute.putAll(newMasterRoute);
    }
}
 
开发者ID:hailin0,项目名称:redis-sentinel-client,代码行数:13,代码来源:ShardedJedisSentinelPool.java

示例9: CustomShardedJedisFactory

import redis.clients.util.Hashing; //导入依赖的package包/类
/**
 * 创建一个"数据分片的Jedis工厂"实例。
 * 
 * @param shards Jedis分片节点信息列表
 * @param algo 哈希算法
 * @param keyTagPattern 键标记模式
 * @param timeBetweenServerStateCheckRunsMillis "Redis服务器状态检测"定时任务的运行间隔时间
 * @param pingRetryTimes Redis PING命令的失败重试次数
 */
public CustomShardedJedisFactory(List<JedisShardInfo> shards, Hashing algo, Pattern keyTagPattern,
                                 int timeBetweenServerStateCheckRunsMillis, int pingRetryTimes){
    this.shards = shards;
    this.originalShardListSize = shards.size();
    this.algo = algo;
    this.keyTagPattern = keyTagPattern;

    this.startServerStateCheckTimerTask(timeBetweenServerStateCheckRunsMillis, pingRetryTimes);
}
 
开发者ID:EdwardLee03,项目名称:jedis-x,代码行数:19,代码来源:CustomShardedJedisFactory.java

示例10: initPool

import redis.clients.util.Hashing; //导入依赖的package包/类
private void initPool(List<HostAndPort> masters) {
	if (!equals(currentHostMasters, masters)) {
		StringBuffer sb = new StringBuffer();
		for (HostAndPort master : masters) {
			sb.append(master.toString());
			sb.append(" ");
		}
		log.info("Created ShardedJedisPool to master at [" + sb.toString() + "]");
		List<JedisShardInfo> shardMasters = makeShardInfoList(masters);
		initPool(poolConfig, new ShardedJedisFactory(shardMasters, Hashing.MURMUR_HASH, null));
		currentHostMasters = masters;
	}
}
 
开发者ID:liuxinglanyue,项目名称:distributed-session-manager,代码行数:14,代码来源:ShardedJedisSentinelPool.java

示例11: createJedisPool

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

示例12: before

import redis.clients.util.Hashing; //导入依赖的package包/类
@Before
public void before() {
	List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
	
	shards.add(new JedisShardInfo("127.0.0.1", 1200));
	shards.add(new JedisShardInfo("127.0.0.1", 1201));
	shards.add(new JedisShardInfo("127.0.0.1", 1202));
	shards.add(new JedisShardInfo("127.0.0.1", 1203));
	
	
	pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards, Hashing.MURMUR_HASH);
}
 
开发者ID:robertomarin,项目名称:redis-de-cache-a-nosql,代码行数:13,代码来源:Redis03Sharding.java

示例13: testMD5Sharding

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

示例14: testMurmurSharding

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

示例15: testMasterSlaveShardingConsistency

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


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