Java Code Examples for redis.clients.jedis.ShardedJedisPipeline#del()

The following examples show how to use redis.clients.jedis.ShardedJedisPipeline#del() . 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 long sdiffstore(final String destination, final String... keys) {
    Assert.hasText(destination);
    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().sdiffstore(destination, keys);
        } else if (allShards.size() > 1) {
            final Set<String> diffSet = sdiff(keys);
            if (!diffSet.isEmpty()) {
                final ShardedJedisPipeline pipeline = jedis.pipelined();
                pipeline.del(destination);
                final Response<Long> response = pipeline.sadd(destination, diffSet.toArray(new String[diffSet.size()]));
                pipeline.sync();
                return response.get();
            }
        }

        return 0;
    } 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 long sinterstore(final String destination, final String... keys) {
    Assert.hasText(destination);
    if (keys.length == 0) {
        return 0;
    }

    ShardedJedis jedis = null;
    try {
        jedis = POOL.getJedis(config.getRedisType());
        final Collection<Jedis> allShards;
        if ((allShards = jedis.getAllShards()).size() == 1) {
            return allShards.iterator().next().sinterstore(destination, keys);
        } else if (allShards.size() > 1) {
            Set<String> interSet = sinter(keys);
            if (!interSet.isEmpty()) {
                final ShardedJedisPipeline pipeline = jedis.pipelined();
                pipeline.del(destination);
                final Response<Long> response = pipeline.sadd(destination, interSet.toArray(new String[interSet.size()]));
                pipeline.sync();
                return response.get();
            }
        }

        return 0;
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}
 
Example 3
Source File: RedisClientImpl.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
@Override
public long sunionstore(final String destination, final String... keys) {
    Assert.hasText(destination);
    if (keys.length == 0) {
        return 0;
    }

    ShardedJedis jedis = null;
    try {
        jedis = POOL.getJedis(config.getRedisType());
        final Collection<Jedis> allShards;
        if ((allShards = jedis.getAllShards()).size() == 1) {
            return allShards.iterator().next().sunionstore(destination, keys);
        } else if (allShards.size() > 1) {
            final Set<String> unionSet = sunion(keys);
            if (!unionSet.isEmpty()) {
                final ShardedJedisPipeline pipeline = jedis.pipelined();
                pipeline.del(destination);
                final Response<Long> response = pipeline.sadd(destination, unionSet.toArray(new String[unionSet.size()]));
                pipeline.sync();
                return response.get();
            }
        }

        return 0;
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}
 
Example 4
Source File: DefaultRedisTransactionCallback.java    From easyooo-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void doCallback(ShardedJedisPipeline p) {
	for (Command cmd : redisCommands) {
		switch (cmd.getOp()) {
			case SET:
				p.set(cmd.getCacheKey(), cmd.getCacheValue());
				break;
			case MOD:
				p.set(cmd.getCacheKey(), cmd.getCacheValue());
				break;
			case DEL:
				p.del(cmd.getCacheKey());
				break;
			case ADD_MEMBERS:
				p.sadd(cmd.getCacheGroupKey(), cmd.getGroupValues());
				break;
			case DEL_MEMBERS:
				p.srem(cmd.getCacheGroupKey(), cmd.getGroupValues());
				break;
			case SETS:
				String[] keyvalues = cmd.getKeyvalues();
				for (int i = 0; i < keyvalues.length; i+=2) {
					p.set(keyvalues[i], keyvalues[i+1]);
				}
			default:
				break;
		}
	}
}