本文整理汇总了Java中redis.clients.jedis.Jedis.lrange方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.lrange方法的具体用法?Java Jedis.lrange怎么用?Java Jedis.lrange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.lrange方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerService
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 注册服务
* 将服务URL保存到redis的list集合中
* @param serviceUrl:http://192.168.0.100:8080/工程名
*/
public boolean registerService(String serviceUrl){
Jedis jedis = JedisTemplate.getJedis();
Long len;
Long tmp;
try{
len = jedis.llen(onlineServices);
tmp = len;
List<String> services = jedis.lrange(onlineServices, 0, -1);
if(!services.contains(serviceUrl)){
len = jedis.rpush("onlineServices", serviceUrl);
if(tmp + 1 == len){
return true;
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
jedis.close();
}
return false;
}
示例2: getVByList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 往redis里取list
*
* @param <T>
* @param listKey
* @param start
* @param end
* @param requiredType
* @return
*/
@SuppressWarnings("unchecked")
public <T> List<T> getVByList(String listKey,int start,int end,Class<T> requiredType) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
List<T> list = new ArrayList<T>();
List<byte[]> xx = jds.lrange(listKey.getBytes(),start,end);
for (byte[] bs : xx) {
T t = SerializeUtil.deserialize(bs, requiredType);
list.add(t);
}
return list;
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例3: getAllService
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取所有服务列表
*/
public List<String> getAllService(){
Jedis jedis = JedisTemplate.getJedis();
List<String> services = null;
try{
services = jedis.lrange(onlineServices, 0, -1);
}catch(Exception e){
e.printStackTrace();
}finally{
jedis.close();
}
return services;
}
示例4: getList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取List缓存
*
* @param key 键
* @return 值
*/
public static List<String> getList(String key) {
List<String> value = null;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.lrange(key, 0, -1);
logger.debug("getList {} = {}", key, value);
}
} catch (Exception e) {
logger.warn("getList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return value;
}
示例5: getObjectList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取List缓存
*
* @param key 键
* @return 值
*/
public static List<Object> getObjectList(String key) {
List<Object> value = null;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
List<byte[]> list = jedis.lrange(getBytesKey(key), 0, -1);
value = Lists.newArrayList();
for (byte[] bs : list) {
value.add(toObject(bs));
}
logger.debug("getObjectList {} = {}", key, value);
}
} catch (Exception e) {
logger.warn("getObjectList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return value;
}
示例6: lrange
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public List<String> lrange(String key, int start, int stop) {
Jedis jedis = null;
boolean success = true;
List<String> ret = null;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.lrange(key, start, stop);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "lrange", e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例7: lrange
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public List<String> lrange(String key) {
Jedis jedis = null;
try {
jedis = getJedis();
if (jedis == null) {
logger.error("get jedis fail");
}
List<String> list = jedis.lrange(key, 0, 50);
return list;
} catch (JedisConnectionException e) {
if (jedis != null) {
jedis.close();
}
} finally {
returnJedisResource(jedis);
}
return null;
}
示例8: getActiveSessions
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取会话列表
* @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;
}
示例9: getList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取List缓存
* @param key 键
* @return 值
*/
public static List<String> getList(String key) {
List<String> value = null;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.lrange(key, 0, -1);
logger.debug("getList {} = {}", key, value);
}
} catch (Exception e) {
logger.warn("getList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return value;
}
示例10: getObjectList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取List缓存
* @param key 键
* @return 值
*/
public static List<Object> getObjectList(String key) {
List<Object> value = null;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
List<byte[]> list = jedis.lrange(getBytesKey(key), 0, -1);
value = Lists.newArrayList();
for (byte[] bs : list){
value.add(toObject(bs));
}
logger.debug("getObjectList {} = {}", key, value);
}
} catch (Exception e) {
logger.warn("getObjectList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return value;
}
示例11: getActiveSessions
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取会话列表
* @param offset
* @param limit
* @return
*/
public Map getActiveSessions(int offset, int limit) {
Map sessions = new HashMap();
Jedis jedis = RedisUtil.getJedis();
// 获取在线会话总数
long total = jedis.llen(LAMBO_UPMS_SERVER_SESSION_IDS);
// 获取当前页会话详情
List<String> ids = jedis.lrange(LAMBO_UPMS_SERVER_SESSION_IDS, offset, (offset + limit - 1));
List<Session> rows = new ArrayList<>();
for (String id : ids) {
String session = RedisUtil.get(LAMBO_UPMS_SHIRO_SESSION_ID + "_" + id);
// 过滤redis过期session
if (null == session) {
RedisUtil.lrem(LAMBO_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;
}
示例12: lrange
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public List<String> lrange(String key, long start, long end) {
Jedis jedis = null;
List<String> res = null;
try {
jedis = pool.getResource();
res = jedis.lrange(key, start, end);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
示例13: index
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 此操作可能消耗资源较多,因为需要传递所有数据到内存,如果遇到问题在考虑优化吧
*
* @param queueID 队列id
* @param key 待查找的资源
* @return 该资源当前在队列的位置, 如果该资源在队列中不存在, 则返回-1
*/
@Override
public long index(String queueID, String key) {
if (!lockQueue(queueID)) {
return -1;
}
Jedis jedis = jedisPool.getResource();
try {
List<String> queue = jedis.lrange(makePoolQueueKey(queueID), 0, -1);
return queue.indexOf(key);
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
}
示例14: sliceQueue
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private List<String> sliceQueue(String queueID) {
if (!lockQueue(queueID)) {
throw new IllegalStateException("error for acquire queue lock for queue :" + queueID);
}
@Cleanup Jedis jedis = jedisPool.getResource();
try {
return jedis.lrange(makeSliceQueueKey(queueID), 0, -1);
} finally {
unLockQueue(queueID);
}
}