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

The following examples show how to use redis.clients.jedis.Jedis#lindex() . 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: 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 2
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key获取list中指定下标位置的value
 * </p>
 *
 * @param key
 * @param index
 * @return 如果没有返回null
 */
public String lindex(String key, long index) {
    Jedis jedis = null;
    String res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.lindex(key, index);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 3
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public String lindex(String key, long index) {
    Jedis jedis = null;
    String res = null;
    try {
        jedis = pool.getResource();
        res = jedis.lindex(key, index);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 4
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取List中指定位置的值
 * 
 * @param byte[] key
 * @param int index 位置
 * @return 值
 * **/
public byte[] lindex(byte[] key, int index) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	byte[] value = sjedis.lindex(key, index);
	returnJedis(sjedis);
	return value;
}
 
Example 5
Source File: RedisManager.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
public String lindex(String key,Long index){
    String value=null;
    Jedis jedis = pool.getResource();
    try {
        value =jedis.lindex(key,index);
    } finally {
        pool.returnResource(jedis);
    }
    return value;
}
 
Example 6
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 7
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private String lindex0(Jedis j, String key, long index) {
	return j.lindex(key, index);
}
 
Example 8
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 获取List中指定位置的值
 * 
 * @param key
 * @param  index 位置
 * @return 值
 **/
public byte[] lindex(byte[] key, int index) {
	Jedis sjedis = getJedis();
	byte[] value = sjedis.lindex(key, index);
	sjedis.close();
	return value;
}