本文整理匯總了Java中redis.clients.jedis.Jedis.lindex方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.lindex方法的具體用法?Java Jedis.lindex怎麽用?Java Jedis.lindex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.lindex方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: lindex
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String lindex(String key) {
Jedis jedis = null;
boolean success = true;
String ret = null;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.lindex(key, 0);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "lpop key:" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例2: addIndex
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@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;
}
示例3: lindex
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@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;
}
示例4: addIndex
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@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;
}