Redis
Spring Data 支持的一个键值存储是 Redis。引用 Redis 项目主页:
One of the key-value stores supported by Spring Data is Redis. To quote the Redis project home page: Redis is an advanced key-value store. It is similar to memcached but the dataset is not volatile, and values can be strings, exactly like in memcached, but also lists, sets, and ordered sets. All this data types can be manipulated with atomic operations to push/pop elements, add/remove elements, perform server side union, intersection, difference between sets, and so forth. Redis supports different kind of sorting abilities.
Spring Data Redis 提供了从 Spring 应用程序轻松配置和访问 Redis 的方法。它提供了低级别和高级别的抽象,用于与存储进行交互,从而将用户从基础设施问题中解放出来。
Spring Data Redis provides easy configuration and access to Redis from Spring applications. It offers both low-level and high-level abstractions for interacting with the store, freeing the user from infrastructural concerns.
Spring Data 对 Redis 的支持包含广泛的功能:
Spring Data support for Redis contains a wide range of features:
-
RedisTemplate
andReactiveRedisTemplate
helper class that increases productivity when performing common Redis operations. Includes integrated serialization between objects and values. -
Exception translation into Spring’s portable Data Access Exception hierarchy.
-
Automatic implementation of Repository interfaces, including support for custom query methods.
-
Feature-rich Object Mapping integrated with Spring’s Conversion Service.
-
Annotation-based mapping metadata that is extensible to support other metadata formats.
-
Transactions and Pipelining.
-
Redis Cache integration through Spring’s Cache abstraction.
-
Redis Pub/Sub Messaging and Redis Stream Listeners.
-
Redis Collection Implementations for Java such as
RedisList
orRedisSet
.
Why Spring Data Redis?
Spring Framework 是领先的全栈 Java/JEE 应用程序框架。它提供了一个轻量级容器和一个非侵入式编程模型,通过使用依赖注入、AOP 和可移植服务抽象来启用。
The Spring Framework is the leading full-stack Java/JEE application framework. It provides a lightweight container and a non-invasive programming model enabled by the use of dependency injection, AOP, and portable service abstractions.
NoSQL 存储系统为水平可扩展性和速度提供了经典 RDBMS 的替代方案。在实现方面,键值存储是 NoSQL 空间中规模最大(也是最古老的)成员之一。
NoSQL storage systems provide an alternative to classical RDBMS for horizontal scalability and speed. In terms of implementation, key-value stores represent one of the largest (and oldest) members in the NoSQL space.
Spring Data Redis (SDR) 框架通过消除通过 Spring 的出色基础设施支持与存储进行交互所需的冗余任务和样板代码,使编写使用 Redis 键值存储的 Spring 应用程序变得容易。
The Spring Data Redis (SDR) framework makes it easy to write Spring applications that use the Redis key-value store by eliminating the redundant tasks and boilerplate code required for interacting with the store through Spring’s excellent infrastructure support.
Redis Support High-level View
Redis 支持提供了多个组件。对于大多数任务,高级别抽象和支持服务是最佳选择。请注意,你可以在任意时刻在层之间移动。例如,你可以获得一个低级别连接(甚至是本机库),以直接与 Redis 进行通信。
The Redis support provides several components.For most tasks, the high-level abstractions and support services are the best choice.Note that, at any point, you can move between layers.For example, you can get a low-level connection (or even the native library) to communicate directly with Redis.