The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Redis的Dev Services

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 DevService的可用配置属性:

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

类型

默认值

If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present.

When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in Dev or Test mode and when Docker is running.

Environment variable: QUARKUS_REDIS_DEVSERVICES_ENABLED

Show more

boolean

true

The container image name to use, for container based DevServices providers. If you want to use Redis Stack modules (bloom, graph, search…​), use: redis/redis-stack:latest.

Environment variable: QUARKUS_REDIS_DEVSERVICES_IMAGE_NAME

Show more

string

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_REDIS_DEVSERVICES_PORT

Show more

int

Indicates if the Redis server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Redis starts a new container.

The discovery uses the quarkus-dev-service-redis label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_REDIS_DEVSERVICES_SHARED

Show more

boolean

true

The value of the quarkus-dev-service-redis label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services for Redis looks for a container with the quarkus-dev-service-redis label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the quarkus-dev-service-redis label set to the specified value.

This property is used when you need multiple shared Redis servers.

Environment variable: QUARKUS_REDIS_DEVSERVICES_SERVICE_NAME

Show more

string

redis

Environment variables that are passed to the container.

Environment variable: QUARKUS_REDIS_DEVSERVICES_CONTAINER_ENV

Show more

Map<String,String>

If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present.

When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in Dev or Test mode and when Docker is running.

Environment variable: QUARKUS_REDIS__ADDITIONAL_REDIS_CLIENTS__DEVSERVICES_ENABLED

Show more

boolean

true

The container image name to use, for container based DevServices providers. If you want to use Redis Stack modules (bloom, graph, search…​), use: redis/redis-stack:latest.

Environment variable: QUARKUS_REDIS__ADDITIONAL_REDIS_CLIENTS__DEVSERVICES_IMAGE_NAME

Show more

string

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_REDIS__ADDITIONAL_REDIS_CLIENTS__DEVSERVICES_PORT

Show more

int

Indicates if the Redis server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Redis starts a new container.

The discovery uses the quarkus-dev-service-redis label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_REDIS__ADDITIONAL_REDIS_CLIENTS__DEVSERVICES_SHARED

Show more

boolean

true

The value of the quarkus-dev-service-redis label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services for Redis looks for a container with the quarkus-dev-service-redis label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the quarkus-dev-service-redis label set to the specified value.

This property is used when you need multiple shared Redis servers.

Environment variable: QUARKUS_REDIS__ADDITIONAL_REDIS_CLIENTS__DEVSERVICES_SERVICE_NAME

Show more

string

redis

Environment variables that are passed to the container.

Environment variable: QUARKUS_REDIS__ADDITIONAL_REDIS_CLIENTS__DEVSERVICES_CONTAINER_ENV

Show more

Map<String,String>

运行应用程序的生产版本需要正常配置Redis连接,所以如果你想在 application.properties 中定义生产的数据库配置,同时继续使用Dev Services,我们建议你使用 %prod. profile来定义你的Redis设置。

Redis的Dev Services依赖Docker来启动服务器。如果你的环境不支持Docker,则需要手动启动服务,或者连接到一个运行中的服务。

If you want to use Redis Stack modules (bloom, graph, search…​), set the image-name to redis/redis-stack:latest

服务共享

很多时候你需要在多个应用之间共享Dev Services。Redis的Dev Services实现了 服务发现 机制,允许多个以 dev 模式运行的Quarkus应用共享同一个Dev Services。

Redis的Dev Services启动容器时使用 quarkus-dev-service-redis 标签,该标签用于识别容器。

如果需要多个(共享的)Dev Services,可以用 quarkus.redis.devservices.service-name 属性指定服务名称。Quarkus将尝试查找具有相同服务名称的容器,如果找不到,则启动一个新容器。默认的服务名称是 redis

在dev模式下默认启用服务共享,而在测试模式下默认禁用。也可以使用 quarkus.redis.devservices.shared=false 配置禁用服务共享。

Related content