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

The following examples show how to use redis.clients.jedis.ShardedJedisPipeline#srem() . 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 sreplace(final String key, final String[] oldMembers, final String[] newMembers) {
    Assert.hasText(key);
    ShardedJedis jedis = null;
    try {
        jedis = POOL.getJedis(config.getRedisType());
        final ShardedJedisPipeline pipeline = jedis.pipelined();
        if (!ArrayUtils.isEmpty(oldMembers)) {
            pipeline.srem(key, oldMembers);
        }

        Response<Long> response = null;
        if (!ArrayUtils.isEmpty(newMembers)) {
            response = pipeline.sadd(key, newMembers);
        }

        pipeline.sync();
        if (response != null) {
            return response.get();
        }

        return 0;
    } catch (final Throwable e) {
        throw new RedisClientException(e.getMessage(), e);
    } finally {
        POOL.close(jedis);
    }
}
 
Example 2
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;
		}
	}
}