当前位置: 首页>>代码示例>>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;未经允许,请勿转载。