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

The following examples show how to use redis.clients.jedis.Jedis#lrem() . 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: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem remove(String queueID, String key) {
    if (!lockQueue(queueID)) {
        return null;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        String dataJson = jedis.hget(makeDataKey(queueID), key);
        if (isNil(dataJson)) {
            return null;
        }
        jedis.hdel(makeDataKey(queueID), key);
        // lrem很消耗资源,尽量减少该命令操作
        for (String slice : sliceQueue(queueID)) {
            if (jedis.lrem(makePoolQueueKey(queueID, slice), 1, key) > 0) {
                break;
            }
        }
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        unLockQueue(queueID);
    }
}
 
Example 2
Source File: JedisScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem remove(String queueID, String key) {
    if (!lockQueue(queueID)) {
        return null;
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String dataJson = jedis.hget(makeDataKey(queueID), key);
        if (isNil(dataJson)) {
            return null;
        } else {
            jedis.hdel(makeDataKey(queueID), key);
            //lrem很消耗资源,尽量减少该命令操作
            jedis.lrem(makePoolQueueKey(queueID), 1, key);
        }
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 3
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key从对应的list中删除指定的count个 和 value相同的元素
 * </p>
 *
 * @param key
 * @param count
 *            当count为0时删除全部
 * @param value
 * @return 返回被删除的个数
 */
public Long lrem(String key, long count, String value) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.lrem(key, count, value);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 4
Source File: RedisUtil.java    From zhcc-server with Apache License 2.0 5 votes vote down vote up
/**
 * lrem
 * @param key
 * @param count
 * @param value
 */
public synchronized static void lrem(String key, long count, String value) {
	try {
		Jedis jedis = RedisUtil.getJedis();
		jedis.lrem(key, count, value);
		jedis.close();
	} catch (Exception e) {
		LOGGER.error("lpush error : " + e);
	}
}
 
Example 5
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public Long lrem(String key, long count, String value) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.lrem(key, count, value);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 6
Source File: RedisUtil.java    From zheng with MIT License 5 votes vote down vote up
/**
 * lrem
 * @param key
 * @param count
 * @param value
 */
public synchronized static void lrem(String key, long count, String value) {
	try {
		Jedis jedis = RedisUtil.getJedis();
		jedis.lrem(key, count, value);
		jedis.close();
	} catch (Exception e) {
		LOGGER.error("lpush error : " + e);
	}
}
 
Example 7
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long lrem0(Jedis j, String key, long count, String value) {
	return j.lrem(key, count, value);
}
 
Example 8
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 删除List中c条记录,被删除的记录值为value
 * 
 * @param  key
 * @param  c 要删除的数量,如果为负数则从List的尾部检查并删除符合的记录
 * @param  value 要匹配的值
 * @return 删除后的List中的记录数
 */
public long lrem(byte[] key, int c, byte[] value) {
	Jedis jedis = getJedis();
	long count = jedis.lrem(key, c, value);
	jedis.close();
	return count;
}
 
Example 9
Source File: ListCacheOperate.java    From xian with Apache License 2.0 3 votes vote down vote up
/**
 * List 移除元素
 *
 * @param jedis    jedis object
 * @param key      the cache key
 * @param valueObj the value object
 * @return 注意:
 * if count is greater than 0 : 从表头开始向表尾搜索, 移除与 VALUE 相等的元素, 数量为 COUNT
 * if count is lower than 0 : 从表尾开始向表头搜索, 移除与 VALUE 相等的元素, 数量为 COUNT 的绝对值
 * if count equals 0 : 移除列表中所有与 VALUE 相等的值
 */
public static long remove(Jedis jedis, String key, Object valueObj) {
    final int count = 1; // > 0

    String value = FormatUtil.formatValue(valueObj);

    return jedis.lrem(key, count, value);
}
 
Example 10
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 删除List中c条记录,被删除的记录值为value
 * 
 * @param byte[] key
 * @param int c 要删除的数量,如果为负数则从List的尾部检查并删除符合的记录
 * @param byte[] value 要匹配的值
 * @return 删除后的List中的记录数
 * */
public long lrem(byte[] key, int c, byte[] value) {
	Jedis jedis = getJedis();
	long count = jedis.lrem(key, c, value);
	returnJedis(jedis);
	return count;
}