Bind Azure Cache for Redis to your application in Azure Spring Cloud
This article applies to: ✔️ Java
Instead of manually configuring your Spring Boot applications, you can automatically bind select Azure services to your applications by using Azure Spring Cloud. This article shows how to bind your application to Azure Cache for Redis.
Prerequisites
- A deployed Azure Spring Cloud instance
- An Azure Cache for Redis service instance
- The Azure Spring Cloud extension for the Azure CLI
If you don't have a deployed Azure Spring Cloud instance, follow the steps in the quickstart on deploying an Azure Spring Cloud app.
Prepare your Java project
Add the following dependency to your project's pom.xml file:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis-reactive</artifactId> </dependency>Remove any
spring.redis.*properties from theapplication.propertiesfileUpdate the current deployment using
az spring-cloud app updateor create a new deployment usingaz spring-cloud app deployment create.
Bind your app to the Azure Cache for Redis
Go to your Azure Spring Cloud service page in the Azure portal. Go to Application Dashboard and select the application to bind to Azure Cache for Redis. This application is the same one you updated or deployed in the previous step.
Select Service binding and select Create service binding. Fill out the form, being sure to select the Binding type value Azure Cache for Redis, your Azure Cache for Redis server, and the Primary key option.
Restart the app. The binding should now work.
To ensure the service binding is correct, select the binding name and verify its details. The
propertyfield should look like this:spring.redis.host=some-redis.redis.cache.windows.net spring.redis.port=6380 spring.redis.password=abc****** spring.redis.ssl=true
Next steps
In this article, you learned how to bind your application in Azure Spring Cloud to Azure Cache for Redis. To learn more about binding services to your application, see Bind to an Azure Database for MySQL instance.