本文整理汇总了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;
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
}