Java Code Examples for redis.clients.util.Hashing#MURMUR_HASH
The following examples show how to use
redis.clients.util.Hashing#MURMUR_HASH .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisShardedPool.java From mmall20180107 with Apache License 2.0 | 6 votes |
private static void initPool(){ JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(maxTotal); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMinIdle(minIdle); jedisPoolConfig.setTestOnBorrow(testOnBorrow); jedisPoolConfig.setTestOnReturn(testOnReturn); jedisPoolConfig.setBlockWhenExhausted(true);//连接耗尽的时候,是否阻塞,false会抛出异常,true阻塞直到超时。默认为true。 JedisShardInfo shardInfo1 = new JedisShardInfo(redis1Ip,redis1Port,2000); JedisShardInfo shardInfo2 = new JedisShardInfo(redis2Ip,redis2Port,2000); List<JedisShardInfo> jedisShardInfoList = new ArrayList<JedisShardInfo>(2); jedisShardInfoList.add(shardInfo1); jedisShardInfoList.add(shardInfo2); shardedJedisPool = new ShardedJedisPool(jedisPoolConfig,jedisShardInfoList, Hashing.MURMUR_HASH, Sharded.DEFAULT_KEY_TAG_PATTERN); }
Example 2
Source File: RedisShardedPool.java From mmall-kay-Java with Apache License 2.0 | 6 votes |
private static void initPool() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxTotal); config.setMaxIdle(maxIdle); config.setMinIdle(minIdle); config.setBlockWhenExhausted(true); //资源耗尽时是否阻塞 config.setTestOnBorrow(testOnborrow); config.setTestOnReturn(testOnReturn); JedisShardInfo info1 = new JedisShardInfo(host1, port1,1000*2,2); //超时时间默认是2s JedisShardInfo info2 = new JedisShardInfo(host2, port2,1000*2,1); List<JedisShardInfo> jedisShardInfoList = new ArrayList<>(2); jedisShardInfoList.add(info1); jedisShardInfoList.add(info2); //Hashing.MURMUR_HASH 一致性算法分片,Sharded中有默认分配虚拟节点策略 pool = new ShardedJedisPool(config, jedisShardInfoList, Hashing.MURMUR_HASH, Sharded.DEFAULT_KEY_TAG_PATTERN); }
Example 3
Source File: RedisClient.java From Redis_Learning with Apache License 2.0 | 6 votes |
/** * ��ʼ����Ƭ�� */ private void initialShardedPool() { // �ػ������� JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(20); config.setMaxIdle(5); config.setMaxWait(1000l); config.setTestOnBorrow(false); List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); JedisShardInfo infoA = new JedisShardInfo(ADDR, PORT); infoA.setPassword("redis"); shards.add(infoA); // ���Dz��� ��ʱ���������ķ������������ӷ��������� // JedisShardInfo infoB = new JedisShardInfo(SUB_ADDR, PORT2); // infoB.setPassword("redis"); // shards.add(infoB); // shards = Arrays.asList(infoA,infoB); shardedJedisPool = new ShardedJedisPool(config, shards, Hashing.MURMUR_HASH, ShardedJedis.DEFAULT_KEY_TAG_PATTERN); }
Example 4
Source File: ShardedJedisTest.java From cachecloud with Apache License 2.0 | 6 votes |
@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)); } }
Example 5
Source File: ShardedJedisTest.java From cachecloud with Apache License 2.0 | 6 votes |
@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()); } }
Example 6
Source File: RedisCacheClient.java From AsuraFramework with Apache License 2.0 | 5 votes |
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()); } }
Example 7
Source File: RedisShardedCacheClient.java From AsuraFramework with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: ShardedJedisTest.java From cachecloud with Apache License 2.0 | 5 votes |
@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); }
Example 9
Source File: RedisClientPool.java From nano-framework with Apache License 2.0 | 5 votes |
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); } }
Example 10
Source File: ShardedJedisPool.java From cachecloud with Apache License 2.0 | 4 votes |
public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, List<JedisShardInfo> shards) { this(poolConfig, shards, Hashing.MURMUR_HASH); }
Example 11
Source File: ShardedJedisPool.java From cachecloud with Apache License 2.0 | 4 votes |
public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, List<JedisShardInfo> shards, Pattern keyTagPattern) { this(poolConfig, shards, Hashing.MURMUR_HASH, keyTagPattern); }
Example 12
Source File: ShardedCacheFactory.java From howsun-javaee-framework with Apache License 2.0 | 4 votes |
public ShardedCacheFactory(final CacheFactoryConfig connectionConfig) { super(connectionConfig, new ShardedJedisFactory(connectionConfig.getJedisShardInfos(), Hashing.MURMUR_HASH, null)); }