Example usage for org.springframework.data.redis.core RedisTemplate opsForValue

List of usage examples for org.springframework.data.redis.core RedisTemplate opsForValue

Introduction

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

Prototype

@Override
    public ValueOperations<K, V> opsForValue() 

Source Link

Usage

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

@Test
public void removalKeyValueTest() {
    RedisTemplate<String, Long> redis = new RedisTemplate<>();
    redis.setConnectionFactory(connectionFactory);
    redis.setKeySerializer(RedisStringSerializer.INSTANCE);
    redis.setValueSerializer(RedisLongSerializer.INSTANCE);
    redis.afterPropertiesSet();/* 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";

    Set<String> keys = redis.keys(key1);
    for (String foundKey : keys) {
        logger.debug("Found Key= " + foundKey + " value= " + ops.get(foundKey));
    }

    redis.delete(key2);

}

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

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

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

    String key1 = "miko-spring-postgresql:counter-test";
    String key2 = "miko-spring-postgresql:counter-test-2";

    Set<String> keys = redis.keys(key1);
    for (String foundKey : keys) {
        logger.debug("Found Key= " + foundKey + " value= " + ops.get(foundKey));
    }

    redis.delete(key2);

}

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

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

    ValueOperations<String, Long> ops = redis.opsForValue();
    String key = "spring-postgresql:counter-test";

    Long value = ops.get(key);
    logger.debug("VALUE = " + value);

    assertThat(value, notNullValue());
}

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

@Test
public void testKeyValue() {
    RedisTemplate<String, Long> redis = new RedisTemplate<>();
    redis.setConnectionFactory(connectionFactory);
    redis.setKeySerializer(RedisStringSerializer.INSTANCE);
    redis.setValueSerializer(RedisLongSerializer.INSTANCE);
    redis.afterPropertiesSet();//w  w w.ja  v a 2s  . c  o  m

    ValueOperations<String, Long> ops = redis.opsForValue();
    String key = "miko-spring-postgresql:counter-test";

    Long value = ops.get(key);
    logger.debug("VALUE = " + value);

    assertThat(value, notNullValue());
}

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 w w w.  j ava2  s .  c o  m*/

    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();//w w  w .j av a2s  .c o  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:org.ednovo.gooru.service.ResourceCassandraServiceImpl.java

private ValueOperations<String, String> getValueOperation() {
    RedisTemplate<String, String> redisStringTemplate = getRedisStringTemplate();
    ValueOperations<String, String> valueOps = redisStringTemplate.opsForValue();
    return valueOps;
}