Dev Services for Redis
Quarkus 支持一项称为 Dev Services 的功能,该功能允许您在没有任何配置的情况下创建各种数据源。这在实际操作中意味着,如果您正在运行 docker 并且尚未配置 quarkus.redis.hosts
,则 Quarkus 将在运行测试或开发模式时自动启动 Redis 容器,并自动配置连接。
Quarkus supports a feature called Dev Services that allows you to create various datasources without any config.
What that means practically, is that if you have docker running and have not configured quarkus.redis.hosts
,
Quarkus will automatically start a Redis container when running tests or dev mode, and automatically configure the connection.
用于自定义 Redis Dev Service 的可用属性。
Available properties to customize the Redis Dev Service. Unresolved directive in redis-dev-services.adoc - include::{generated-dir}/config/quarkus-redis-client_quarkus.redis.devservices.adoc[]
在运行应用程序的生产版本时,Redis 连接需要按正常方式进行配置,因此,如果您希望在您的 `application.properties`中包含生产数据库配置,并继续使用 Dev Service,我们建议您使用 `%prod.`profile 定义 Redis 设置。
When running the production version of the application, the Redis connection need to be configured as normal,
so if you want to include a production database config in your application.properties
and continue to use Dev Services
we recommend that you use the %prod.
profile to define your Redis settings.
适用于 Redis 的 Dev Service 依赖于 Docker 来启动服务器。如果您的环境不支持 Docker,您将需要手动启动服务器,或连接到已运行的服务器。
Dev Services for Redis relies on Docker to start the server. If your environment does not support Docker, you will need to start the server manually, or connect to an already running server.
如果您想使用 Redis Stack modules(bloom、graph、search…),请将 image-name 设置为 redis/redis-stack:latest
If you want to use Redis Stack modules (bloom, graph, search…), set the image-name to redis/redis-stack:latest
Shared server
大多数情况下,您需要在应用程序之间共享服务器。Dev Services for Redis 为在 dev 模式下运行的多个 Quarkus 应用程序实施了一个 service discovery 机制,以共享单个服务器。
Most of the time you need to share the server between applications. Dev Services for Redis implements a service discovery mechanism for your multiple Quarkus applications running in dev mode to share a single server.
Dev Services for Redis 使用 |
Dev Services for Redis starts the container with the |
如果您需要多个(共享)服务器,可以配置 quarkus.redis.devservices.service-name
属性并指示服务器名称。它会查找具有相同值或找不到值时启动新值的容器。默认服务名称为 redis
。
If you need multiple (shared) servers, you can configure the quarkus.redis.devservices.service-name
attribute and indicate the server name.
It looks for a container with the same value, or starts a new one if none can be found.
The default service name is redis
.
在 dev 模式下默认启用共享,但在 test 模式下禁用共享。您可以使用 quarkus.redis.devservices.shared=false
禁用共享。
Sharing is enabled by default in dev mode, but disabled in test mode.
You can disable the sharing with quarkus.redis.devservices.shared=false
.