本文整理汇总了Java中redis.clients.jedis.ShardedJedis.getAllShards方法的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedis.getAllShards方法的具体用法?Java ShardedJedis.getAllShards怎么用?Java ShardedJedis.getAllShards使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.ShardedJedis
的用法示例。
在下文中一共展示了ShardedJedis.getAllShards方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCloseable
import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Test
public void checkCloseable() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
shards.get(0).setPassword("foobared");
shards.get(1).setPassword("foobared");
ShardedJedis jedisShard = new ShardedJedis(shards);
try {
jedisShard.set("shard_closeable", "true");
} finally {
jedisShard.close();
}
for (Jedis jedis : jedisShard.getAllShards()) {
assertTrue(!jedis.isConnected());
}
}
示例2: gets
import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
* 获取单个值
*
* @param likeKey 键
* @return 结果
*/
public List<String> gets(String likeKey) {
List<String> result = new ArrayList<>();
ShardedJedis shardedJedis = shardedJedisPool.getResource();
if (shardedJedis == null) {
return null;
}
try {
Collection<Jedis> jedisC = shardedJedis.getAllShards();
Iterator<Jedis> iter = jedisC.iterator();
while (iter.hasNext()) {
Jedis _jedis = iter.next();
Set<String> keys = _jedis.keys(likeKey + "*");
keys.forEach(s -> result.add(_jedis.get(s)));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
shardedJedis.close();
}
return result;
}