redis 질서 있 는 집합

4079 단어 자바redis
**
1.질서 있 는 집합 추가 또는 업데이트
**
	/**
	 * 
	 *        key member  
	   	Redis Zincrby                     increment

		            increment ,         ,   ZINCRBY key -5 member ,    member   score     5 。
		
		  key    ,      key     , ZINCRBY key increment member     ZADD key increment member 。
		
		  key         ,      。
		
		                。
	 * @param key
	 * @param increment
	 * @param member
	 */
	protected static Double zincrby(String key, double increment, String member) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.zincrby(key, increment, 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 null;
	}

2,조회 질서 집합
/**
	 *                   
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	protected static Set rangeWithScores(String key, long start, long end) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.zrevrangeWithScores(key, start, end);
		} 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,조회 순서 집합 총수
/**
	 *   zadd   
	 * @param key
	 * @return
	 */
	protected static long ZCARD(String key) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.zcard(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 0;
	}

**
4,질서 있 는 집합 제거
**
/**
	 *        
	 * 
	 * @param key
	 * @param members
	 * return 0,       ,1      
	 */
	protected static long ZREM(String key, String members) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.zrem(key, members);
		} 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;
	}

5.질서 있 는 집중 을 제거 하고 점수(score)구간 의 모든 구성원 을 지정 합 니 다.
/**
	 * Redis Zremrangebyscore           ,    (score)        。
	 */
	protected static Long zremrangebyscore(String key, double start, double end) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			return jedis.zremrangeByScore(key, start, end);
		} 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 0L;
	}

**
6,랭 킹 획득
**
/**
	 * 
	 * @param key
	 * @param member
	 * @return   
	 */
	protected static Long rank(String key, String member) {
		Jedis jedis = null;
		try {
			jedis = ConnectionManager.getConnection();
			Long zk = jedis.zrevrank(key, member);
			return zk;
		} catch (Exception e) {
			logger.info("redis bug:" + e.getMessage());
		} finally {
			try {
				ConnectionManager.closeConnection(jedis);
			} catch (Exception e) {
				logger.info("redis bug:" + e.getMessage()); 				
				logger.info(" kkkredis   jedis  " + e.getMessage());
			}
		}
	
		return -1l;
	}

좋은 웹페이지 즐겨찾기