本文整理了Java中redis.clients.jedis.Jedis.lrange()
方法的一些代码示例,展示了Jedis.lrange()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.lrange()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:lrange
[英]Return the specified elements of the list stored at the specified key. Start and end are zero-based indexes. 0 is the first element of the list (the list head), 1 the next element and so on.
For example LRANGE foobar 0 2 will return the first three elements of the list.
start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.
Consistency with range functions in various programming languages
Note that if you have a list of numbers from 0 to 100, LRANGE 0 10 will return 11 elements, that is, rightmost item is included. This may or may not be consistent with behavior of range-related functions in your programming language of choice (think Ruby's Range.new, Array#slice or Python's range() function).
LRANGE behavior is consistent with one of Tcl.
Out-of-range indexes
Indexes out of range will not produce an error: if start is over the end of the list, or start > end, an empty list is returned. If end is over the end of the list Redis will threat it just like the last element of the list.
Time complexity: O(start+n) (with n being the length of the range and start being the start offset)
[中]返回存储在指定键处的列表的指定元素。开始和结束是基于零的索引。0是列表的第一个元素(列表头),1是下一个元素,依此类推。
例如,LRANGE foobar 0 2将返回列表的前三个元素。
“开始”和“结束”也可以是负数,表示从列表末尾开始的偏移。例如,-1是列表的最后一个元素,-2是倒数第二个元素,依此类推。
与各种编程语言中的范围函数的一致性
请注意,如果您有一个从0到100的数字列表,LRANGE 0 10将返回11个元素,即包括最右边的项。这可能与所选编程语言中与范围相关的函数的行为一致,也可能不一致(想想Ruby的range.new、Array#slice或Python的range()函数)。
LRANGE行为与Tcl的行为一致。
超出范围索引
超出范围的索引不会产生错误:如果开始在列表末尾,或开始>结束,则返回空列表。如果结束在列表的末尾,Redis将像列表的最后一个元素一样威胁它。
时间复杂度:O(开始+n)(n是范围的长度,开始是开始偏移)
代码示例来源:origin: sohutv/cachecloud
@Override
public List<byte[]> execute(Jedis connection) {
return connection.lrange(key, start, end);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public List<String> execute(Jedis connection) {
return connection.lrange(key, start, end);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
public List<byte[]> execute(Jedis connection) {
return connection.lrange(keyByte, start, end);
}
}.runBinary(keyByte);
代码示例来源:origin: sohutv/cachecloud
@Override
public List<byte[]> lrange(byte[] key, long start, long end) {
Jedis j = getShard(key);
return j.lrange(key, start, end);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public List<String> lrange(String key, long start, long end) {
Jedis j = getShard(key);
return j.lrange(key, start, end);
}
代码示例来源:origin: caoxinyu/RedisClient
@Override
protected void command() {
jedis.select(db);
page = jedis.lrange(key, start, end);
}
代码示例来源:origin: caoxinyu/RedisClient
@Override
protected void command() {
jedis.select(db);
values = jedis.lrange(key, 0, -1);
}
代码示例来源:origin: Netflix/conductor
@Override
public List<String> lrange(String key, long start, long end) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.lrange(key, start, end);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: shuzheng/zheng
/**
* 获取会话列表
* @param offset
* @param limit
* @return
*/
public Map getActiveSessions(int offset, int limit) {
Map sessions = new HashMap();
Jedis jedis = RedisUtil.getJedis();
// 获取在线会话总数
long total = jedis.llen(ZHENG_UPMS_SERVER_SESSION_IDS);
// 获取当前页会话详情
List<String> ids = jedis.lrange(ZHENG_UPMS_SERVER_SESSION_IDS, offset, (offset + limit - 1));
List<Session> rows = new ArrayList<>();
for (String id : ids) {
String session = RedisUtil.get(ZHENG_UPMS_SHIRO_SESSION_ID + "_" + id);
// 过滤redis过期session
if (null == session) {
RedisUtil.lrem(ZHENG_UPMS_SERVER_SESSION_IDS, 1, id);
total = total - 1;
continue;
}
rows.add(SerializableUtil.deserialize(session));
}
jedis.close();
sessions.put("total", total);
sessions.put("rows", rows);
return sessions;
}
代码示例来源:origin: jfinal/jfinal
/**
* 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 指定。
* 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。
* 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
* <pre>
* 例子:
* 获取 list 中所有数据:cache.lrange(listKey, 0, -1);
* 获取 list 中下标 1 到 3 的数据: cache.lrange(listKey, 1, 3);
* </pre>
*/
@SuppressWarnings("rawtypes")
public List lrange(Object key, long start, long end) {
Jedis jedis = getJedis();
try {
List<byte[]> data = jedis.lrange(keyToBytes(key), start, end);
if (data != null) {
return valueListFromBytesList(data);
} else {
return new ArrayList<byte[]>(0);
}
}
finally {close(jedis);}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public List<byte[]> lRange(byte[] key, long start, long end) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().lrange(key, start, end)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().lrange(key, start, end)));
return null;
}
return connection.getJedis().lrange(key, start, end);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: jwpttcg66/NettyGameServer
public List<String> lrange(String key, int start, int stop) {
Jedis jedis = null;
boolean sucess = true;
List<String> ret;
try {
jedis = jedisPool.getResource();
ret = jedis.lrange(key, start, stop);
return ret;
} catch (Exception e) {
sucess = false;
returnBrokenResource(jedis, "lrange", e);
return null;
} finally {
if (sucess && jedis != null) {
returnResource(jedis);
}
}
}
代码示例来源:origin: spinnaker/kayenta
List<String> pendingUpdatesJsonList = jedis.lrange(pendingUpdatesKey, 0, -1);
代码示例来源:origin: spinnaker/kayenta
List<String> updatesThroughCheckpoint = jedis.lrange(pendingUpdatesKey, 0, -1);
StorageService configurationService =
storageServiceRepository
代码示例来源:origin: com.wso2telco.core/pcr-service
@Override
public List<String> getApplicationIdList(String sectorId) throws PCRException {
List<String> applicationIds = new ArrayList<String>();
Jedis jedis = RedisUtil.getInstance().getResource();
List<String> appidlist = jedis.lrange(sectorId, 0, -1);
for (String appinfo : appidlist) {
applicationIds.add(appinfo.split(":")[0]);
}
jedis.close();
return applicationIds;
}
代码示例来源:origin: OpenNMS/opennms
@Override
public List<String> getResourceIdsWithPrefix(Context context, String resourceIdPrefix) {
try (Jedis jedis = m_pool.getResource()) {
final List<String> elements = Lists.newArrayList(SEARCH_PREFIX, context.getId());
elements.addAll(m_resourceIdSplitter.splitIdIntoElements(resourceIdPrefix));
return jedis.lrange(m_resourceIdSplitter.joinElementsToId(elements).getBytes(), 0, -1).stream()
.map(bytes -> resourceId(METADATA_PREFIX, context.getId(), bytes))
.collect(Collectors.toList());
}
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis
protected List<String> listWorkIdsList(final byte[] queueBytes) throws IOException {
return Framework.getService(RedisExecutor.class).execute(jedis -> {
List<byte[]> keys = jedis.lrange(queueBytes, 0, -1);
List<String> list = new ArrayList<>(keys.size());
for (byte[] workIdBytes : keys) {
list.add(string(workIdBytes));
}
return list;
});
}
代码示例来源:origin: lordofthejars/nosql-unit
private static void checkListValues(RedisConnectionCallback redisConnectionCallback, JSONObject expectedListObject) throws Error {
JSONArray expectedValuesArray = (JSONArray) expectedListObject.get(VALUES_TOKEN);
List<byte[]> expectedListValues = extractListOfValues(expectedValuesArray);
Object expectedKey = expectedListObject.get(KEY_TOKEN);
byte[] key = toByteArray(expectedKey);
Jedis jedis = redisConnectionCallback.getActiveJedis(key);
checkType(jedis, expectedKey, key, "list");
List<byte[]> elements = jedis.lrange(key, 0, -1);
checkListSize(expectedListValues.size(), expectedKey, elements.size());
checkValueInList(expectedListValues, expectedKey, elements);
}
代码示例来源:origin: xetorthio/johm
public List<String> lrange(int start, int end) {
Jedis jedis = getResource();
List<String> lrange = jedis.lrange(key(), start, end);
returnResource(jedis);
return lrange;
}
代码示例来源:origin: gresrun/jesque
protected KeyInfo handleList(final Jedis jedis) {
final KeyInfo keyInfo = new KeyInfo(this.key, KeyType.LIST);
keyInfo.setSize(jedis.llen(this.key));
if (this.doArrayValue) {
keyInfo.setArrayValue(jedis.lrange(this.key, this.offset, this.offset + this.count));
}
return keyInfo;
}
内容来源于网络,如有侵权,请联系作者删除!