Skip to content

Substitute/configure DEL for UNLINK on respository.save implementations #2294

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
gjafachini opened this issue Mar 30, 2022 · 2 comments · May be fixed by #3162
Open

Substitute/configure DEL for UNLINK on respository.save implementations #2294

gjafachini opened this issue Mar 30, 2022 · 2 comments · May be fixed by #3162
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@gjafachini
Copy link

On update intensive applications, where CrudRepository.save/saveAll is called many times on already existing keys, the current implementation uses DEL command before SET, and this puts some pressure on the DB since is blocking command.
E.g. https://github.com/spring-projects/spring-data-redis/blob/485bcad1108cdcb250157dbbc1bdad8c7fcac4af/src/main/asciidoc/reference/redis-repositories.adoc#replace-existing

Specially on larger structures, when you need to update a value many times, this behavior put a lot of pressure on the DB.
Each save on existing keys executes (setting TTL as well):
"DEL" "key"
"HMSET" "key" "_class" "something" "id" ...
"EXPIRE" "key" "259200"

Another place where DEL is used that could be substituted by UNLINK is when cleaning the secondary indexes on the ExpirationListener:
org.springframework.data.redis.core.RedisKeyValueAdapter.MappingExpirationListener#onMessage

I know from Redis 6 on we can configure to do DEL as UNLINK, however this would affect all applications. Would be useful to provide configuration for using DEL or UNLINK

The versions where this is observed:
<spring.boot.version>2.6.2</spring.boot.version>
<artifactId>redisson-spring-boot-starter</artifactId>
<redisson.version>3.16.7</redisson.version>

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 30, 2022
@mp911de mp911de added type: enhancement A general enhancement status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 4, 2022
@JunggiKim
Copy link

I want to contribute to this issue
Can you give me a direction?

@kssumin
Copy link

kssumin commented May 26, 2025

Hi team, @mp911de

I'd like to contribute to this issue.

My proposed implementation approach:

  • Add a configuration property (e.g., spring.data.redis.use-unlink-for-cleanup=false) with DEL as default to maintain backward compatibility
  • Modify RedisKeyValueAdapter and related deletion logic to use the configured command
  • Update both the save operation cleanup and expiration listener cleanup
  • Add comprehensive tests covering both DEL and UNLINK scenarios

Would this approach work for you? I can start working on a draft PR if you're okay with this direction.
Any specific implementation guidelines or patterns I should follow for this contribution?

Thanks!

kssumin added a commit to kssumin/spring-data-redis that referenced this issue 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: kssumin <ksoomin25@gmail.com>
kssumin added a commit to kssumin/spring-data-redis that referenced this issue May 31, 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 <ksoomin25@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants