当前位置: 首页>>代码示例>>Java>>正文


Java ShardedJedisPipeline.sadd方法代码示例

本文整理汇总了Java中redis.clients.jedis.ShardedJedisPipeline.sadd方法的典型用法代码示例。如果您正苦于以下问题:Java ShardedJedisPipeline.sadd方法的具体用法?Java ShardedJedisPipeline.sadd怎么用?Java ShardedJedisPipeline.sadd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.ShardedJedisPipeline的用法示例。


在下文中一共展示了ShardedJedisPipeline.sadd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pAddSet

import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
public List<Object> pAddSet(String key, int seconds, String... values) {
    try (ShardedJedis shardedJedis = shardedJedisPool.getResource()) {
        ShardedJedisPipeline pipeline = shardedJedis.pipelined();
        for(String value : values) {
            pipeline.sadd(key, value);
        }
        pipeline.expire(key, seconds);
        List<Object> result = pipeline.syncAndReturnAll();
        result.remove(result.size() -1);
        return result;
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:13,代码来源:RedisTemplate.java

示例2: sreplace

import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:29,代码来源:RedisClientImpl.java

示例3: sdiffstore

import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:29,代码来源:RedisClientImpl.java

示例4: sinterstore

import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:32,代码来源:RedisClientImpl.java

示例5: sunionstore

import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:32,代码来源:RedisClientImpl.java

示例6: doCallback

import redis.clients.jedis.ShardedJedisPipeline; //导入方法依赖的package包/类
@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;
		}
	}
}
 
开发者ID:leopardoooo,项目名称:easyooo-framework,代码行数:30,代码来源:DefaultRedisTransactionCallback.java


注:本文中的redis.clients.jedis.ShardedJedisPipeline.sadd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。