本文整理汇总了Java中redis.clients.jedis.Jedis.sadd方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.sadd方法的具体用法?Java Jedis.sadd怎么用?Java Jedis.sadd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.sadd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSet
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 设置Set缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public static long setSet(String key, Set<String> value, int cacheSeconds) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(key)) {
jedis.del(key);
}
result = jedis.sadd(key, (String[])value.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
}
logger.debug("setSet {} = {}", key, value);
} catch (Exception e) {
logger.warn("setSet {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例2: pushWhenNoRepeat
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
protected void pushWhenNoRepeat(Task task, Request request) {
Jedis jedis = jedisPool.getResource();
try {
String content = serializer.serialize(request);
if(request.getPriority() == 0) {
jedis.rpush(RedisKeys.getQueueNoPriorityKey(task), content);
} else if (request.getPriority() > 0) {
jedis.zadd(RedisKeys.getZsetPlusPriorityKey(task), request.getPriority(), content);
} else {
jedis.zadd(RedisKeys.getZsetMinusPriorityKey(task), request.getPriority(), content);
}
jedis.sadd(RedisKeys.getSetKey(task), request.key());
} finally {
jedis.close();
}
}
示例3: setObjectSet
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 设置Set缓存
*
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public static long setObjectSet(String key, Set<Object> value, int cacheSeconds) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
jedis.del(key);
}
Set<byte[]> set = Sets.newHashSet();
for (Object o : value) {
set.add(toBytes(o));
}
result = jedis.sadd(getBytesKey(key), (byte[][]) set.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
}
logger.debug("setObjectSet {} = {}", key, value);
} catch (Exception e) {
logger.warn("setObjectSet {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例4: saddString
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public long saddString(String key, String value) {
Jedis jedis = null;
boolean success = true;
Long ret = 0L;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.sadd(key, value);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "saddString" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例5: saddStrings
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public long saddStrings(String key, String... values) {
Jedis jedis = null;
boolean success = true;
long ret = 0;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.sadd(key, values);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "saddStrings" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例6: sAdd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void sAdd(String key, String value) {
int tries = 0;
boolean sucess = false;
do {
tries++;
try {
Jedis jedis = pool.getResource();
jedis.sadd(key, value);
jedis.close();
sucess = true;
} catch (JedisConnectionException ex) {
log.error(RedisConstants.CONN_FAILED_RETRY_MSG + tries);
if (tries == numRetries)
throw ex;
}
} while (!sucess && tries <= numRetries);
}
示例7: setObjectSet
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 设置Set缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public static long setObjectSet(String key, Set<Object> value, int cacheSeconds) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
jedis.del(key);
}
Set<byte[]> set = Sets.newHashSet();
for (Object o : value){
set.add(toBytes(o));
}
result = jedis.sadd(getBytesKey(key), (byte[][])set.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
}
logger.debug("setObjectSet {} = {}", key, value);
} catch (Exception e) {
logger.warn("setObjectSet {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例8: main
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Bench<JedisPool> bench = new JedisBench() {
@Override
public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
Jedis jedis = benchInstance.getResource();
Timer.Context time = metrics.timer("set").time();
String key = "set_" + threadNumber;
jedis.sadd(key, data);
time.stop();
jedis.close();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例9: addRepeatCheck
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void addRepeatCheck(Task task, Request request) {
Jedis jedis = jedisPool.getResource();
try {
jedis.sadd(RedisKeys.getSetKey(task), request.key());
} finally {
jedis.close();
}
}
示例10: sadd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* sadd
* @param key
* @param value
* @param seconds
*/
public synchronized static void sadd(String key, String value, int seconds) {
try {
Jedis jedis = RedisUtil.getJedis();
jedis.sadd(key, value);
jedis.expire(key, seconds);
jedis.close();
} catch (Exception e) {
LOGGER.error("sadd error : " + e);
}
}
示例11: setSetAdd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 向Set缓存中添加值
*
* @param key 键
* @param value 值
* @return
*/
public static long setSetAdd(String key, String... value) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
result = jedis.sadd(key, value);
logger.debug("setSetAdd {} = {}", key, value);
} catch (Exception e) {
logger.warn("setSetAdd {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例12: addCheatLog
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public void addCheatLog(BasicCheatLog log)
{
// TODO: RestAPI endpoint?
Jedis jedis = SamaGamesAPI.get().getBungeeResource();
jedis.sadd("anticheat:log:" + log.getPlayerID(), new Gson().toJson(log));
jedis.close();
}
示例13: sadd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* sadd
* @param key
* @param value
* @param seconds
*/
public synchronized static void sadd(String key, String value, int seconds) {
try {
Jedis jedis = RedisUtil.getJedis();
jedis.sadd(key, value);
jedis.expire(key, seconds);
jedis.close();
} catch (Exception e) {
_log.error("sadd error : " + e);
}
}
示例14: push
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 写进去url种子
*
* @param urlSeed 种子
*/
@Override
public void push(UrlSeed urlSeed) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
if (urlSeed.getUrl() == null
|| urlSeed.getUrl().trim().equals("")
|| urlSeed.getUrl().trim().equals("#")
|| urlSeed.getUrl().trim().toLowerCase().contains("javascript:"))
return;
if (jedis.sismember(Prefix_Set, urlSeed.getUrl())) {
// logger.info("UrlSeed重复:" + urlSeed.getUrl());
} else {
jedis.sadd(Prefix_Set, urlSeed.getUrl());
Gson gson = new Gson();
String urlSeedJson = gson.toJson(urlSeed);
if (urlSeed.getPriority() == 5l) {
jedis.rpush(Prefix_Queue_default, urlSeedJson);
} else if (urlSeed.getPriority() > 5l) {
jedis.rpush(Prefix_Queue_high, urlSeedJson);
} else {
jedis.rpush(Prefix_Queue_low, urlSeedJson);
}
}
} catch (Exception e) {
logger.error("连接获取失败!", e);
} finally {
if (null != jedis) {
jedis.close();
}
}
}
示例15: isDuplicate
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public boolean isDuplicate(Request request, ISpider spider) {
Jedis jedis = pool.getResource();
try {
return jedis.sadd(getSetKey(spider), request.getUrl()) > 0;
} finally {
jedis.close();
}
}