本文整理汇总了Java中redis.clients.jedis.Jedis.llen方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.llen方法的具体用法?Java Jedis.llen怎么用?Java Jedis.llen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.llen方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: llen
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public Long llen(String key) {
Jedis jedis = null;
try {
jedis = getJedis();
if (jedis == null) {
logger.error("get jedis fail");
return null;
}
return jedis.llen(key);
} catch (JedisConnectionException e) {
if (jedis != null) {
jedis.close();
}
} finally {
returnJedisResource(jedis);
}
return null;
}
示例3: 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;
}
示例4: getLenByList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取list长度
* @param listKey
* @return
*/
public Long getLenByList(String listKey) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
Long result = jds.llen(listKey.getBytes());
return result;
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例5: 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;
}
示例6: 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;
}
示例7: getLeftCount
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public int getLeftCount(Task task) {
Jedis jedis = jedisPool.getResource();
try {
Long size = jedis.llen(RedisKeys.getQueueKey(task));
return size.intValue();
} finally {
jedis.close();
}
}
示例8: getLeftRequests
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public int getLeftRequests(String spiderName) {
Jedis jedis = pool.getResource();
try {
Long size = jedis.llen(getQueueKey(spiderName));
return size.intValue();
} finally {
pool.returnResource(jedis);
}
}
示例9: llen
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public Long llen(String key) {
Jedis jedis = null;
Long res = null;
try {
jedis = pool.getResource();
res = jedis.llen(key);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
示例10: getLeftRequestsCount
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public int getLeftRequestsCount(ISpider spider) {
Jedis jedis = pool.getResource();
try {
Long size = jedis.llen(getQueueKey(spider));
return size.intValue();
} finally {
jedis.close();
}
}
示例11: 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;
}