Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

redis-om-spring

> 后端框架
Open source

Spring Data Redis extensions for better search, documents models, and more

655 stars0 likes0 views
WebsiteGitHub

About

Spring Data Redis extensions for better search, documents models, and more

Object Mapping (and more) for Redis!


Redis OM Spring extends Spring Data Redis to take full advantage of Redis. Read the Official Docs here Redis OM Spring

Stage Release Snapshot Coverage Issues Resolution License
[![Project stage][badge-stage]][badge-stage-page] [![Releases][badge-releases]][link-releases] [![Snapshots][badge-snapshots]][link-snapshots] [![Percentage of issues still open][badge-open-issues]][open-issues] [![Average time to resolve an issue][badge-issue-resolution]][issue-resolution] [![License][license-image]][license-url]

Learn / Discuss / Collaborate

Discord Twitch YouTube Twitter
[![Discord][discord-shield]][discord-url] [![Twitch][twitch-shield]][twitch-url] [![YouTube][youtube-shield]][youtube-url] [![Twitter][twitter-shield]][twitter-url]

Table of contents

  • Why Redis OM?
  • Redis OM Spring
  • Getting Started
    • Launch Redis
    • The SpringBoot App
    • ‍♂️ The Mapped Model
    • The Repository
    • Querying with Entity Streams
      • Entity Meta-model
  • Maven configuration
    • Official Releases
      • Explicitly configuring OM as an annotation processor
    • Snapshots
  • Gradle configuration
    • Add Repository - Snapshots Only
    • Dependency
  • Documentation
  • Demos
    • Embedded Demos
    • External Demos
  • ⛏️ Troubleshooting
  • ✨ So How Do You Get RediSearch and RedisJSON?
  • Contributing
  • ‍‍ Sibling Projects
  • License

Why Redis OM?

The Redis OM family of client libraries provide high-level abstractions, idiomatically implemented for your language and platform of choice. We currently cater to the Node, Python, .NET, and Spring communities.

Redis OM Spring

Redis OM Spring provides powerful repository and custom object-mapping abstractions built on top of the Spring Data Redis (SDR) framework.

Redis OM Spring provides all Spring Data Redis capabilities, plus:

  • @Document annotation to map Spring Data models to Redis JSON documents
  • Enhancement to the Spring Data Redis @RedisHash via @EnableRedisEnhancedRepositories:
    • uses Redis' native search engine (RediSearch) for secondary indexing
    • uses ULID for @Id annotated fields
  • RedisDocumentRepository with automatic implementation of Repository interfaces for complex querying capabilities using @EnableRedisDocumentRepositories
  • Declarative search indexes via @Indexed
  • Full-text search indexes via @Searchable
  • Dynamic index naming and multi-tenant support with SpEL expressions and RedisIndexContext
  • Index migration service with Blue-Green, Dual-Write, and In-Place migration strategies
  • EntityStreams: Streams-based Query and Aggregations Builder
  • @Bloom annotation to determine very fast, with and with high degree of certainty, whether a value is in a collection.
  • @Vectorize annotation to generate embeddings for text and images for use in Vector Similarity Searches
  • Vector Similarity Search API (See Redis Stack Vectors)

[!IMPORTANT]

Version Compatibility

Choose the correct Redis OM Spring version for your Spring Boot version:

Redis OM Spring Spring Boot Java Status
1.0.x 3.4.x 17+ Maintenance
1.1.x 3.5.x 17+ Current Stable
2.0.x 4.0.x 17+ Latest

Always use the Redis OM Spring version that matches your Spring Boot version.

Getting Started

Here is a quick teaser of an application using Redis OM Spring to map a Spring Data model using a RedisJSON document.

Launch Redis

Redis OM Spring relies on the search, query, and JSON capabilities of Redis Stack. Before writing any code, you'll need a Redis Stack. The quickest way to get this is with Docker:

bash
docker run -p 6379:6379 -p 8001:8001 redis/redis-stack

This launches redis-stack, an extension of Redis that adds several modern data structures to Redis. You'll also notice that if you open up http://localhost:8001, you'll have access to the redis-insight GUI, a GUI you can use to visualize and work with your data in Redis. We have also provided a Docker Compose YAML file for you to quickly get started using Redis Stack.

To launch the docker compose application, on the command line (or via Docker Desktop), clone this repository and run (from the root folder):

bash
docker compose up

Configuring your Redis Connection

By default, Redis OM Spring connects to localhost at port 6379. If your instance is running somewhere else, you can configure the connection in your application.properties or application.yaml:

In application.properties:

spring.data.redis.host=your.cloud.db.redislabs.com
spring.data.redis.port=12345
spring.data.redis.password=xxxxxxxx
spring.data.redis.username=default

In application.yaml:

spring:
  data:
    redis:
      host: your.cloud.db.redislabs.com
      port: 12345
      password: xxxxxxxx
      username: default

The SpringBoot App

Use the @EnableRedisDocumentRepositories annotation to scan for @Document annotated Spring models, Inject repositories beans implementing RedisDocumentRepository which you can use for CRUD operations and custom queries (all by declaring Spring Data Query Interfaces):

…

‍♂️ The Mapped Model

Like many other Spring Data projects, an annotation at the class level determines how instances of the class are persisted. Redis OM Spring provides the @Document annotation to persist models as JSON documents using RedisJSON:

…

For multi-tenant applications, you can use dynamic index naming with SpEL expressions:

java
// Dynamic index naming for multi-tenant support
@Document
@IndexingOptions(indexName = "#{@environment.getProperty('app.tenant')}_companies_idx")
public class Company {
  @Id private String id;
  @Searchable private String name;
  // other fields...
}

Redis OM Spring, replaces the conventional UUID primary key strategy generation with a ULID (Universally Unique Lexicographically Sortable Identifier) which is faster to generate and easier on the eyes.

The Repository

Redis OM Spring data repository's goal, like other Spring Data repositories, is to significantly reduce the amount of boilerplate code required to implement data access. Simply create a Java interface that extends RedisDocumentRepository that takes the domain class to manage as well as the ID type of the domain class as type arguments. RedisDocumentRepository extends the Spring Data class PagingAndSortingRepository.

Declare query methods on the interface. You can both, expose CRUD methods or create declarations for complex queries that Redis OM Spring will fulfill at runtime:

…

The repository proxy has two ways to derive a store-specific query from the method name:

  • By deriving the query from the method name directly.
  • By using a manually defined query using the @Query or @Aggregation annotations.

Querying with Entity Streams

Redis OM Spring Entity Streams provides a Java 8 Streams interface to Query Redis JSON documents using RediSearch. Entity Streams allow you to process data in a type safe declarative way similar to SQL statements. Streams can be used to express a query as a chain of operations.

Entity Streams in Redis OM Spring provides the same semantics as Java 8 streams. Streams can be made of Redis Mapped entities (@Document) or one or more properties of an Entity. Entity Streams progressively build the query until a terminal operation is invoked (such as collect). Whenever a Terminal operation is applied to a Stream, the Stream cannot accept additional operations to its pipeline and it also means that the Stream is started.

Let's start with a simple example, a Spring @Service which includes EntityStream to query for instances of the mapped class Person:

java
package com.redis.om.skeleton.services;

import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.redis.om.skeleton.models.Person;
import com.redis.om.skeleton.models.Person$;
import com.redis.om.spring.search.stream.EntityStream;

@Service
public class PeopleService {
  @Autowired
  EntityStream entityStream;

  // Find all people
  public Iterable findAllPeople() {
    return entityStream //
        .of(Person.class) //
        .collect(Collectors.toList());
  }

}

The EntityStream is injected into the PeopleService using @Autowired. We can then get a stream for Person objects by using entityStream.of(Person.class). At this point the stream represents the equivalent of a SELECT * FROM Person on a relational database. The call to collect will then execute the underlying query and return a collection of all Person objects in Redis.

Entity Meta-model

To produce more elaborate queries, you're provided with a generated metamodel, which is a class with the same name as your model but ending with a dollar sign. In the example below, our entity model is Person therefore we get a metamodel named Person$. With the metamodel you have access to the operations related to the underlying search engine field. For example, in the example we have an age property which is an integer. Therefore, our metamodel has an AGE property which has numeric operations we can use with the stream's filter method such as between.

java
// Find people by age range
public Iterable findByAgeBetween(int minAge, int maxAge) {
  return entityStream //
      .of(Person.class) //
      .filter(Person$.AGE.between(minAge, maxAge)) //
      .sorted(Person$.AGE, SortOrder.ASC) //
      .collect(Collectors.toList());
}

In this example we also make

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javajavaredisspring

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架