本文整理汇总了Java中redis.clients.jedis.ShardedJedis.getShardInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedis.getShardInfo方法的具体用法?Java ShardedJedis.getShardInfo怎么用?Java ShardedJedis.getShardInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.ShardedJedis
的用法示例。
在下文中一共展示了ShardedJedis.getShardInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeysDifferentShard
import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
private List<String> getKeysDifferentShard(ShardedJedis jedis) {
List<String> ret = new ArrayList<String>();
JedisShardInfo first = jedis.getShardInfo("a0");
ret.add("a0");
for (int i = 1; i < 100; ++i) {
JedisShardInfo actual = jedis.getShardInfo("a" + i);
if (actual != first) {
ret.add("a" + i);
break;
}
}
return ret;
}
示例2: checkSharding
import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Test
public void checkSharding() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
ShardedJedis jedis = new ShardedJedis(shards);
List<String> keys = getKeysDifferentShard(jedis);
JedisShardInfo s1 = jedis.getShardInfo(keys.get(0));
JedisShardInfo s2 = jedis.getShardInfo(keys.get(1));
assertNotSame(s1, s2);
}
示例3: checkKeyTags
import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Test
public void checkKeyTags() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
ShardedJedis jedis = new ShardedJedis(shards, ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
assertEquals(jedis.getKeyTag("foo"), "foo");
assertEquals(jedis.getKeyTag("foo{bar}"), "bar");
assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is
// non greedy
assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear
// anywhere
assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear
// anywhere
JedisShardInfo s1 = jedis.getShardInfo("abc{bar}");
JedisShardInfo s2 = jedis.getShardInfo("foo{bar}");
assertSame(s1, s2);
List<String> keys = getKeysDifferentShard(jedis);
JedisShardInfo s3 = jedis.getShardInfo(keys.get(0));
JedisShardInfo s4 = jedis.getShardInfo(keys.get(1));
assertNotSame(s3, s4);
ShardedJedis jedis2 = new ShardedJedis(shards);
assertEquals(jedis2.getKeyTag("foo"), "foo");
assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar");
JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}");
JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}");
assertNotSame(s5, s6);
}
示例4: testAvoidLeaksUponDisconnect
import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
* Test for "Issue - BinaryShardedJedis.disconnect() may occur memory leak". You can find more
* detailed information at https://github.com/xetorthio/jedis/issues/808
* @throws InterruptedException
*/
@Test
public void testAvoidLeaksUponDisconnect() throws InterruptedException {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(2);
// 6379
JedisShardInfo shard1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
shard1.setPassword("foobared");
shards.add(shard1);
// 6380
JedisShardInfo shard2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
shard2.setPassword("foobared");
shards.add(shard2);
@SuppressWarnings("resource")
ShardedJedis shardedJedis = new ShardedJedis(shards);
// establish the connection for two redis servers
shardedJedis.set("a", "bar");
JedisShardInfo ak = shardedJedis.getShardInfo("a");
assertEquals(shard2, ak);
shardedJedis.set("b", "bar1");
JedisShardInfo bk = shardedJedis.getShardInfo("b");
assertEquals(shard1, bk);
// We set a name to the instance so it's easy to find it
Iterator<Jedis> it = shardedJedis.getAllShards().iterator();
Jedis deadClient = it.next();
deadClient.clientSetname("DEAD");
ClientKillerUtil.killClient(deadClient, "DEAD");
assertEquals(true, deadClient.isConnected());
assertEquals(false, deadClient.getClient().getSocket().isClosed());
assertEquals(false, deadClient.getClient().isBroken()); // normal - not found
shardedJedis.disconnect();
assertEquals(false, deadClient.isConnected());
assertEquals(true, deadClient.getClient().getSocket().isClosed());
assertEquals(true, deadClient.getClient().isBroken());
Jedis jedis2 = it.next();
assertEquals(false, jedis2.isConnected());
assertEquals(true, jedis2.getClient().getSocket().isClosed());
assertEquals(false, jedis2.getClient().isBroken());
}