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
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/redis-repositories.adoc
+30-10Lines changed: 30 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ To access domain entities stored in a Redis you can leverage repository support
14
14
====
15
15
[source,java]
16
16
----
17
-
@RedisHash("persons");
17
+
@RedisHash("persons")
18
18
public class Person {
19
19
20
20
@Id String id;
@@ -156,7 +156,7 @@ of Complex Type
156
156
addresses.[work].city = "...
157
157
|===
158
158
159
-
Mapping behavior can be customized by registering the according `Converter` in `CustomConversions`. Those converters can take care of converting from/to a single `byte[]` as well as `Map<String,byte[]>` whereas the first one is suitable for eg. converting one complex type to eg. a binary JSON representation that still uses the default mappings hash structure, whereas the second options offers full control over the resulting hash.
159
+
Mapping behavior can be customized by registering the according `Converter` in `CustomConversions`. Those converters can take care of converting from/to a single `byte[]` as well as `Map<String,byte[]>` whereas the first one is suitable for eg. converting one complex type to eg. a binary JSON representation that still uses the default mappings hash structure. The second option offers full control over the resulting hash. Writing objects to a Redis hash will delete the content from the hash and re-create the whole hash, so not mapped data will be lost.
160
160
161
161
.Sample byte[] Converters
162
162
====
@@ -306,15 +306,15 @@ public class ApplicationConfig {
306
306
307
307
[[redis.repositories.indexes]]
308
308
== Secondary Indexes
309
-
http://redis.io/topics/indexes[Secondary indexes] are used to enable lookup operations based on native redis structures. Values are written to the according indexes on every save and are removed when objects are deleted or <<redis.repositories.expirations,expire>>.
309
+
http://redis.io/topics/indexes[Secondary indexes] are used to enable lookup operations based on native Redis structures. Values are written to the according indexes on every save and are removed when objects are deleted or <<redis.repositories.expirations,expire>>.
310
310
311
311
Given the sample `Person` entity we can create an index for _firstname_ by annotating the property with `@Indexed`.
312
312
313
313
.Annotation driven indexing
314
314
====
315
315
[source,java]
316
316
----
317
-
@RedisHash("persons");
317
+
@RedisHash("persons")
318
318
public class Person {
319
319
320
320
@Id String id;
@@ -349,7 +349,7 @@ Further more the programmatic setup allows to define indexes on map keys and lis
349
349
====
350
350
[source,java]
351
351
----
352
-
@RedisHash("persons");
352
+
@RedisHash("persons")
353
353
public class Person {
354
354
355
355
// ... other properties omitted
@@ -455,16 +455,19 @@ public class TimeToLiveOnMethod {
455
455
The repository implementation ensures subscription to http://redis.io/topics/notifications[Redis keyspace notifications] via `RedisMessageListenerContainer`.
456
456
457
457
When the expiration is set to a positive value the according `EXPIRE` command is executed.
458
-
Additionally to persisting the original, a _phantom_ copy is persisted in Redis and set to expire 5 minutes after the original one. This done to enable the Repository support to publish `RedisKeyExpiredEvent` holding the expired value via Springs `ApplicationEventPublisher` whenever a key expires even though the original values have already been gone.
458
+
Additionally to persisting the original, a _phantom_ copy is persisted in Redis and set to expire 5 minutes after the original one. This is done to enable the Repository support to publish `RedisKeyExpiredEvent` holding the expired value via Springs `ApplicationEventPublisher` whenever a key expires even though the original values have already been gone. Expiry events
459
+
will be received on all connected applications using Spring Data Redis repositories.
459
460
460
461
The `RedisKeyExpiredEvent` will hold a copy of the actually expired domain object as well as the key.
461
462
462
-
NOTE: The keyspace notification message listener will alter `notify-keyspace-events` settings in Redis if those are not already set. Existing settings will not be overridden so it is left to the user to set those up correctly when not leaving them empty.
463
+
NOTE: The keyspace notification message listener will alter `notify-keyspace-events` settings in Redis if those are not already set. Existing settings will not be overridden, so it is left to the user to set those up correctly when not leaving them empty.
464
+
465
+
NOTE: Redis Pub/Sub messages are not persistent. If a key expires while the application is down the expiry event will not be processed which may lead to secondary indexes containing still references to the expired object.
463
466
464
467
[[redis.repositories.references]]
465
468
== Persisting References
466
-
Marking properties with `@Reference` allows to store a simple key reference instead of copying the all values into the hash itself.
467
-
On loading from Redis references are resolved automatically and mapped back into the object.
469
+
Marking properties with `@Reference` allows storing a simple key reference instead of copying values into the hash itself.
470
+
On loading from Redis, references are resolved automatically and mapped back into the object.
NOTE: Please make sure properties used in finder methods are set up for indexing.
501
505
502
-
Using derived finder methods might not always be sufficient to model the queries to execute. `RedisCallback` offers more control over the actual matching of index structures or even customly added ones. All it takes is providing a `RedisCallback` that returns a single or `Iterable` set of _id_ values.
506
+
NOTE: Query methods for Redis repositories support only queries for entities and collections of entities with paging.
507
+
508
+
Using derived query methods might not always be sufficient to model the queries to execute. `RedisCallback` offers more control over the actual matching of index structures or even custom added ones. All it takes is providing a `RedisCallback` that returns a single or `Iterable` set of _id_ values.
0 commit comments