Skip to content

Conversation

@bsbodden
Copy link
Collaborator

@bsbodden bsbodden commented Sep 5, 2025

…a retrieval (#657)

The existsById() method in both RedisDocumentRepository and RedisEnhancedRepository was inefficiently retrieving entire data structures when only existence validation was needed. This optimization replaces the inherited Spring Data behavior with direct Redis EXISTS commands, providing significant performance gains.

Changes:

  • Override existsById() in SimpleRedisDocumentRepository and SimpleRedisEnhancedRepository
  • Use connection.keyCommands().exists() for O(1) existence checks
  • Properly handle composite IDs by implementing getKeyForId() helper methods
  • Apply ID filters and maintain full backward compatibility

Performance impact:

  • Documents: existsById() → findById() → JSON.GET → full document deserialization
  • Hashes: existsById() → findById() → HGETALL → full hash retrieval
  • After: existsById() → EXISTS → boolean result only
  • Eliminates unnecessary network transfer and CPU overhead for existence checks

…a retrieval (redis#657)

The existsById() method in both RedisDocumentRepository and RedisEnhancedRepository
was inefficiently retrieving entire data structures when only existence validation
was needed. This optimization replaces the inherited Spring Data behavior with
direct Redis EXISTS commands, providing significant performance gains.

Changes:
- Override existsById() in SimpleRedisDocumentRepository and SimpleRedisEnhancedRepository
- Use connection.keyCommands().exists() for O(1) existence checks
- Properly handle composite IDs by implementing getKeyForId() helper methods
- Apply ID filters and maintain full backward compatibility

Performance impact:
- Documents: existsById() → findById() → JSON.GET → full document deserialization
- Hashes: existsById() → findById() → HGETALL → full hash retrieval
- After: existsById() → EXISTS → boolean result only
- Eliminates unnecessary network transfer and CPU overhead for existence checks
@bsbodden bsbodden self-assigned this Sep 5, 2025
@bsbodden bsbodden merged commit a4c7654 into redis:main Sep 5, 2025
1 check passed
@bsbodden bsbodden deleted the bsb/issue-657 branch September 5, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant