org.springframework.data.redis.core.BoundZSetOperations Java Examples

The following examples show how to use org.springframework.data.redis.core.BoundZSetOperations. 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: RedisDelayBucket.java    From Milkomeda with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public DelayJob poll(Integer index) {
    String name = bucketNames.get(index);
    BoundZSetOperations<String, String> bucket = getBucket(name);
    // 升序查第一个(最上面的是延迟/TTR过期的)
    Set<ZSetOperations.TypedTuple<String>> set = bucket.rangeWithScores(0, 1);
    if (CollectionUtils.isEmpty(set)) {
        return null;
    }
    ZSetOperations.TypedTuple<String> typedTuple = set.toArray(new ZSetOperations.TypedTuple[]{})[0];
    if (typedTuple.getValue() == null) {
        return null;
    }
    return DelayJob.compatibleDecode(typedTuple.getValue(), typedTuple.getScore());
}
 
Example #2
Source File: RedisDelayBucket.java    From Milkomeda with MIT License 5 votes vote down vote up
@Override
public void add(List<DelayJob> delayJobs) {
    String bucketName = getCurrentBucketName();
    BoundZSetOperations<String, String> bucket = getBucket(bucketName);
    Set<ZSetOperations.TypedTuple<String>> delayJobSet = delayJobs.stream()
            .map(delayJob -> new DefaultTypedTuple<>(delayJob.toSimple(), (double) delayJob.getDelayTime()))
            .collect(Collectors.toSet());
    bucket.add(delayJobSet);
}
 
Example #3
Source File: RedisDelayBucket.java    From Milkomeda with MIT License 5 votes vote down vote up
@Override
public void remove(Integer index, DelayJob delayJob) {
    String name = bucketNames.get(index);
    BoundZSetOperations<String, String> bucket = getBucket(name);
    // 优化后的方式删除
    if (delayJob.isUsedSimple()) {
        bucket.remove(delayJob.toSimple());
        return;
    }
    // 兼容旧方式序列化删除
    bucket.remove(JSONUtil.serialize(delayJob));
}
 
Example #4
Source File: RedisTest.java    From spring-boot-cookbook with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypedTuple() {

    Set<DefaultTypedTuple<Integer>> typedTupleSet = new HashSet<>();
    ArrayList<Integer> source = newArrayList(1, 2, 3, 4, 5, 6);
    for (int i = 0; i < source.size(); i++) {
        DefaultTypedTuple<Integer> typedTuple = new DefaultTypedTuple<>(source.get(i), i + 100.0);
        typedTupleSet.add(typedTuple);
    }
    BoundZSetOperations myzset = redisTemplate.boundZSetOps("myzset");
    myzset.add(typedTupleSet);
    System.out.println(myzset.range(0, -1));
}
 
Example #5
Source File: DefaultPersistenceService.java    From spring-boot-email-tools with Apache License 2.0 5 votes vote down vote up
protected void addOps(final EmailSchedulingData emailSchedulingData) {
    final String orderingKey = orderingKey(emailSchedulingData);
    final String valueKey = emailSchedulingData.getId();

    final double score = calculateScore(emailSchedulingData);

    BoundZSetOperations<String, String> orderingZSetOps = orderingTemplate.boundZSetOps(orderingKey);
    orderingZSetOps.add(valueKey, score);
    orderingZSetOps.persist();

    BoundValueOperations<String, EmailSchedulingData> valueValueOps = valueTemplate.boundValueOps(valueKey);
    valueValueOps.set(emailSchedulingData);
    valueValueOps.persist();
}
 
Example #6
Source File: DefaultPersistenceService.java    From spring-boot-email-tools with Apache License 2.0 5 votes vote down vote up
protected Collection<EmailSchedulingData> getNextBatchOps(final String orderingKey, final int batchMaxSize) {
    Preconditions.checkArgument(batchMaxSize > 0, "Batch size should be a positive integer.");

    final BoundZSetOperations<String, String> boundZSetOperations = orderingTemplate.boundZSetOps(orderingKey);
    final long amount = boundZSetOperations.size();
    final Set<String> valueIds = boundZSetOperations.range(0, max(0, min(amount, batchMaxSize) - 1));
    return valueIds.stream()
            .map(id -> getOps(id))
            .filter(Objects::nonNull)
            .collect(Collectors.toSet());
}
 
Example #7
Source File: CacheProcessor.java    From coolretailer with Apache License 2.0 4 votes vote down vote up
private BoundZSetOperations<String, String> getZSetOps() {
	return template.boundZSetOps("autocomplete");
}
 
Example #8
Source File: CacheProcessor.java    From coolretailer with Apache License 2.0 4 votes vote down vote up
private BoundZSetOperations<String, String> getZSetOpsForMissingProducts() {
	return template.boundZSetOps("missing");
}
 
Example #9
Source File: BQProcessor.java    From coolretailer with Apache License 2.0 4 votes vote down vote up
private BoundZSetOperations<String, String> getZSetOps() {
	return template.boundZSetOps("autocomplete");
}
 
Example #10
Source File: RedisDelayBucket.java    From Milkomeda with MIT License 4 votes vote down vote up
@Override
public void add(DelayJob delayJob) {
    String bucketName = getCurrentBucketName();
    BoundZSetOperations<String, String> bucket = getBucket(bucketName);
    bucket.add(delayJob.toSimple(), delayJob.getDelayTime());
}
 
Example #11
Source File: MyRedisTemplate.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
@Override
public BoundZSetOperations<K, V> boundZSetOps(K key) {
	throw new MethodNotSupportException("myRedisTemplate not support this method : boundZSetOps(K key) , please use opsForXX");
	//return new DefaultBoundZSetOperations<K, V>(key, this);
}
 
Example #12
Source File: RedisDelayBucket.java    From Milkomeda with MIT License 2 votes vote down vote up
/**
 * 获得桶的ZSet
 *
 * @param bucketName 桶名
 * @return BoundZSetOperations
 */
private BoundZSetOperations<String, String> getBucket(String bucketName) {
    return redisTemplate.boundZSetOps(bucketName);
}