Skip to content

Commit bd7728e

Browse files
DATAREDIS-425 - Add Support for basic CRUD and finder Operations backed by Hashes and Sets.
We now enable storing domain object as a flat Redis 'HASH' and maintain additional 'SET' structures to enable finder operations on simple properties. @RedisHash("persons"); class Person { @id String id; @indexed String firstname; String lastname; Map<String, String> attributes; City city; @reference Person mother; } The above is stored in the HASH with key 'persons:1' as _class = org.example.Person id = 1 firstname = rand lastname = al’thor attributes.[eye-color] = grey attributes.[hair-color] = red city.name = emond's field city.region = two rivers mother = persons:2 Complex types are flattened out to their full property path for each of the values provided. If the properties actual value type does not match the declared one the '_class' type hint is added to the entry. city._class = CityInAndor.class city.name = emond's field city.region = two rivers city.country = andor Map and Collection like structures are stored with their key/index values as part of the property path. If the map/collection value type does not match the actutal objects one the '_class' type hint is added to the entry. list.[0]._class = DomainType.class list.[0].property1 = ... map.[key-1]._class = DomainType.class map.[key-1].property1 = ... Properties marked with '@reference' are stored as semantic references by just storing the key to the referenced object 'HASH' instead of embedding its values. mother = persons:2 Please note that referenced objects are not transitively updated/saved and that lazy loading of references will be part of future development. A 'save' operation therefore executes the following: # flatten domain type and add as hash HMSET persons:1 id 1 firstname rand … # add the newly inserted entry to the list of all entries of that type SADD persons 1 # index the firstname for finder lookup SADD persons.firstname:rand 1 Simple finder operation like 'findByFirstname' use 'SINTER' to find matching SINTER persons.firstname:rand HGETALL persons:1 Besides resolving an index via the '@Index' annotation we also allow to add custom configuration via the 'indexConfiguration' attribute of '@EnableRedisRepositories'. @configuration @EnableRedisRepositories(indexConfiguration = CustomIndexConfiguration.class) class Config { } static class CustomIndexConfiguration extends IndexConfiguration { @OverRide protected Iterable<RedisIndexDefinition> initialConfiguration() { return Arrays.asList( new SimpleIndexDefinition("persons", "lastname"), ); } } The '@timetolive' annotation allows to define a property or method providing an expiration time when storing the key in redis. @RedisHash class Person { @id String id; @timetolive Long ttl; } Original Pull Request: spring-projects#156
1 parent 5a85ac4 commit bd7728e

File tree

57 files changed

+9911
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+9911
-6
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ jdk:
44
- oraclejdk8
55
env:
66
matrix:
7-
- PROFILE=ci
8-
- PROFILE=spring41-next
97
- PROFILE=spring42
108
- PROFILE=spring42-next
119
- PROFILE=spring43-next

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<properties>
1919
<dist.key>DATAREDIS</dist.key>
20-
<springdata.commons>1.12.0.BUILD-SNAPSHOT</springdata.commons>
20+
<springdata.keyvalue>1.1.0.BUILD-SNAPSHOT</springdata.keyvalue>
2121
<jta>1.1</jta>
2222
<beanutils>1.9.2</beanutils>
2323
<xstream>1.4.8</xstream>
@@ -53,8 +53,8 @@
5353

5454
<dependency>
5555
<groupId>org.springframework.data</groupId>
56-
<artifactId>spring-data-commons</artifactId>
57-
<version>${springdata.commons}</version>
56+
<artifactId>spring-data-keyvalue</artifactId>
57+
<version>${springdata.keyvalue}</version>
5858
</dependency>
5959

6060
<dependency>

0 commit comments

Comments
 (0)