Skip to content

Add support for KeyValueOperations.findAllById(…) #655

Open

Description

@mp911de

Based on spring-projects/spring-data-redis#3150, we should introduce a new interface method returning multiple items by Id, something along the lines of KeyValueOperations.findAllById(Iterable<ID> ids, Class<T> type) and provide the necessary methods in KeyValueAdapter.

Activity

  1. dlwldnjs1009 commented on Jul 9, 2026

    @dlwldnjs1009

    I'd like to take this one. I ran into it in production with @RedisHash repositories, where findAllById issues one HGETALL round trip per id, and we currently work around it with executePipelined, same as reported in spring-projects/spring-data-redis#3150.

    Proposed shape, following the issue description:

    // KeyValueOperations
    <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> type);
    // KeyValueAdapter
    default <T> List<@Nullable T> getAll(Iterable<?> ids, String keyspace, Class<T> type) {
        // default implementation iterates get(id, keyspace, type)
    }

    getAll returns a list aligned with the given ids, with null for ids without a matching entry, so callers can correlate results with ids. KeyValueTemplate.findAllById uses that to keep publishing per-id beforeGet/afterGet events (batched: all beforeGet events before the lookup, then one afterGet per id). Store modules can override getAll with a batched implementation: a pipelined HGETALL in RedisKeyValueAdapter for spring-projects/spring-data-redis#3150, which I'd submit as a follow-up PR there.

    One deliberate choice: a new method name instead of overloading get. An overload get(Iterable, String, Class) shifts overload resolution for existing untyped calls: when(mock.get(any(), anyString(), any())) in MapRepositoriesConfigurationExtensionIntegrationTests silently binds to the new method, and third-party code stubbing or calling KeyValueAdapter the same way would break identically.

    SimpleKeyValueRepository.findAllById then delegates to KeyValueOperations.findAllById instead of looping findById.

    I have this implemented locally with unit and integration tests, but wanted to check the API shape here before opening a PR. Does the shape match what you had in mind, in particular the getAll naming and the null-preserving return?

  2. dlwldnjs1009 commented on Jul 21, 2026

    @dlwldnjs1009

    @mp911de Following up on my comment above: I have an implementation with unit and integration tests ready.

    Could you confirm whether KeyValueAdapter#getAll is the intended name and whether its position-aligned, null-preserving result contract is acceptable?

    I can open a PR once those API details are settled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions