DATAREDIS-741 - Improve repository operation documentation.

Original pull request: #354.
This commit is contained in:
Christoph Strobl
2018-08-30 14:46:15 +02:00
committed by Mark Paluch
parent ec70c70550
commit ae05daebdd

View File

@@ -792,3 +792,110 @@ class RepositoryClient {
----
A Redis Repository requires `RedisKeyValueAdapter` and `RedisKeyValueTemplate` instances. These beans are created and managed by the Spring Data CDI extension if no provided beans are found. You can, however, supply your own beans to configure the specific properties of `RedisKeyValueAdapter` and `RedisKeyValueTemplate`.
== Redis Repositories Anatomy
Redis as a store itself offers a very narrow low level interface leaving higher level functions such as secondary indexes and
query operations up to the user.
This section provides a more detailed view on commands issues by the repository abstraction for better understanding of
potential performance implications.
=== Insert new
====
[source, java]
----
repository.save(new Person("rand", "al'thor"));
----
[source, text]
----
HMSET "persons:19315449-cda2-4f5c-b696-9cb8018fa1f9" "_class" "person" "id" "19315449-cda2-4f5c-b696-9cb8018fa1f9" "firstname" "rand" "lastname" "al'thor" <1>
SADD "persons" "19315449-cda2-4f5c-b696-9cb8018fa1f9" <2>
SADD "persons:firstname:rand" "19315449-cda2-4f5c-b696-9cb8018fa1f9" <3>
SADD "persons:19315449-cda2-4f5c-b696-9cb8018fa1f9:idx" "persons:firstname:rand" <4>
----
<1> Save the flatened entry as hash.
<2> Add the key of the hash added in <1> to the helper index of entities of same keyspace.
<3> Add the key of the hash added in <2> to the secondary index of firstnames with the properties value.
<4> Add the index of <3> to the set of helper structures for entry to keep track of indexes to clean on delete/update.
====
=== Replace existing
====
[source, java]
----
repository.save(new Person("e82908cf-e7d3-47c2-9eec-b4e0967ad0c9", "Dragon Reborn", "al'thor"));
----
[source, text]
----
DEL "persons:e82908cf-e7d3-47c2-9eec-b4e0967ad0c9" <1>
HMSET "persons:e82908cf-e7d3-47c2-9eec-b4e0967ad0c9" "_class" "person" "id" "e82908cf-e7d3-47c2-9eec-b4e0967ad0c9" "firstname" "Dragon Reborn" "lastname" "al'thor" <2>
SADD "persons" "e82908cf-e7d3-47c2-9eec-b4e0967ad0c9" <3>
SMEMBERS "persons:e82908cf-e7d3-47c2-9eec-b4e0967ad0c9:idx" <4>
TYPE "persons:firstname:rand" <5>
SREM "persons:firstname:rand" "e82908cf-e7d3-47c2-9eec-b4e0967ad0c9" <6>
DEL "persons:e82908cf-e7d3-47c2-9eec-b4e0967ad0c9:idx" <7>
SADD "persons:firstname:Dragon Reborn" "e82908cf-e7d3-47c2-9eec-b4e0967ad0c9"
SADD "persons:e82908cf-e7d3-47c2-9eec-b4e0967ad0c9:idx" "persons:firstname:Dragon Reborn"
----
<1> Remove the existing hash to avoid leftovers of hash keys potentially no longer present.
<2> Save the flatened entry as hash.
<3> Add the key of the hash added in <1> to the helper index of entities of same keyspace.
<4> Get existing index structures that might need to be updated.
<5> Check if the index exists and what type it is (text, geo,...)
<6> Remove a potentially existing key from the index.
<7> Remove the helper holding index information.
<6> Add the key of the hash added in <2> to the secondary index of firstnames with the properties value.
<4> Add the index of <6> to the set of helper structures for entry to keep track of indexes to clean on delete/update.
====
=== Save Geo Data
Geo indexes follow the same rules as normal text based ones but use geo structure to store values.
====
[source, text]
----
GEOADD "persons:hometown:location" "13.361389" "38.115556" "76900e94-b057-44bc-abcf-8126d51a621b"
SADD "persons:76900e94-b057-44bc-abcf-8126d51a621b:idx" "persons:hometown:location"
----
<1> Add the key of the saved entry to the the geo index.
<2> Keep track of the index structure.
====
=== Find using simple index
====
[source, java]
----
repository.findByFirstname("egwene");
----
[source, text]
----
SINTER "persons:firstname:egwene" <1>
HGETALL "persons:d70091b5-0b9a-4c0a-9551-519e61bc9ef3" <2>
HGETALL ...
----
<1> Fetch keys contained in the secondary index.
<2> Fetch each and every key returned by <1> individually.
====
=== Find using Geo Index
====
[source, java]
----
repository.findByHometownLocationNear(new Point(15, 37), new Distance(200, KILOMETERS));
----
[source, text]
----
GEORADIUS "persons:hometown:location" "15.0" "37.0" "200.0" "km"
HGETALL "persons:76900e94-b057-44bc-abcf-8126d51a621b"
----
====