redis隊列 list

1,添加隊列

/**
	 * add list
	 * 
	 * @param key
	 * @param member
	 */
	protected static long lpush(String key, String member) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.lpush(key, member);
		} catch (Exception e) {
			logger.info("redis bug:" + e.getMessage());
			
		} finally {
			try {
				ConnectionManager.closeConnection(jedis);
			} catch (Exception e) {
				logger.info("redis bug:" + e.getMessage());
				// TODO Auto-generated catch block
				
			}
		}
		return 0;
	}

2,查詢隊列

/**
	 * 查詢隊列
	 * @param key
	 * @param start   開始位置
	 * @param end	結束位置
	 * @return
	 */
	protected static List<String> lrange(String key,int start,int end) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			List<String> ls=jedis.lrange(key, start, end);
			return ls;
		} catch (Exception e) {
			logger.info("redis bug:" + e.getMessage());
			
		} finally {
			try {
				ConnectionManager.closeConnection(jedis);
			} catch (Exception e) {
				logger.info("redis bug:" + e.getMessage());
				// TODO Auto-generated catch block
				
			}
		}
		return null;
	}

3,移除最先插入到隊列的值

/**
	 * 移除最先插入到隊列的值
	 * @param key
	 * @return 被移除的值
	 */
	protected static String rpop(String key) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.rpop(key);
		} catch (Exception e) {
			logger.info("redis bug:" + e.getMessage());
			
		} finally {
			try {
				ConnectionManager.closeConnection(jedis);
			} catch (Exception e) {
				logger.info("redis bug:" + e.getMessage());
				// TODO Auto-generated catch block
				
			}
		}
		return null;
	}

4,獲取隊列長度

	/**
	 * 獲取隊列長度
	 * 
	 * @param key
	 * @param member
	 */
	protected static long llen(String key) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			Long l=jedis.llen(key);
			return l;
		} catch (Exception e) {
			logger.info("redis bug:" + e.getMessage());
			
		} finally {
			try {
				ConnectionManager.closeConnection(jedis);
			} catch (Exception e) {
				logger.info("redis bug:" + e.getMessage());
				// TODO Auto-generated catch block
				
			}
		}
		return 0;
	}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章