KeyValue
Spring Data KeyValue 提供了轻松配置和访问类似 Map
的结构的功能,这些结构将值与唯一键相关联。它提供了低级和高级抽象,用于与基础数据结构交互,让用户不必担心基础设施问题。
Spring Data KeyValue provides easy configuration and access to Map
like structures that associate values with unique keys.
It offers both low-level and high-level abstractions for interacting with the underlying data structure, freeing the user from infrastructural concerns.
Spring Data Key Value 中的键值抽象需要一个 Adapter
,它可以屏蔽原生存储实现,让 KeyValueTemplate
可以基于任何键值对结构进行工作。键分布在 key-value.keyspaces。除非另行指定,否则类名用作实体的默认键空间。以下接口定义显示了 KeyValueOperations
接口,它是 Spring Data Key-Value 的核心:
The key-value abstraction within Spring Data Key Value requires an Adapter
that shields the native store implementation, freeing up KeyValueTemplate
to work on top of any key-value pair-like structure.
Keys are distributed across key-value.keyspaces.
Unless otherwise specified, the class name is used as the default keyspace for an entity.
The following interface definition shows the KeyValueOperations
interface, which is the heart of Spring Data Key-Value:
interface KeyValueOperations {
<T> T insert(T objectToInsert); 1
void update(Object objectToUpdate); 2
void delete(Class<?> type); 3
<T> T findById(Object id, Class<T> type); 4
<T> Iterable<T> findAllOf(Class<T> type); 5
<T> Iterable<T> find(KeyValueQuery<?> query, Class<T> type); 6
//... more functionality omitted.
}
1 | Inserts the given entity and assigns an ID (if required). |
2 | Updates the given entity. |
3 | Removes all entities of the matching type. |
4 | Returns the entity of the given type with its matching ID. |
5 | Returns all entities of the matching type. |
6 | Returns a List of all entities of the given type that match the criteria of the query. |
Keyspaces
键空间定义了应在其中保留实体的数据结构的一部分。该概念类似于 MongoDB 和 Elasticsearch 中的集合、Solr 中的内核以及 JPA 中的表。默认情况下,实体的键空间是从其类型中提取的,但你也可以将不同类型的实体存储在一个键空间内。
Keyspaces define the part of the data structure in which the entity should be kept. This concept is similar to collections in MongoDB and Elasticsearch, cores in Solr, and tables in JPA. By default, the keyspace of an entity is extracted from its type, but you can also store entities of different types within one keyspace.