Java Code Examples for redis.clients.jedis.Jedis#zrem()

The following examples show how to use redis.clients.jedis.Jedis#zrem() . 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 newblog with Apache License 2.0 6 votes vote down vote up
public void zrem(String key, String member) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        if (jedis == null) {
            logger.error("get jedis fail");
        }
        jedis.zrem(key, member);
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
        }
    } finally {
        returnJedisResource(jedis);
    }
}
 
Example 2
Source File: JedisBlockingQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem pop(String queueID) {
    if (!lockQueue(queueID)) {
        throw new RuntimeException("failed to acquire resource queue for queueID: " + queueID);
    }
    Jedis jedis = jedisPool.getResource();
    try {
        ResourceItem resourceItem = poll(queueID);
        if (resourceItem == null) {
            return null;
        }
        jedis.zrem(makePoolQueueKey(queueID), resourceItem.getKey());
        return resourceItem;
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 3
Source File: JedisBlockingQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem remove(String queueID, String key) {
    lockQueue(queueID);
    Jedis jedis = jedisPool.getResource();
    try {
        String data = jedis.hget(makeDataKey(queueID), key);
        if (StringUtils.isBlank(data)) {
            VSCrawlerMonitor.recordOne(queueID + "_find_meta_data_failed");
            return null;
        }
        ResourceItem ret = JSONObject.toJavaObject(JSON.parseObject(data), ResourceItem.class);
        jedis.hdel(makePoolQueueKey(queueID), key);
        jedis.zrem(makePoolQueueKey(queueID), key);
        return ret;
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 4
Source File: RedisContainer.java    From bahir-flink with Apache License 2.0 6 votes vote down vote up
@Override
public void zrem(final String key, final String element) {
    Jedis jedis = null;
    try {
        jedis = getInstance();
        jedis.zrem(key, element);
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Cannot send Redis message with command ZREM to set {} error message {}",
                    key, e.getMessage());
        }
        throw e;
    } finally {
        releaseInstance(jedis);
    }
}
 
Example 5
Source File: KarmaDB.java    From VileBot with MIT License 6 votes vote down vote up
/**
 * Remove noun from the karma/rank set.
 * 
 * @param noun The noun to remove, if it exists.
 * @return true iff the noun existed before removing it.
 */
public static boolean remNoun( String noun )
{
    Long existed;

    Jedis jedis = pool.getResource();
    try
    {
        existed = jedis.zrem( keyOfKarmaSortedSet, noun );
    }
    finally
    {
        pool.returnResource( jedis );
    }

    if ( existed == null || existed != 1 )
    {
        return false;
    }
    return true;
}
 
Example 6
Source File: ChurchDB.java    From VileBot with MIT License 6 votes vote down vote up
public static boolean removeDonor( String noun )
{
    Long existed;
    Jedis jedis = pool.getResource();
    try
    {
        existed = jedis.zrem( keyOfChurchDonorSortedSet, noun );
    }
    finally
    {
        pool.returnResource( jedis );
    }
    if ( existed == null || existed != 1 )
    {
        return false;
    }

    return true;
}
 
Example 7
Source File: RedisPriorityScheduler.java    From webmagic with Apache License 2.0 6 votes vote down vote up
private String getRequest(Jedis jedis, Task task)
{
    String url;
    Set<String> urls = jedis.zrevrange(getZsetPlusPriorityKey(task), 0, 0);
    if(urls.isEmpty())
    {
        url = jedis.lpop(getQueueNoPriorityKey(task));
        if(StringUtils.isBlank(url))
        {
            urls = jedis.zrevrange(getZsetMinusPriorityKey(task), 0, 0);
            if(!urls.isEmpty())
            {
                url = urls.toArray(new String[0])[0];
                jedis.zrem(getZsetMinusPriorityKey(task), url);
            }
        }
    }
    else
    {
        url = urls.toArray(new String[0])[0];
        jedis.zrem(getZsetPlusPriorityKey(task), url);
    }
    return url;
}
 
Example 8
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key删除在zset中指定的value
 * </p>
 *
 * @param key
 * @param members
 *            可以使一个string 也可以是一个string数组
 * @return
 */
public Long zrem(String key, String... members) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.zrem(key, members);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 9
Source File: JedisUtil.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 删除排序集合中的元素成员
 *
 * @param key     集合key
 * @param members 成员名s
 * @return
 */
public static Long zrem(String key, String... members) {
    Long result = null;
    Jedis jedis = null;
    try {
        jedis = getResource();
        result = jedis.zrem(key, members);
    } catch (Exception e) {
        logger.warn("zrem {} = {}", key, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 10
Source File: JedisClientPool.java    From paas with Apache License 2.0 5 votes vote down vote up
@Override
public Long zrem(String key, String... members) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.zrem(key, members);
    jedis.close();
    return result;
}
 
Example 11
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public Long zrem(String key, String... members) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.zrem(key, members);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 12
Source File: RedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
/**
 * 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 14
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long zrem0(Jedis j, String key, String... members) {
	return j.zrem(key, members);
}
 
Example 15
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 从集合中删除成员
 * 
 * @param String
 *            key
 * @param String
 *            member
 * @return 返回1成功
 * */
public long zrem(String key, String member) {
	Jedis jedis = getJedis();
	long s = jedis.zrem(key, member);
	returnJedis(jedis);
	return s;
}