Java Code Examples for redis.clients.jedis.ShardedJedis#smembers()

The following examples show how to use redis.clients.jedis.ShardedJedis#smembers() . 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: RedisClientImpl.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> sinter(final String... keys) {
    Assert.notEmpty(keys);
    ShardedJedis jedis = null;
    try {
        jedis = POOL.getJedis(config.getRedisType());
        final Collection<Jedis> allShards;
        if ((allShards = jedis.getAllShards()).size() == 1) {
            return allShards.iterator().next().sinter(keys);
        } else if (allShards.size() > 1) {
            final Set<String> diffSet = Sets.newLinkedHashSet();
            final Set<String> interSet = Sets.newLinkedHashSet();
            for (String key : keys) {
                final Set<String> now = jedis.smembers(key);
                diffSet.addAll(now);
                now.stream().filter(item -> diffSet.contains(item)).forEach(item -> interSet.add(item));
            }

            return interSet;
        }

        return Collections.emptySet();
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}
 
Example 2
Source File: RedisClientImpl.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> smembers(final String key) {
    Assert.hasText(key);
    ShardedJedis jedis = null;
    try {
        jedis = POOL.getJedis(config.getRedisType());
        return jedis.smembers(key);
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}