Example usage for org.springframework.data.redis.core ValueOperations increment

List of usage examples for org.springframework.data.redis.core ValueOperations increment

Introduction

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

Prototype

@Nullable
Double increment(K key, double delta);

Source Link

Document

Increment a floating point number value stored as string value under key by delta .

Usage

From source file:com.pubkit.platform.persistence.impl.RedisDaoImpl.java

@Override
public void incrementKeyCount(String key) {
    ValueOperations<String, String> ops = this.redisTemplate.opsForValue();
    ops.increment(key, 1);
}

From source file:com.miko.demo.mongo.service.RedisInitTest.java

@Test
public void testRedisTemplate() {
    RedisTemplate<String, Long> redis = new RedisTemplate<>();
    redis.setConnectionFactory(connectionFactory);
    redis.setKeySerializer(RedisStringSerializer.INSTANCE);
    redis.setValueSerializer(RedisLongSerializer.INSTANCE);
    redis.afterPropertiesSet();/*from ww w  .  j a  v  a  2 s.  c om*/

    ValueOperations<String, Long> ops = redis.opsForValue();

    String key1 = "miko-spring-mongo:counter-test";
    String key2 = "miko-spring-mongo:counter-test-2";
    logger.debug("redistTemplate ops = " + ops);

    ops.setIfAbsent(key1, 1L);
    ops.setIfAbsent(key2, 22L);
    Long l = ops.increment(key1, 1);

    logger.debug("redistTemplate L = " + l);

    assertThat(l, is(greaterThan(0L)));
}

From source file:com.miko.demo.postgresql.service.RedisInitTest.java

@Test
public void testRedisTemplate() {
    RedisTemplate<String, Long> redis = new RedisTemplate<>();
    redis.setConnectionFactory(connectionFactory);
    redis.setKeySerializer(RedisStringSerializer.INSTANCE);
    redis.setValueSerializer(RedisLongSerializer.INSTANCE);
    redis.afterPropertiesSet();/*from   w ww .  j a  v  a 2s. co m*/

    ValueOperations<String, Long> ops = redis.opsForValue();

    String key1 = "miko-spring-postgresql:counter-test";
    String key2 = "miko-spring-postgresql:counter-test-2";
    logger.debug("redistTemplate ops = " + ops);

    ops.setIfAbsent(key1, 1L);
    ops.setIfAbsent(key2, 22L);
    Long l = ops.increment(key1, 1);

    logger.debug("redistTemplate L = " + l);

    assertThat(l, is(greaterThan(0L)));
}

From source file:com.company.project.service.dao.RedisDao.java

public void setIfAbsent(String key, Object value) {
    ValueOperations opsForValue = redisTemplate.opsForValue();
    boolean isAbsent = opsForValue.setIfAbsent(key, value);
    if (isAbsent) {
        long sub = opsForValue.increment(key, 11);
    }//from   w  ww  .j  a va 2 s  .  c o m
}