Data Grid Code 教程


Red Hat Data Grid 8.3

了解如何使用 Data Grid 功能

Red Hat Customer Content Services

摘要

为远程缓存和嵌入式缓存运行代码教程,它们演示了各种数据中心功能和使用模式。

Red Hat Data Grid

Data Grid 是一个高性能分布式内存数据存储。

无架构数据结构
将不同对象存储为键值对的灵活性。
基于网格的数据存储
旨在在集群中分发和复制数据。
弹性扩展
动态调整节点数量,以便在不中断服务的情况下满足需求。
数据互操作性
从不同端点在网格中存储、检索和查询数据。

Data Grid 文档

红帽客户门户网站中提供了 Data Grid 的文档。

Data Grid 下载

访问 红帽客户门户上的 Data Grid 软件下载。

注意

您必须有一个红帽帐户才能访问和下载数据中心软件。

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。有关更多详情,请参阅我们的首席技术官 Chris Wright 提供的消息

第 1 章 远程缓存

部署多个 Data Grid 服务器实例,以创建远程缓存集群,为您提供容错且可扩展的数据层,支持 Hot Rod 和 REST 客户端的高速度访问。

1.1. 远程缓存指南

要运行这些教程,您需要至少一个本地运行 Data Grid Server 实例。

您可以下载 发行版并运行以下命令:

$ ./bin/cli.sh user create admin -p "password"
$ ./bin/server.sh
注意

Data Grid Server 默认启用身份验证和授权。创建名为 admin 的用户,为您提供对 Infinispan 服务器的管理访问权限。

构建和运行远程缓存指南

您可以直接在 IDE 中构建并运行远程缓存教程,如下所示:

$ mvn -s /path/to/maven-settings.xml clean package exec:exec

1.2. hot Rod Java 客户端教程

  • hot Rod Java 客户端需要 JDK 8 或更高版本。但是,Data Grid 建议至少使用 Java 11。
教程链接描述

远程缓存使用示例

演示远程分布式缓存的工作方式的最简单代码示例。

每个缓存配置

演示了如何在连接到 Data Grid Server 时动态配置缓存。

最接近的缓存

演示了如何配置接近缓存以提高远程缓存的读取性能。

缓存管理员 API

演示如何使用管理 API 动态创建缓存和缓存模板。

编码

演示了如何对缓存进行编码。

客户端监听程序

使用客户端 Listeners 检测远程缓存中数据变化的时间。

查询

演示了如何查询远程缓存值。

持续查询

演示如何使用持续查询和远程缓存。

Transactions

演示远程事务的工作方式。

安全缓存

演示了如何配置启用了授权的缓存。

TLS 授权

演示了如何通过 TLS 授权连接到 Data Grid 服务器。

计数器

演示远程计数器的工作方式。

Multimap

演示远程多映射如何工作。

任务执行

演示了如何注册服务器任务以及如何从 Hot Rod 客户端执行它们。

JUnit 5 和 testcontainers

演示如何使用 Data Grid 和 JUnit 5 扩展。

Persistence

演示了如何使用 Data Grid 和 persistent 缓存。

Data Grid 文档

您可以在以下文档中找到 Hot Rod Java 客户端的更多资源:

第 2 章 嵌入式缓存

将 Data Grid 添加为 Java 项目的依赖项,并使用嵌入式缓存来提高应用程序性能,并为您提供处理复杂用例的功能。

2.1. 嵌入式缓存指南

您可以直接在 IDE 中运行嵌入的缓存教程,或者从命令行运行,如下所示:

$ mvn -s /path/to/maven-settings.xml clean package exec:exec
教程链接描述

分布式缓存

演示分布式缓存如何工作。

复制缓存

演示复制缓存如何工作。

无效的缓存

演示了无效的缓存是如何工作的。

Transactions

演示事务的工作方式。

演示分布式流如何工作。

JCACHE 集成

演示 JCache 的工作原理。

功能映射

演示 Functional Map API 的工作原理。

Map API

演示 Map API 如何与 Data Grid 缓存一起工作。

Multimap

演示如何使用多映射.

查询

使用 Data Grid Query 对缓存值执行全文本查询。

集群的 Listener

使用 Clustered Listeners 检测内嵌缓存中数据更改时。

计数器

演示如何使用嵌入式集群计数器。

集群锁定

演示如何使用嵌入式集群锁定。

集群执行

演示如何使用嵌入式集群计数器。

Data Grid 文档

您可以在以下文档中找到有关嵌入式缓存的更多资源:

第 3 章 Spring 和 Spring Boot

3.1. Spring 和 Spring Boot 指南

注意

这些代码教程使用 Data Grid 服务器,并且至少需要一个正在运行的实例。

运行 Spring 示例

$ mvn -s /path/to/maven-settings.xml package exec:exec

运行 Spring Boot 示例

$ mvn -s /path/to/maven-settings.xml spring-boot:run

显示激活器统计

导航到浏览器中的 http://localhost:8080/actuator/metrics,以显示可用指标列表。缓存指标前缀为 "cache"。使用标签显示每个缓存的每个指标。例如,basque-names 缓存中的 'puts' 统计:

http://localhost:8080/actuator/metrics/cache.puts?tag=name:basque-names

使用 Prometheus 收集统计信息

此项目中的 prometheus.yml 文件包含 host.docker.internal 绑定,允许 Prometheus 清理 Spring actuator 公开的指标。

将以下命令中的 YOUR_PATH 值改为运行 Prometheus 的目录,然后运行:

Podman

$ podman run -d --name=prometheus -p 9090:9090 -v YOUR_PATH/integrations/spring-boot/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

教程链接描述

Spring Boot 和 Spring Cache 远程模式

演示了如何在 Spring Boot 和 Data Grid Server 中使用 Spring Caches。

Spring Boot 和 Spring Session 远程模式

演示了如何在 Spring Boot 和 Data Grid Server 中使用 Spring Session。

Spring Boot 和 Spring Cache 嵌入式模式

演示了如何在 Spring Boot 和 Data Grid Embedded 中使用 Spring Caches。

Spring Boot 和 Spring Session 嵌入式模式

演示了如何在 Spring Boot 和 Data Grid Embeded 中使用 Spring Session。

在没有 Spring Boot 的情况下嵌入 Spring 缓存

演示了如何在没有 Spring Boot 的情况下使用 Spring Cache 和 Data Grid Embeded。

在没有 Spring Boot 的情况下嵌入 Spring 会话

演示了如何在没有 Spring Boot 的情况下使用 Spring Session 和 Data Grid Embeded。

Data Grid 文档

您可以在以下文档中找到更多资源:

法律通告

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.