DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis
  • How to Connect Redis Sentinel With Spring
  • Multi-Tenancy Implementation Using Spring Boot, MongoDB, and Redis
  • Spring Boot Application With Kafka, Elasticsearch, Redis With Enterprise Standards Part 1

Trending

  • After 9 Years, Microsoft Fulfills This Windows Feature Request
  • Memory Leak Due to Time-Taking finalize() Method
  • Caching 101: Theory, Algorithms, Tools, and Best Practices
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  1. DZone
  2. Coding
  3. Frameworks
  4. Reactive Spring Transactions in Redis

Reactive Spring Transactions in Redis

Learn how Redisson supports reactive Spring transactions.

By 
Nikita Koksharov user avatar
Nikita Koksharov
·
Updated Jan. 27, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
5.6K Views

Join the DZone community and get the full member experience.

Join For Free

Speaking of transactions...


Spring is an open-source, lightweight Java application framework that simplifies the process of developing enterprise software for the Java programming language. The Spring framework includes many core features that promote good software development practices, such as dependency injection and a model-view-controller (MVC) architectural pattern.

Reactive programming is a declarative programming paradigm that works with asynchronous data streams in order to respond to real-time events and build scalable, resilient, concurrent applications. Beginning with Spring Framework 5.2 M2, Spring includes support for reactive transaction management.

Spring includes a Spring Data Redis module for compatibility with Redis, an in-memory data structure store often used to build NoSQL databases. However, Spring doesn't provide support for Redis-based transactions out of the box. For this reason, many Java developers use a third-party Java Redis framework like Redisson to perform reactive Spring transactions in Redis.

Redisson: Reactive Spring Transactions in Redis

Redisson is a third-party open-source Redis Java client. By including distributed implementations of many common Java objects and collections, Redisson dramatically simplifies the process of using Java with Redis.

Redisson offers support for reactive Spring transactions in Redis via interfaces such as RedissonReactiveClient, RTransactionReactive, and ReactiveRedissonTransactionManager. To understand how these all work together, below is an example of how to do reactive Spring transactions in Redis using Redisson:

Java
 




xxxxxxxxxx
1
38


 
1
public class TransactionalBean {
2

          
3
    @Autowired
4
    private ReactiveRedissonTransactionManager transactionManager;
5

          
6
    @Transactional
7
    public Mono<Void> commitData() {
8
        Mono<RTransactionReactive> transaction = transactionManager.getCurrentTransaction();
9
        return transaction.flatMap(t -> {
10
            RMapReactive<String, String> map = t.getMap("myMap");
11
            return map.put("1", "2");
12
        }).then();
13
    }
14

          
15
}
16

          
17

          
18
@Configuration
19
@EnableTransactionManagement
20
public class RedissonReactiveTransactionContextConfig {
21
     
22
     @Bean
23
     public TransactionalBean transactionBean() {
24
         return new TransactionalBean();
25
     }
26
     
27
     @Bean
28
     public ReactiveRedissonTransactionManager transactionManager(RedissonReactiveClient redisson) {
29
         return new ReactiveRedissonTransactionManager(redisson);
30
     }
31
     
32
     @Bean(destroyMethod="shutdown")
33
     public RedissonReactiveClient redisson(@Value("classpath:/redisson.yaml") Resource configFile) throws IOException {
34
          Config config = Config.fromYAML(configFile.getInputStream());
35
         return Redisson.createReactive(config);
36
     }
37
     
38
}



Reactive Spring transactions in Redis are just one example of how developers can implement reactive programming, Java transactions, and the Spring framework using Redisson. The Spring framework is fully compatible with Redis, thanks to the Redisson Java client for Redis.

To get started using Spring with Redisson, check out the Configuration section in the Redisson project wiki. For more information about reactive programming and reactive Spring transactions in Redis, check out the Redisson website.

Further Reading

Using Spring Data Redis in Spring Boot 2.0 to Write a Custom Query

Implementation of Redis in a Microservice/Spring Boot Application

Spring Framework Redis (company)

Opinions expressed by DZone contributors are their own.

Related

  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis
  • How to Connect Redis Sentinel With Spring
  • Multi-Tenancy Implementation Using Spring Boot, MongoDB, and Redis
  • Spring Boot Application With Kafka, Elasticsearch, Redis With Enterprise Standards Part 1

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!