You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix documentation that incorrectly described Redis OM Spring hash mapping as using
Spring Data Redis' basic Set-based indexing. Redis OM Spring actually creates
RediSearch indexes using FT.CREATE commands for Hash entities.
Key corrections:
- Clarify that Redis OM Spring uses RediSearch indexes, not Redis Sets
- Add comparison table showing differences from Spring Data Redis
- Show actual Redis commands (FT.CREATE ON HASH) generated
- Explain O(log N) index-based query performance vs O(N) scans
- Add migration guide from Spring Data Redis
- Update examples to show RediSearch field types (TEXT, TAG, NUMERIC, GEO, VECTOR)
Spring Data Redis (SDR), the library that Redis OM Spring extends, provides mapping of Spring Entities to Redis Hashes. Redis OM Spring enhances this capability by integrating with the Query Engine available in Redis 8.0.0+ (or via Redis Stack for older versions).
9
+
Redis OM Spring fundamentally transforms how Redis Hashes work by adding RediSearch indexing capabilities on top of the standard hash storage. This is a key distinction from Spring Data Redis, which only provides basic hash operations.
10
10
11
-
This integration brings powerful search and indexing capabilities to Redis Hashes, while maintaining compatibility with existing Spring Data Redis code.
11
+
=== The Core Difference
12
12
13
-
== Key Benefits of Redis OM Spring Hash Mapping
13
+
**Spring Data Redis**: Stores entities as Redis Hashes with basic secondary indexing using Redis Sets
14
+
**Redis OM Spring**: Stores entities as Redis Hashes PLUS creates RediSearch indexes for powerful querying
14
15
15
-
* **Enhanced Query Capabilities**: Full text search, numeric ranges, geo-spatial queries
16
-
* **Backward Compatibility**: Works with existing Spring Data Redis code
17
-
* **Simple Annotations**: Easy to add indexing without changing your data model
18
-
* **Performance**: Efficient storage format for simple objects
Redis OM Spring provides a fluent API for complex queries:
413
+
414
+
[source,java]
415
+
----
416
+
@Autowired
417
+
EntityStream entityStream;
418
+
419
+
// Complex query using Entity Streams
420
+
List<Person> admins = entityStream
421
+
.of(Person.class)
422
+
.filter(Person$.ROLES.contains("admin"))
423
+
.filter(Person$.NAME.startsWith("J"))
424
+
.sorted(Person$.EMAIL, SortOrder.ASC)
425
+
.collect(Collectors.toList());
426
+
----
427
+
309
428
== Time To Live (TTL)
310
429
311
430
You can set expiration times for entities:
@@ -393,11 +512,40 @@ public class RedisConfig {
393
512
}
394
513
----
395
514
396
-
== Redis Cluster Considerations
515
+
== Migration from Spring Data Redis
516
+
517
+
Migrating from Spring Data Redis to Redis OM Spring is straightforward:
397
518
398
-
When using Redis Cluster, it's important to ensure that related data is stored in the same hash slot to enable atomic operations and efficient queries.
519
+
1. **Change the repository interface**:
520
+
```java
521
+
// Before: Spring Data Redis
522
+
public interface PersonRepository extends CrudRepository<Person, String> { }
523
+
524
+
// After: Redis OM Spring
525
+
public interface PersonRepository extends RedisEnhancedRepository<Person, String> { }
526
+
```
399
527
400
-
Use the `@IdAsHashTag` annotation to ensure that keys for an entity and its indexes are stored in the same hash slot:
528
+
2. **Enable enhanced repositories**:
529
+
```java
530
+
// Before
531
+
@EnableRedisRepositories
532
+
533
+
// After
534
+
@EnableRedisEnhancedRepositories
535
+
```
536
+
537
+
3. **Add indexing annotations** (optional but recommended):
538
+
```java
539
+
@Indexed // For exact matches
540
+
@Searchable // For full-text search
541
+
@NumericIndexed // For numeric ranges
542
+
```
543
+
544
+
Your existing data remains compatible, and you immediately gain access to powerful search capabilities.
545
+
546
+
== Redis Cluster Considerations
547
+
548
+
When using Redis Cluster with RediSearch indexes, use the `@IdAsHashTag` annotation to ensure proper data locality:
401
549
402
550
[source,java]
403
551
----
@@ -415,14 +563,28 @@ public class HashWithHashTagId {
415
563
416
564
== Performance Considerations
417
565
418
-
* Redis Hashes are very efficient for simple data structures
0 commit comments