當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.sadd方法代碼示例

本文整理匯總了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;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:28,代碼來源:JedisUtils.java

示例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();
    }
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:19,代碼來源:RedisPriorityScheduler.java

示例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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:33,代碼來源:JedisUtils.java

示例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;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:RedisService.java

示例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;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:RedisService.java

示例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);
}
 
開發者ID:ran-jit,項目名稱:distributed-task-scheduler,代碼行數:20,代碼來源:RedisDataCache.java

示例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;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:32,代碼來源:JedisUtils.java

示例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);
}
 
開發者ID:redisson,項目名稱:redisson-benchmark,代碼行數:20,代碼來源:SetAddBenchmark.java

示例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();
    }
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:10,代碼來源:RedisScheduler.java

示例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);
	}
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:17,代碼來源:RedisUtil.java

示例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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:22,代碼來源:JedisUtils.java

示例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();
}
 
開發者ID:SamaGames,項目名稱:AntiCheat,代碼行數:8,代碼來源:PunishmentsManager.java

示例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);
	}
}
 
開發者ID:youngMen1,項目名稱:-Spring-SpringMVC-Mybatis-,代碼行數:17,代碼來源:RedisUtil.java

示例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();
        }
    }
}
 
開發者ID:xjtushilei,項目名稱:ScriptSpider,代碼行數:38,代碼來源:RedisScheduler.java

示例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();
    }

}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:11,代碼來源:RedisScheduler.java


注:本文中的redis.clients.jedis.Jedis.sadd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。