org.springframework.data.redis.core.ZSetOperations.TypedTuple Java Examples

The following examples show how to use org.springframework.data.redis.core.ZSetOperations.TypedTuple. 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: RqueueQDetailServiceImpl.java    From rqueue with Apache License 2.0 6 votes vote down vote up
private List<List<Serializable>> buildRows(
    List<TypedTuple<RqueueMessage>> rqueueMessages, RowBuilder rowBuilder) {
  if (CollectionUtils.isEmpty(rqueueMessages)) {
    return Collections.emptyList();
  }
  List<String> ids =
      rqueueMessages.stream()
          .map(e -> Objects.requireNonNull(e.getValue()).getId())
          .map(MessageUtils::getMessageMetaId)
          .collect(Collectors.toList());

  List<MessageMetadata> vals = rqueueMessageMetadataService.findAll(ids);
  Map<String, Boolean> msgIdToDeleted =
      vals.stream().collect(Collectors.toMap(MessageMetadata::getMessageId, e -> true));
  return rqueueMessages.stream()
      .map(
          e ->
              rowBuilder.row(
                  e.getValue(),
                  msgIdToDeleted.getOrDefault(e.getValue().getId(), false),
                  e.getScore()))
      .collect(Collectors.toList());
}
 
Example #2
Source File: RqueueQDetailServiceImpl.java    From rqueue with Apache License 2.0 6 votes vote down vote up
private DataViewResponse responseForZset(
    String name, String key, int pageNumber, int itemPerPage) {
  DataViewResponse response = new DataViewResponse();
  int start = pageNumber * itemPerPage;
  int end = start + itemPerPage - 1;
  List<List<Serializable>> rows = new ArrayList<>();
  if (!StringUtils.isEmpty(key)) {
    Double score = stringRqueueRedisTemplate.getZsetMemberScore(name, key);
    response.setHeaders(Collections.singletonList("Score"));
    rows.add(Collections.singletonList(score));
  } else {
    response.setHeaders(Arrays.asList("Item", "Score"));
    for (TypedTuple<String> tuple : stringRqueueRedisTemplate.zrangeWithScore(name, start, end)) {
      rows.add(Arrays.asList(String.valueOf(tuple.getValue()), tuple.getScore()));
    }
  }
  response.setRows(rows);
  return response;
}
 
Example #3
Source File: RedisDelayeTimeRound.java    From ecp-uid with Apache License 2.0 6 votes vote down vote up
/**
 * @方法名称 lockLoad
 * @功能描述 <pre>需要一小时加载一次</pre>
 */
@Override
public void lockLoad() {
    // 一小时的数据量
    long start = System.currentTimeMillis();
    long end = start + 3600000;
    Set<TypedTuple<String>> set = new HashSet<>();
    for (int i = 0; i < queueSize; i++) {
        set.addAll(redisTemplate.boundZSetOps(RedisDelayMsgServiceImpl.TOPIC_DELAYE + i).rangeByScoreWithScores(start, end));
    }
    set.stream().collect(Collectors.groupingBy(TypedTuple::getScore)).entrySet().stream().forEach(item -> {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(item.getKey().longValue());
        bucketBuffer[calendar.get(Calendar.SECOND)] = item.getValue().stream().map(TypedTuple::getValue).collect(Collectors.toList());
    });
}
 
Example #4
Source File: AbstractOperations.java    From redis-admin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
Set<Tuple> rawTupleValues(Set<TypedTuple<V>> values) {
	if (values == null) {
		return null;
	}
	Set<Tuple> rawTuples = new LinkedHashSet<Tuple>(values.size());
	for (TypedTuple<V> value : values) {
		byte[] rawValue;
		if (valueSerializer() == null && value.getValue() instanceof byte[]) {
			rawValue = (byte[]) value.getValue();
		} else {
			rawValue = valueSerializer().serialize(value.getValue());
		}
		rawTuples.add(new DefaultTuple(rawValue, value.getScore()));
	}
	return rawTuples;
}
 
Example #5
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 6 votes vote down vote up
@Override
public Cursor<TypedTuple<V>> scan(K key, final ScanOptions options) {

	final byte[] rawKey = rawKey(key);
	Cursor<Tuple> cursor = execute(new RedisCallback<Cursor<Tuple>>() {

		@Override
		public Cursor<Tuple> doInRedis(RedisConnection connection) throws DataAccessException {
			connection.select(dbIndex);
			return connection.zScan(rawKey, options);
		}
	}, true);

	return new ConvertingCursor<Tuple, TypedTuple<V>>(cursor, new Converter<Tuple, TypedTuple<V>>() {

		@Override
		public TypedTuple<V> convert(Tuple source) {
			return deserializeTuple(source);
		}
	});
}
 
Example #6
Source File: RqueueQDetailServiceImpl.java    From rqueue with Apache License 2.0 5 votes vote down vote up
private List<TypedTuple<RqueueMessage>> readFromZset(
    String name, int pageNumber, int itemPerPage) {
  long start = pageNumber * (long) itemPerPage;
  long end = start + itemPerPage - 1;

  return rqueueMessageTemplate.readFromZset(name, start, end).stream()
      .map(e -> new DefaultTypedTuple<>(e, null))
      .collect(Collectors.toList());
}
 
Example #7
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, final double min, final double max, final long offset,
		final long count) {
	final byte[] rawKey = rawKey(key);

	Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

		public Set<Tuple> doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zRevRangeByScoreWithScores(rawKey, min, max, offset, count);

		}
	}, true);

	return deserializeTupleValues(rawValues);
}
 
Example #8
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max, final long offset,
		final long count) {
	final byte[] rawKey = rawKey(key);

	Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

		public Set<Tuple> doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zRangeByScoreWithScores(rawKey, min, max, offset, count);
		}
	}, true);

	return deserializeTupleValues(rawValues);
}
 
Example #9
Source File: RqueueQDetailServiceTest.java    From rqueue with Apache License 2.0 5 votes vote down vote up
@Test
public void viewDataZset() {
  Set<TypedTuple<Object>> objects = new HashSet<>();
  objects.add(new DefaultTypedTuple<>("Test", 100.0));
  objects.add(
      new DefaultTypedTuple<>(
          RqueueMessageFactory.buildMessage(null, "jobs", null, null), 200.0));

  List<List<Serializable>> rows = new ArrayList<>();
  for (TypedTuple<Object> typedTuple : objects) {
    List<Serializable> row = new ArrayList<>();
    row.add(String.valueOf(typedTuple.getValue()));
    row.add(typedTuple.getScore());
    rows.add(row);
  }
  DataViewResponse expectedResponse = new DataViewResponse();
  List<String> headers = new ArrayList<>();
  headers.add("Item");
  headers.add("Score");
  expectedResponse.setHeaders(headers);

  expectedResponse.setRows(rows);

  doReturn(objects).when(stringRqueueRedisTemplate).zrangeWithScore("jobs", 0, 9);
  DataViewResponse response = rqueueQDetailService.viewData("jobs", DataType.ZSET, null, 0, 10);

  assertEquals(expectedResponse, response);
}
 
Example #10
Source File: RValue.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public static Object creatZSetValue(Set<TypedTuple<Object>> values) {
	List<RValue> rValues = new ArrayList<RValue>();
	for(TypedTuple<Object> v:values) {
		rValues.add(new RValue(v.getScore(), v.getValue()));
	}
	return rValues;
}
 
Example #11
Source File: RqueueMessageTemplateImpl.java    From rqueue with Apache License 2.0 5 votes vote down vote up
@Override
public List<TypedTuple<RqueueMessage>> readFromZsetWithScore(String name, long start, long end) {
  Set<TypedTuple<RqueueMessage>> messages = zrangeWithScore(name, start, end);
  if (messages == null) {
    return new ArrayList<>();
  }
  return new ArrayList<>(messages);
}
 
Example #12
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, final double min, final double max) {
	final byte[] rawKey = rawKey(key);

	Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

		public Set<Tuple> doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zRevRangeByScoreWithScores(rawKey, min, max);

		}
	}, true);

	return deserializeTupleValues(rawValues);
}
 
Example #13
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max) {
	final byte[] rawKey = rawKey(key);

	Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

		public Set<Tuple> doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zRangeByScoreWithScores(rawKey, min, max);
		}
	}, true);

	return deserializeTupleValues(rawValues);
}
 
Example #14
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Set<TypedTuple<V>> reverseRangeWithScores(K key, final long start, final long end) {
	final byte[] rawKey = rawKey(key);

	Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

		public Set<Tuple> doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zRevRangeWithScores(rawKey, start, end);
		}
	}, true);

	return deserializeTupleValues(rawValues);
}
 
Example #15
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Set<TypedTuple<V>> rangeWithScores(K key, final long start, final long end) {
	final byte[] rawKey = rawKey(key);

	Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

		public Set<Tuple> doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zRangeWithScores(rawKey, start, end);
		}
	}, true);

	return deserializeTupleValues(rawValues);
}
 
Example #16
Source File: DefaultZSetOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public Long add(K key, Set<TypedTuple<V>> tuples) {
	final byte[] rawKey = rawKey(key);
	final Set<Tuple> rawValues = rawTupleValues(tuples);

	return execute(new RedisCallback<Long>() {

		public Long doInRedis(RedisConnection connection) {
			connection.select(dbIndex);
			return connection.zAdd(rawKey, rawValues);
		}
	}, true);
}
 
Example #17
Source File: AbstractOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
TypedTuple<V> deserializeTuple(Tuple tuple) {
	Object value = tuple.getValue();
	if (valueSerializer() != null) {
		value = valueSerializer().deserialize(tuple.getValue());
	}
	return new DefaultTypedTuple(value, tuple.getScore());
}
 
Example #18
Source File: AbstractOperations.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
Set<TypedTuple<V>> deserializeTupleValues(Collection<Tuple> rawValues) {
	if (rawValues == null) {
		return null;
	}
	Set<TypedTuple<V>> set = new LinkedHashSet<TypedTuple<V>>(rawValues.size());
	for (Tuple rawValue : rawValues) {
		set.add(deserializeTuple(rawValue));
	}
	return set;
}
 
Example #19
Source File: DefaultTypedTuple.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(TypedTuple<V> o) {

	if (o == null) {
		return compareTo(Double.valueOf(0));
	}

	return compareTo(o.getScore());
}
 
Example #20
Source File: RedisDao.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
public void addZSET(String serverName, int dbIndex, String key,
		double[] scores, String[] members) {
	RedisTemplate<String, Object> redisTemplate = redisTemplateFactory.getRedisTemplate(serverName);
	redisConnectionDbIndex.set(dbIndex);
	Set<TypedTuple<Object>> zset = new HashSet<TypedTuple<Object>>();
	for(int i=0;i<members.length;i++) {
		final Object ob = members[i];
		final double sc = scores[i];
		zset.add(new TypedTuple () {
			private Object v;
			private double score;
			{
				v = ob;
				score = sc;
			}
			@Override
			public int compareTo(Object o) {
				if(o == null) return 1;
				if(o instanceof TypedTuple) {
					TypedTuple tto = (TypedTuple) o;
					return this.getScore()-tto.getScore() >= 0?1:-1;
				}
				return 1;
			}
			@Override
			public Object getValue() {
				return v;
			}
			@Override
			public Double getScore() {
				return score;
			}
		});
	}
	redisTemplate.opsForZSet().add(key, zset);
}
 
Example #21
Source File: ZSetCommandTest.java    From ehousechina with Apache License 2.0 5 votes vote down vote up
/**
	 * 返回有序集 key 中, score 值介于 max 和 min 之间(默认包括等于 max 或 min )的所有的成员。有序集成员按 score 值递减(从大到小)的次序排列。
	 */
	@Test
public void testZrevrangebyscore() {
		/*Set<String> set=template.opsForZSet().reverseRangeByScore(ZSetKey.ZSETKEY.toString(), 1, 4);
		for(String v:set){
			log.info(">> {}",v);
		}*/
		Set<TypedTuple<String>> set=template.opsForZSet().reverseRangeByScoreWithScores(ZSetKey.ZSETKEY.toString(), 1, 4);
		for(TypedTuple v:set){
			log.info(">> {}-{}",v.getValue(),v.getScore());
		}
	}
 
Example #22
Source File: ZSetCommandTest.java    From ehousechina with Apache License 2.0 5 votes vote down vote up
/**
	 * 返回有序集 key 中,指定区间内的成员。
	 */
	@Test
public void testZrevrange() {
		/*long value=template.opsForZSet().reverseRank(ZSetKey.ZSETKEY.toString(), SimpleData.ZHANGSAN.getKey());
		log.info(">> {}",value);*/
		Set<TypedTuple<String>> set=template.opsForZSet().reverseRangeWithScores(ZSetKey.ZSETKEY.toString(), 1, 4);
		for(TypedTuple v:set){
			log.info(">> {}",v.getScore());
		}
	}
 
Example #23
Source File: ZSetCommandTest.java    From ehousechina with Apache License 2.0 5 votes vote down vote up
/**
	 * 返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从小到大)次序排列。
	 */
	@Test
public void testZrangebyscore() {
		/*Set<String> set=template.opsForZSet().rangeByScore(ZSetKey.ZSETKEY.toString(), 1, 4);
		for(String v:set){
			log.info(">> {}",v);
		}*/
		Set<TypedTuple<String>> set=template.opsForZSet().rangeByScoreWithScores(ZSetKey.ZSETKEY.toString(), 1, 4);
		for(TypedTuple v:set){
			log.info(">> {}-{}",v.getValue(),v.getScore());
		}
	}
 
Example #24
Source File: RqueueQDetailServiceImpl.java    From rqueue with Apache License 2.0 5 votes vote down vote up
private List<TypedTuple<RqueueMessage>> readFromList(
    String name, int pageNumber, int itemPerPage) {
  long start = pageNumber * (long) itemPerPage;
  long end = start + itemPerPage - 1;
  return rqueueMessageTemplate.readFromList(name, start, end).stream()
      .map(e -> new DefaultTypedTuple<>(e, null))
      .collect(Collectors.toList());
}
 
Example #25
Source File: DefaultBoundZSetOperations.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public Set<TypedTuple<V>> rangeWithScores(long start, long end) {
	return ops.rangeWithScores(getKey(), start, end);
}
 
Example #26
Source File: RqueueQDetailServiceImpl.java    From rqueue with Apache License 2.0 4 votes vote down vote up
private List<TypedTuple<RqueueMessage>> readFromZetWithScore(
    String name, int pageNumber, int itemPerPage) {
  long start = pageNumber * (long) itemPerPage;
  long end = start + itemPerPage - 1;
  return rqueueMessageTemplate.readFromZsetWithScore(name, start, end);
}
 
Example #27
Source File: RqueueRedisTemplate.java    From rqueue with Apache License 2.0 4 votes vote down vote up
public Set<TypedTuple<V>> zrangeWithScore(String key, long start, long end) {
  return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
}
 
Example #28
Source File: DefaultBoundZSetOperations.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public Long add(Set<TypedTuple<V>> tuples) {
	return ops.add(getKey(), tuples);
}
 
Example #29
Source File: DefaultBoundZSetOperations.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor<TypedTuple<V>> scan(ScanOptions options) {
	return ops.scan(getKey(), options);
}
 
Example #30
Source File: RedisDao.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public Object getZSET(String serverName, int dbIndex, String key) {
	RedisTemplate<String, Object> redisTemplate = redisTemplateFactory.getRedisTemplate(serverName);
	redisConnectionDbIndex.set(dbIndex);
	Set<TypedTuple<Object>> values = redisTemplate.opsForZSet().rangeWithScores(key, 0, 1000);
	return RValue.creatZSetValue(values);
}