@Override public boolean add(E e, double score) { Boolean result = boundZSetOps.add(e, score); checkResult(result); return result; }
@Override public Set<E> range(long start, long end) { return boundZSetOps.range(start, end); }
@Override public boolean remove(Object o) { Long result = boundZSetOps.remove(o); checkResult(result); return result == 1; }
@Override public Notifier notify( JobConfiguration id, NotificationLevel level, String message, boolean completed ) { if ( id != null && !(level != null && level.isOff()) ) { Notification notification = new Notification( level, id.getJobType(), new Date(), message, completed ); String notificationKey = generateNotificationKey( id.getJobType(), id.getUid() ); String notificationOrderKey = generateNotificationOrderKey( id.getJobType() ); Date now = new Date(); try { if ( redisTemplate.boundZSetOps( notificationOrderKey ).zCard() >= MAX_POOL_TYPE_SIZE ) { Set<String> deleteKeys = redisTemplate.boundZSetOps( notificationOrderKey ).range( 0, 0 ); redisTemplate.delete( deleteKeys ); redisTemplate.boundZSetOps( notificationOrderKey ).removeRange( 0, 0 ); } redisTemplate.boundZSetOps( notificationKey ).add( objectMapper.writeValueAsString( notification ), now.getTime() ); redisTemplate.boundZSetOps( notificationOrderKey ).add( id.getUid(), now.getTime() ); } catch ( JsonProcessingException ex ) { log.warn( String.format( NOTIFIER_ERROR, ex.getMessage() ) ); } log.info( notification ); } return this; }
private void doIncrementOrOverwrite(BoundZSetOperations<String, Object> ops, Object object, Double score, boolean increment) { if (increment) { ops.incrementScore(object, score); } else { ops.add(object, score); } }
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()); }
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(); }
public Iterable<Metric<?>> findAll() { // This set is sorted Set<String> keys = this.zSetOperations.range(0, -1); Iterator<String> keysIt = keys.iterator(); List<Metric<?>> result = new ArrayList<Metric<?>>(keys.size()); List<String> values = this.redisOperations.opsForValue().multiGet(keys); for (String v : values) { String key = keysIt.next(); Metric<?> value = deserialize(key, v, this.zSetOperations.score(key)); if (value != null) { result.add(value); } } return result; }
private void trackMembership(String redisKey) { this.zSetOperations.incrementScore(redisKey, 0.0D); }
@Override public Set<TypedTuple<E>> rangeWithScores(long start, long end) { return boundZSetOps.rangeWithScores(start, end); }
@Override public int size() { Long result = boundZSetOps.size(); checkResult(result); return result.intValue(); }
@Override public RedisZSet<E> remove(long start, long end) { boundZSetOps.removeRange(start, end); return this; }
@Override public Double score(Object o) { return boundZSetOps.score(o); }
if ( redisTemplate.boundZSetOps( summaryOrderKey ).zCard() >= MAX_POOL_TYPE_SIZE ) Set<String> summaryKeyToBeDeleted = redisTemplate.boundZSetOps( summaryOrderKey ).range( 0, 0 ); redisTemplate.boundZSetOps( summaryOrderKey ).removeRange( 0, 0 ); summaryKeyToBeDeleted.forEach( d -> redisTemplate.boundHashOps( summaryKey ).delete( d ) ); Date now = new Date(); redisTemplate.boundZSetOps( summaryOrderKey ).add( id.getUid(), now.getTime() );
private void doIncrementOrOverwrite(BoundZSetOperations<String, Object> ops, Object object, Double score, boolean increment) { if (increment) { ops.incrementScore(object, score); } else { ops.add(object, score); } }
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()); }
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(); }
@Override public void increment(String counterName, String fieldName, double score) { redisTemplate.boundZSetOps(getMetricKey(counterName)).incrementScore(fieldName, score); }
@Override public Set<TypedTuple<E>> rangeWithScores(long start, long end) { return boundZSetOps.rangeWithScores(start, end); }
public long count() { return this.zSetOperations.size(); }