Java Code Examples for redis.clients.jedis.Jedis#smembers()
The following examples show how to use
redis.clients.jedis.Jedis#smembers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisUtil.java From scaffold-cloud with MIT License | 6 votes |
/** * 获取缓存 * * @param key 键 * @return 值 */ public static Set<String> getSet(String key) { Set<String> value = null; Jedis jedis = null; try { jedis = getResource(); if (jedis.exists(key)) { value = jedis.smembers(key); } } catch (Exception e) { logger.warn("getSet {} = {}", key, value, e); } finally { close(jedis); } return value; }
Example 2
Source File: JedisCache.java From charging_pile_cloud with MIT License | 6 votes |
/** * 获取集合 * * @param dbIndex * @param key * @return */ public static Set<String> getSetValue(int dbIndex, String key) { Set<String> result = null; Jedis jedis = null; try { jedis = jedisManager.getJedis(); jedis.select(dbIndex); result = jedis.smembers(key); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { jedis.close(); } return result; }
Example 3
Source File: JedisUtils.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 获取缓存 * @param key 键 * @return 值 */ public static Set<Object> getObjectSet(String key) { Set<Object> value = null; Jedis jedis = null; try { jedis = getResource(); if (jedis.exists(getBytesKey(key))) { value = Sets.newHashSet(); Set<byte[]> set = jedis.smembers(getBytesKey(key)); for (byte[] bs : set){ value.add(toObject(bs)); } logger.debug("getObjectSet {} = {}", key, value); } } catch (Exception e) { logger.warn("getObjectSet {} = {}", key, value, e); } finally { returnResource(jedis); } return value; }
Example 4
Source File: UrlJob.java From ispider with Apache License 2.0 | 6 votes |
@Override public void execute(JobExecutionContext context) throws JobExecutionException { /** * 1.从指定url种子仓库获取种子url * 2.将种子url添加进高优先级列表 */ Jedis jedis = JedisUtil.getJedis(); Set<String> seedUrls = jedis.smembers(SpiderConstants.SPIDER_SEED_URLS_KEY); // spider.seed.urls Redis数据类型为set,防止重复添加种子url for(String seedUrl : seedUrls) { String domain = SpiderUtil.getTopDomain(seedUrl); // 种子url的顶级域名 jedis.sadd(domain + SpiderConstants.SPIDER_DOMAIN_HIGHER_SUFFIX, seedUrl); logger.info("获取种子:{}", seedUrl); } JedisUtil.returnJedis(jedis); // System.out.println("Scheduler Job Test..."); }
Example 5
Source File: JedisUtil.java From BigData with GNU General Public License v3.0 | 5 votes |
/** * 返回集合中的所有成员 * * @param String * key * @return 成员集合 * */ public Set<String> smembers(String key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); Set<String> set = sjedis.smembers(key); returnJedis(sjedis); return set; }
Example 6
Source File: RedisJobStore.java From redis-quartz with MIT License | 5 votes |
/** * Store calendar in redis. * * @param name the name * @param calendar the calendar * @param replaceExisting the replace existing * @param updateTriggers the update triggers * @param jedis thread-safe redis connection * @throws ObjectAlreadyExistsException the object already exists exception * @throws JobPersistenceException */ private void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers, Jedis jedis) throws ObjectAlreadyExistsException, JobPersistenceException { String calendarHashKey = createCalendarHashKey(name); if (jedis.exists(calendarHashKey) && !replaceExisting) throw new ObjectAlreadyExistsException(calendarHashKey + " already exists"); Gson gson = new Gson(); Map<String, String> calendarHash = new HashMap<>(); calendarHash.put(CALENDAR_CLASS, calendar.getClass().getName()); calendarHash.put(CALENDAR_SERIALIZED, gson.toJson(calendar)); jedis.hmset(calendarHashKey, calendarHash); jedis.sadd(CALENDARS_SET, calendarHashKey); if (updateTriggers) { String calendarTriggersSetkey = createCalendarTriggersSetKey(name); Set<String> triggerHasjKeys = jedis.smembers(calendarTriggersSetkey); for (String triggerHashKey : triggerHasjKeys) { OperableTrigger trigger = retrieveTrigger(new TriggerKey(triggerHashKey.split(":")[2], triggerHashKey.split(":")[1]), jedis); long removed = jedis.zrem(RedisTriggerState.WAITING.getKey(), triggerHashKey); trigger.updateWithNewCalendar(calendar, getMisfireThreshold()); if (removed == 1) setTriggerState(RedisTriggerState.WAITING, (double)trigger.getNextFireTime().getTime(), triggerHashKey); } } }
Example 7
Source File: RedisDAO.java From jseckill with Apache License 2.0 | 5 votes |
/** * 从缓存中获取所有的实时商品数据(包括实时库存量) * @return */ public List<Seckill> getAllGoods() { List<Seckill> result = new ArrayList<>(); Jedis jedis = jedisPool.getResource(); Set<String> idSet = jedis.smembers(RedisKey.SECKILL_ID_SET); if (idSet != null || idSet.size() > 0) { for (String seckillId : idSet) { String goodsKey = RedisKeyPrefix.SECKILL_GOODS + seckillId; byte[] bytes = jedis.get(goodsKey.getBytes()); if (bytes != null) { Seckill seckill = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, seckill, schema); try { // goodsKey获取到的库存量是初始值,并不是当前值,所有需要从RedisKeyPrefix.SECKILL_INVENTORY+seckillID // 获取到的库存,再设置到结果中去 String inventoryStr = jedis.get(RedisKeyPrefix.SECKILL_INVENTORY + seckillId); if (!StringUtils.isEmpty(inventoryStr)) { seckill.setInventory(Integer.valueOf(inventoryStr)); } } catch (NumberFormatException ex) { logger.error(ex.getMessage(), ex); } result.add(seckill); } } } jedis.close(); return result; }
Example 8
Source File: RedisServiceImpl.java From ace-cache with Apache License 2.0 | 5 votes |
@Override public Set<String> smembers(String key) { Jedis jedis = null; Set<String> res = null; try { jedis = pool.getResource(); res = jedis.smembers(key); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { returnResource(pool, jedis); } return res; }
Example 9
Source File: RedisStorage.java From quartz-redis-jobstore with Apache License 2.0 | 5 votes |
/** * Store a {@link org.quartz.Calendar} * @param name the name of the calendar * @param calendar the calendar object to be stored * @param replaceExisting if true, any existing calendar with the same name will be overwritten * @param updateTriggers if true, any existing triggers associated with the calendar will be updated * @param jedis a thread-safe Redis connection * @throws JobPersistenceException */ @Override public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers, Jedis jedis) throws JobPersistenceException{ final String calendarHashKey = redisSchema.calendarHashKey(name); if(!replaceExisting && jedis.exists(calendarHashKey)){ throw new ObjectAlreadyExistsException(String.format("Calendar with key %s already exists.", calendarHashKey)); } Map<String, String> calendarMap = new HashMap<>(); calendarMap.put(CALENDAR_CLASS, calendar.getClass().getName()); try { calendarMap.put(CALENDAR_JSON, mapper.writeValueAsString(calendar)); } catch (JsonProcessingException e) { throw new JobPersistenceException("Unable to serialize calendar.", e); } Pipeline pipe = jedis.pipelined(); pipe.hmset(calendarHashKey, calendarMap); pipe.sadd(redisSchema.calendarsSet(), calendarHashKey); pipe.sync(); if(updateTriggers){ final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(name); Set<String> triggerHashKeys = jedis.smembers(calendarTriggersSetKey); for (String triggerHashKey : triggerHashKeys) { OperableTrigger trigger = retrieveTrigger(redisSchema.triggerKey(triggerHashKey), jedis); long removed = jedis.zrem(redisSchema.triggerStateKey(RedisTriggerState.WAITING), triggerHashKey); trigger.updateWithNewCalendar(calendar, misfireThreshold); if(removed == 1){ setTriggerState(RedisTriggerState.WAITING, (double) trigger.getNextFireTime().getTime(), triggerHashKey, jedis); } } } }
Example 10
Source File: JedisClientPool.java From paas with Apache License 2.0 | 5 votes |
@Override public Set<String> smembers(String key) { Jedis jedis = jedisPool.getResource(); Set<String> result = jedis.smembers(key); jedis.close(); return result; }
Example 11
Source File: RedisJobStore.java From redis-quartz with MIT License | 5 votes |
/** * Gets triggers for a job. * * @param jobTriggerHashkey the job_trigger hash key * @param jedis thread-safe redis connection * @return the triggers for the job * @throws JobPersistenceException */ private List<OperableTrigger> getTriggersForJob(String jobTriggerHashkey, Jedis jedis) throws JobPersistenceException { List<OperableTrigger> triggers = new ArrayList<>(); Set<String> triggerHashkeys = jedis.smembers(jobTriggerHashkey); for (String triggerHashkey : triggerHashkeys) triggers.add(retrieveTrigger(new TriggerKey(triggerHashkey.split(":")[2], triggerHashkey.split(":")[1]), jedis)); return triggers; }
Example 12
Source File: JedisClientPool.java From blog-sample with Apache License 2.0 | 5 votes |
@Override public Set<String> smembers(String key) { Jedis jedis = jedisPool.getResource(); Set<String> result = jedis.smembers(key); jedis.close(); return result; }
Example 13
Source File: JedisUtil.java From BigData with GNU General Public License v3.0 | 5 votes |
public Set<byte[]> smembers(byte[] key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); Set<byte[]> set = sjedis.smembers(key); returnJedis(sjedis); return set; }
Example 14
Source File: JedisUtil.java From Project with Apache License 2.0 | 5 votes |
/** * 返回集合中的所有成员 * * @param key * @return 成员集合 */ public Set<String> smembers(String key) { Jedis sjedis = getJedis(); Set<String> set = sjedis.smembers(key); sjedis.close(); return set; }
Example 15
Source File: QuoteFactDB.java From VileBot with MIT License | 5 votes |
/** * Get the facts of a noun. * * @param noun The noun to get the facts of * @return The set of facts for the noun */ public static Set<String> getFacts( String noun ) { Jedis jedis = pool.getResource(); try { return jedis.smembers( keyOfFactSetsPrefix + noun ); } finally { pool.returnResource( jedis ); } }
Example 16
Source File: RedisStore.java From datacollector with Apache License 2.0 | 5 votes |
public LookupValue get(Pair<String, DataType> pair) { Jedis jedis = pool.getResource(); LookupValue values; // check the type DataType type = pair.getRight(); String key = pair.getLeft(); switch (type) { case STRING: values = new LookupValue(jedis.get(key), type); break; case LIST: values = new LookupValue(jedis.lrange(key, 0, jedis.llen(key)), type); break; case HASH: values = new LookupValue(jedis.hgetAll(key), type); break; case SET: values = new LookupValue(jedis.smembers(key), type); break; default: values = null; } jedis.close(); return values; }
Example 17
Source File: RedisJobStore.java From redis-quartz with MIT License | 5 votes |
/** * Pause triggers. * * @param triggerGroupHashKey the trigger group hash key * @param jedis thread-safe redis connection * @throws JobPersistenceException */ private boolean pauseTriggers(String triggerGroupHashKey, Jedis jedis) throws JobPersistenceException { if (jedis.sadd(PAUSED_TRIGGER_GROUPS_SET, triggerGroupHashKey) > 0) { Set<String> triggers = jedis.smembers(triggerGroupHashKey); for(String trigger : triggers) pauseTrigger(new TriggerKey(trigger.split(":")[2], trigger.split(":")[1]), jedis); return true; } return false; }
Example 18
Source File: UserlistDB.java From VileBot with MIT License | 5 votes |
/** * Get the nicks in a userlist. * * @param noun The name of the list * @return The set of nicks for the list */ public static Set<String> getUsersIn( String listName ) { Jedis jedis = pool.getResource(); try { return jedis.smembers( keyOfUserlistSetsPrefix + listName ); } finally { pool.returnResource( jedis ); } }
Example 19
Source File: SomeOperate.java From Redis_Learning with Apache License 2.0 | 4 votes |
public static void SetOperate(Jedis jedis, ShardedJedis shardedJedis) { System.out.println("================set================="); System.out.println("��տ����������ݣ�" + jedis.flushDB()); System.out.println("=============��============="); System.out.println("��sets�����м���Ԫ��element001��" + jedis.sadd("sets", "element001")); System.out.println("��sets�����м���Ԫ��element002��" + jedis.sadd("sets", "element002")); System.out.println("��sets�����м���Ԫ��element003��" + jedis.sadd("sets", "element003")); System.out.println("��sets�����м���Ԫ��element004��" + jedis.sadd("sets", "element004")); System.out.println("��sets�����м���Ԫ��element001��" + jedis.sadd("sets", "element001")); System.out.println("�鿴sets�����е�����Ԫ��:" + jedis.smembers("sets")); System.out.println(); System.out.println("=============ɾ============="); System.out.println("����sets��ɾ��Ԫ��element003��" + jedis.srem("sets", "element003")); // smembers(key) ����������Ϊkey��set������Ԫ�� System.out.println("�鿴sets�����е�����Ԫ��:" + jedis.smembers("sets")); /* * System.out.println("sets����������λ�õ�Ԫ�س�ջ��"+jedis.spop("sets")); --��ʵ������ * System.out.println("�鿴sets�����е�����Ԫ��:"+jedis.smembers("sets")); */ System.out.println(); System.out.println("=============��============="); // sismember(key, member) ��member�Ƿ�������Ϊkey��set��Ԫ�� System.out.println("�ж�element001�Ƿ��ڼ���sets�У�" + jedis.sismember("sets", "element001")); // scard(key) ����������Ϊkey��set�Ļ��� System.out.println("������ " + jedis.scard("sets")); System.out.println("ѭ����ѯ��ȡsets�е�ÿ��Ԫ�أ�"); Set<String> set = jedis.smembers("sets"); Iterator<String> it = set.iterator(); while (it.hasNext()) { Object obj = it.next(); System.out.println(obj); } System.out.println(); System.out.println("=============��������============="); System.out.println("sets1�����Ԫ��element001��" + jedis.sadd("sets1", "element001")); System.out.println("sets1�����Ԫ��element002��" + jedis.sadd("sets1", "element002")); System.out.println("sets1�����Ԫ��element003��" + jedis.sadd("sets1", "element003")); System.out.println("sets2�����Ԫ��element002��" + jedis.sadd("sets2", "element002")); System.out.println("sets2�����Ԫ��element003��" + jedis.sadd("sets2", "element003")); System.out.println("sets2�����Ԫ��element004��" + jedis.sadd("sets2", "element004")); System.out.println("�鿴sets1�����е�����Ԫ��:" + jedis.smembers("sets1")); System.out.println("�鿴sets2�����е�����Ԫ��:" + jedis.smembers("sets2")); System.out.println("sets1��sets2������" + jedis.sinter("sets1", "sets2")); System.out.println("sets1��sets2������" + jedis.sunion("sets1", "sets2")); // ��A��B���������ϣ�����������A�Ҳ�����B��Ԫ�ع��ɵļ���,Ϊ����� System.out.println("sets1��sets2���" + jedis.sdiff("sets1", "sets2")); }
Example 20
Source File: Main.java From JavaBase with MIT License | 4 votes |
private void transferSet(String key, Jedis originJedis, Jedis targetJedis) { Set<String> members = originJedis.smembers(key); String[] temp = new String[members.size()]; String[] result = members.toArray(temp); targetJedis.sadd(key, result); }