Skip to content

Add configurable deletion strategy for Redis repository operations #2294 #3162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kssumin
Copy link

@kssumin kssumin commented May 28, 2025

Summary

This PR implements configurable deletion strategy for Redis repository operations, allowing applications to choose between synchronous DEL and asynchronous UNLINK commands for better performance optimization.

Background

Currently, Spring Data Redis repositories always use the blocking DEL command when updating existing keys, which can cause performance issues in update-intensive applications, especially when dealing with large data structures. Redis 4.0+ introduced the non-blocking UNLINK command as an alternative.

Changes

Core Implementation

  • DeletionStrategy enum: Defines DEL (default) and UNLINK options
  • RedisKeyValueAdapter:
    • Added setDeletionStrategy() and getDeletionStrategy() methods
    • Updated put(), delete(), and expiration handling to use configured strategy
    • Added applyDeletionStrategy() utility method
  • @EnableRedisRepositories: Extended with deletionStrategy attribute
  • RedisRepositoryConfigurationExtension: Updated to propagate configuration

Test Coverage

  • RedisKeyValueAdapterTests: Basic functionality and configuration tests
  • RedisRepositoryConfigurationExtensionUnitTests: Annotation configuration tests

Closes #2294

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 28, 2025
Allow applications to choose between DEL and UNLINK commands for Redis key deletion operations in repository contexts. This provides better performance for applications with frequent updates on existing keys, especially when dealing with large data structures under high load.

Changes include DeletionStrategy enum with DEL and UNLINK options, extension of @EnableRedisRepositories annotation with deletionStrategy attribute, updates to RedisKeyValueAdapter to apply the configured strategy, and comprehensive tests covering configuration and functionality.

Closes spring-projects#2294

Signed-off-by: Kim Sumin <[email protected]>
@kssumin kssumin force-pushed the feature/configurable-del-unlink-strategy branch from 6533bd7 to cd16fa3 Compare May 31, 2025 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Substitute/configure DEL for UNLINK on respository.save implementations
3 participants