Example usage for org.springframework.data.redis.core BoundZSetOperations add

List of usage examples for org.springframework.data.redis.core BoundZSetOperations add

Introduction

In this page you can find the example usage for org.springframework.data.redis.core BoundZSetOperations add.

Prototype

@Nullable
Boolean add(V value, double score);

Source Link

Document

Add value to a sorted set at the bound key, or update its score if it already exists.

Usage

From source file:example.RedisOperationsTests.java

@Test
public void zrangeByLex() {

    BoundZSetOperations<String, String> zsets = redis.boundZSetOps("myzset");

    zsets.add("a", 0.0);
    zsets.add("b", 0.0);
    zsets.add("c", 0.0);
    zsets.add("d", 0.0);
    zsets.add("e", 0.0);
    zsets.add("f", 0.0);
    zsets.add("g", 0.0);

    zsets.persist();/* ww w.  ja  v a2s. c  om*/

    RedisConnection redisConnection = redisConnectionFactory.getConnection();

    redisConnection.zRangeByLex("myzset".getBytes(), Range.range().lte("c")).stream().//
            map(it -> new String(it)).//
            forEach(System.out::println);

    System.out.println("###");

    redisConnection.zRangeByLex("myzset".getBytes(), Range.range().lt("c")).stream().//
            map(it -> new String(it)).//
            forEach(System.out::println);

    System.out.println("###");

    redisConnection.zRangeByLex("myzset".getBytes(), Range.range().gt("aaa").lt("g")).stream().//
            map(it -> new String(it)).//
            forEach(System.out::println);
}

From source file:org.springframework.integration.redis.outbound.RedisCollectionPopulatingMessageHandler.java

@SuppressWarnings("unchecked")
private void handleZset(RedisZSet<Object> zset, final Message<?> message) throws Exception {
    final Object payload = message.getPayload();

    if (this.extractPayloadElements) {
        final BoundZSetOperations<String, Object> ops = (BoundZSetOperations<String, Object>) this.redisTemplate
                .boundZSetOps(zset.getKey());

        if ((payload instanceof Map<?, ?> && this.isMapValuesOfTypeNumber((Map<?, ?>) payload))) {
            final Map<Object, Number> pyloadAsMap = (Map<Object, Number>) payload;
            this.processInPipeline(new PipelineCallback() {
                public void process() {
                    for (Object key : pyloadAsMap.keySet()) {
                        Number d = pyloadAsMap.get(key);
                        ops.add(key, d == null ? determineScore(message)
                                : NumberUtils.convertNumberToTargetClass(d, Double.class));
                    }// w  ww  .j ava  2s .co  m
                }
            });
        } else if (payload instanceof Collection<?>) {
            this.processInPipeline(new PipelineCallback() {
                public void process() {
                    for (Object object : ((Collection<?>) payload)) {
                        ops.add(object, determineScore(message));
                    }
                }
            });
        } else {
            this.addToZset(zset, payload, this.determineScore(message));
        }
    } else {
        this.addToZset(zset, payload, this.determineScore(message));
    }
}

From source file:org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler.java

private void doIncrementOrOverwrite(final BoundZSetOperations<String, Object> ops, Object object, Double score,
        boolean increment) {
    if (increment) {
        ops.incrementScore(object, score);
    } else {/*www. j  ava2s. c o  m*/
        ops.add(object, score);
    }
}