-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add configurable deletion strategy for Redis repository operations #2294 #3162
Conversation
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 <ksoomin25@gmail.com>
6533bd7
to
cd16fa3
Compare
Thank you for getting in touch and taking the time to craft the PR.
There is a potential benefit of UNLINK
when working with large data structures as you mentioned.
However I'm not fully convinced we need to have the behaviour configurable here. UNLINK
calculates the cost of deleting the key and freeing the memory (in case of hash by looking at the number of elements). So it may do it immediately or later. Since Redis 6.0 lazyfree-lazy-user-del
offers a server side flag to mrodify the default behaviour of DEL
to act like UNLINK
.
Uh oh!
There was an error while loading. Please reload this page.
Summary
This PR implements configurable deletion strategy for Redis repository operations, allowing applications to choose between synchronous
DEL
and asynchronousUNLINK
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-blockingUNLINK
command as an alternative.Changes
Core Implementation
DeletionStrategy
enum: DefinesDEL
(default) andUNLINK
optionsRedisKeyValueAdapter
:setDeletionStrategy()
andgetDeletionStrategy()
methodsput()
,delete()
, and expiration handling to use configured strategyapplyDeletionStrategy()
utility method@EnableRedisRepositories
: Extended withdeletionStrategy
attributeRedisRepositoryConfigurationExtension
: Updated to propagate configurationTest Coverage
RedisKeyValueAdapterTests
: Basic functionality and configuration testsRedisRepositoryConfigurationExtensionUnitTests
: Annotation configuration testsCloses #2294