Java Code Examples for redis.clients.jedis.Jedis#llen()
The following examples show how to use
redis.clients.jedis.Jedis#llen() .
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: JedisUtil.java From newblog with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: JedisScoredQueueStore.java From vscrawler with Apache License 2.0 | 6 votes |
@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 3
Source File: UpmsSessionDao.java From zheng with MIT License | 6 votes |
/** * 获取会话列表 * @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; }
Example 4
Source File: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
/** * <p> * 通过key返回list的长度 * </p> * * @param key * @return */ public Long llen(String key) { Jedis jedis = null; Long res = null; try { jedis = jedisPool.getResource(); res = jedis.llen(key); } catch (Exception e) { log.error(e.getMessage()); } finally { returnResource(jedisPool, jedis); } return res; }
Example 5
Source File: JedisUtil.java From Project with Apache License 2.0 | 5 votes |
/** * List长度 * * @param key * @return 长度 */ public long llen(byte[] key) { Jedis sjedis = getJedis(); long count = sjedis.llen(key); sjedis.close(); return count; }
Example 6
Source File: RedisClient.java From Mykit with Apache License 2.0 | 5 votes |
/** * 该方法不适用于普通的调用,该方法只针对于错误日志记录 * * @param key * @param field */ public void lpushForErrorMsg(String key, String field) { Jedis client = jedisPool.getResource(); try { if (client.llen(key) > 1000) { return; } client.lpush(key, field); } finally { // 向连接池“归还”资源 jedisPool.returnResourceObject(client); } }
Example 7
Source File: RedisClient.java From Mykit with Apache License 2.0 | 5 votes |
public long llen(String key) { Jedis client = jedisPool.getResource(); try { return client.llen(key); } finally { // 向连接池“归还”资源 jedisPool.returnResourceObject(client); } }
Example 8
Source File: RedisServiceImpl.java From ace-cache with Apache License 2.0 | 5 votes |
@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; }
Example 9
Source File: JedisUtil.java From BigData with GNU General Public License v3.0 | 5 votes |
/** * List长度 * * @param byte[] key * @return 长度 * */ public long llen(byte[] key) { // ShardedJedis sjedis = getShardedJedis(); Jedis sjedis = getJedis(); long count = sjedis.llen(key); returnJedis(sjedis); return count; }
Example 10
Source File: RedisManager.java From jee-universal-bms with Apache License 2.0 | 5 votes |
public Long llen(String key){ Long length=null; Jedis jedis = pool.getResource(); try { length=jedis.llen(key); } finally { pool.returnResource(jedis); } return length; }
Example 11
Source File: RedisTaskResultStore.java From helix with Apache License 2.0 | 5 votes |
@Override public long llen(String key) throws Exception { Jedis jedis = _jedisPool.getResource(); try { return jedis.llen(key); } finally { _jedisPool.returnResource(jedis); } }
Example 12
Source File: RedisScheduler.java From webmagic with Apache License 2.0 | 5 votes |
@Override public int getLeftRequestsCount(Task task) { Jedis jedis = pool.getResource(); try { Long size = jedis.llen(getQueueKey(task)); return size.intValue(); } finally { pool.returnResource(jedis); } }
Example 13
Source File: JedisSegmentScoredQueueStore.java From vscrawler with Apache License 2.0 | 4 votes |
@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 14
Source File: DefaultRedis.java From craft-atom with MIT License | 4 votes |
private Long llen0(Jedis j, String key) { return j.llen(key); }
Example 15
Source File: RedisClient.java From springboot-learn with MIT License | 2 votes |
/** * 列表获取长度 * * @param key * @return */ public Long llen(String key) { Jedis jedis = jedisPool.getResource(); return jedis.llen(key); }
Example 16
Source File: RedisClient.java From springboot-learn with MIT License | 2 votes |
/** * 列表获取长度 * * @param key * @return */ public Long llen(String key) { Jedis jedis = jedisPool.getResource(); return jedis.llen(key); }