spring-projects / spring-projects/spring-data-redis

Feature Request: PlatformTransactionManager for Redis-only Applications

Open
#3,205 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Description

Currently, Spring Data Redis allows RedisTemplate to participate in transactions by enabling setEnableTransactionSupport(true). However, declarative transaction management (@Transactional) requires a PlatformTransactionManager. The current documentation assumes that applications already have a JDBC DataSourceTransactionManager or similar, which makes Redis transactions only usable in applications that also use a database.

For applications that use Redis exclusively, there is no out-of-the-box PlatformTransactionManager implementation. This limits the ability to use @Transactional or TransactionTemplate with Redis in a consistent Spring transaction management style.

Proposed Solution

Provide a new implementation of PlatformTransactionManager specifically for Redis-only applications. Key features could include:

  • Integration with RedisTemplate and its transaction support (MULTI/EXEC/DISCARD).
  • Thread-bound connection management, similar to current transactional support when setEnableTransactionSupport(true) is enabled.
  • Support for rollback semantics if an exception occurs within a @Transactional method.
  • Minimal or no dependencies on a JDBC DataSource.
Example Usage
@Configuration
@EnableTransactionManagement
public class RedisTxOnlyConfiguration {

    @Bean
    public StringRedisTemplate redisTemplate() {
        StringRedisTemplate template = new StringRedisTemplate(redisConnectionFactory());
        template.setEnableTransactionSupport(true);
        return template;
    }

    @Bean
    public RedisConnectionFactory redisConnectionFactory() {
        // Lettuce or Jedis
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new RedisTransactionManager(redisTemplate());
    }
}

This would allow fully declarative @Transactional support for Redis-only applications, making transaction management consistent across Spring components.

Benefits
  • Unified transaction management for Redis-only applications.
  • Reduces the need for workaround solutions using programmatic transaction handling.
  • Aligns Redis support with Spring’s existing transaction model.
Additional Context

Related documentation: [Spring Data Redis – Transaction Support](https://docs.spring.io/spring-data/redis/docs/current/reference/html/#redis:transactions)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring Data Redis transaction-support documentation and the existing RedisTemplate behavior when setEnableTransactionSupport(true) is enabled. Define the transaction manager's scope, connection binding, MULTI/EXEC/DISCARD handling, and rollback behavior for @Transactional and TransactionTemplate use in Redis-only applications.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.