本文整理匯總了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();
}
}