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

The following examples show how to use redis.clients.jedis.Jedis#linsert() . 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: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 通过key在list指定的位置之前或者之后 添加字符串元素
 * </p>
 *
 * @param key
 * @param where
 *            LIST_POSITION枚举类型
 * @param pivot
 *            list里面的value
 * @param value
 *            添加的value
 * @return
 */
public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot,
                    String value) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.linsert(key, where, pivot, value);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 2
Source File: JedisScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addIndex(String queueID, long index, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    remove(queueID, e.getKey());
    Jedis jedis = jedisPool.getResource();
    try {
        String poolQueueKey = makePoolQueueKey(queueID);
        Long length = jedis.llen(poolQueueKey);
        if (index <= length) {
            index = length - 1;
        }
        String position = jedis.lindex(makePoolQueueKey(queueID), index);
        if (isNil(position)) {
            jedis.rpush(poolQueueKey, e.getKey());
        } else {
            jedis.linsert(poolQueueKey, BinaryClient.LIST_POSITION.AFTER, position, e.getKey());
        }
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
    return true;
}
 
Example 3
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public Long linsert(String key, LIST_POSITION where, String pivot, String value) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.linsert(key, where, pivot, value);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 4
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 4 votes vote down vote up
@Override
public boolean addIndex(String queueID, long index, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        remove(queueID, e.getKey());
        // block 从1开始计数
        int block = blockID(index + 1);
        List<String> sliceQueue = sliceQueue(queueID);
        String sliceID;
        if (block - 1 < sliceQueue.size()) {
            sliceID = sliceQueue.get(block - 1);
        } else {
            // create a new slice
            sliceID = String.valueOf(block);
            if (!sliceQueue.contains(sliceID)) {
                Preconditions.checkArgument(index <= size(queueID));
                jedis.rpush(makeSliceQueueKey(queueID), sliceID);
            } else {
                sliceID = sliceQueue.get(sliceQueue.size() - 1);
            }
        }
        String poolQueueKey = makePoolQueueKey(queueID, sliceID);
        Long length = jedis.llen(poolQueueKey);
        long offset = blockOffset(index);
        if (offset <= length) {
            offset = length - 1;
        }
        String position = jedis.lindex(makePoolQueueKey(queueID, sliceID), offset);
        if (isNil(position)) {
            jedis.rpush(poolQueueKey, e.getKey());
        } else {
            jedis.linsert(poolQueueKey, BinaryClient.LIST_POSITION.AFTER, position, e.getKey());
        }
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
    } finally {
        unLockQueue(queueID);
    }
    return true;
}
 
Example 5
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long linsertbefore0(Jedis j, String key, String pivot, String value) {
	return j.linsert(key, LIST_POSITION.BEFORE, pivot, value);
}
 
Example 6
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long linsertafter0(Jedis j, String key, String pivot, String value) {
	return j.linsert(key, LIST_POSITION.AFTER, pivot, value);
}
 
Example 7
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 在指定位置插入记录
 * 
 * @param    key
 * @param where 前面插入或后面插入
 * @param    pivot 相对位置的内容
 * @param     value 插入的内容
 * @return 记录总数
 */
public long linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value) {
	Jedis jedis = getJedis();
	long count = jedis.linsert(key, where, pivot, value);
	jedis.close();
	return count;
}
 
Example 8
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 在指定位置插入记录
 * 
 * @param String
 *            key
 * @param LIST_POSITION
 *            前面插入或后面插入
 * @param byte[] pivot 相对位置的内容
 * @param byte[] value 插入的内容
 * @return 记录总数
 * */
public long linsert(byte[] key, LIST_POSITION where, byte[] pivot,
		byte[] value) {
	Jedis jedis = getJedis();
	long count = jedis.linsert(key, where, pivot, value);
	returnJedis(jedis);
	return count;
}