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

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

Introduction

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

Prototype

public void setEnableTransactionSupport(boolean enableTransactionSupport) 

Source Link

Document

If set to true RedisTemplate will use MULTI...EXEC|DISCARD to keep track of operations.

Usage

From source file:com.company.project.config.DataConfig.java

@Bean
public RedisTemplate<String, Object> redisTemplate() {
    //        RedisTemplate<String, Blog> template = new RedisTemplate<>();
    //        template.setConnectionFactory(redisConfig.redisConnectionFactory());
    //        template.setKeySerializer(new StringRedisSerializer());
    //        template.setValueSerializer(new JacksonJsonRedisSerializer<>(Blog.class));
    //        template.setHashKeySerializer(new StringRedisSerializer());
    //        template.setHashValueSerializer(new JacksonJsonRedisSerializer<>(Blog.class));
    //        return template;

    //RedisTemplate<String, String> template = new StringRedisTemplate(redisConnectionFactory());
    RedisTemplate<String, Object> template = new RedisTemplate();
    template.setConnectionFactory(redisConnectionFactory());
    // explicitly enable transaction support - 4.9.1. @Transactional Support http://docs.spring.io/spring-data/redis/docs/current/reference/html/
    template.setEnableTransactionSupport(true);
    return template;
}

From source file:org.shareok.data.redis.UserDaoImpl.java

@Transactional
public void test2() {
    RedisTemplate<String, Object> redis = new RedisTemplate<>();
    redis.setConnectionFactory(connectionFactory);
    //        redis.setKeySerializer(ApplicationConfig.StringSerializer.INSTANCE);
    //        redis.setValueSerializer(new JacksonJsonRedisSerializer<User>(UserDaoImpl.class));
    redis.afterPropertiesSet();/*from   ww  w. ja  va2  s.co m*/
    redis.setEnableTransactionSupport(true);//???redistemplate?
    redis.multi();
    redis.boundValueOps("somevkey").increment(1);
    redis.boundZSetOps("somezkey").add("zvalue", 11);
    redis.exec();
    redis.setEnableTransactionSupport(false);
}