You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Quickstart: Use Azure Cache for Redis in Java with Jedis Redis client
14
13
15
14
In this quickstart, you incorporate Azure Cache for Redis into a Java app using the [Jedis](https://github.com/xetorthio/jedis) Redis client. Your cache is a secure, dedicated cache that is accessible from any application within Azure.
16
15
@@ -27,148 +26,192 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
Depending on your operating system, add environment variables for your **Host name** and **Primary access key** that you noted previously. Open a command prompt, or a terminal window, and set up the following values:
Replace the placeholders with the following values:
48
+
1. Change to the new **redis-jedis-test** project directory.
49
+
1. Open the **pom.xml** file. In the file, you see a dependency for [Jedis](https://github.com/xetorthio/jedis):
53
50
54
-
-`<your-host-name>`: The DNS host name, obtained from the *Properties* section of your Azure Cache for Redis resource in the Azure portal.
55
-
-`<your-primary-access-key>`: The primary access key, obtained from the *Access keys* section of your Azure Cache for Redis resource in the Azure portal.
51
+
### [Microsoft Entra ID authentication (recommended)](#tab/entraid)
//Construct a Token Credential from Identity library, e.g. DefaultAzureCredential / ClientSecretCredential / Client CertificateCredential / ManagedIdentityCredential etc.
106
+
DefaultAzureCredential defaultAzureCredential = new DefaultAzureCredentialBuilder().build();
107
+
108
+
// Fetch a Microsoft Entra token to be used for authentication. This token will be used as the password.
This code shows you how to connect to an Azure Cache for Redis instance using the cache host name and key environment variables. The code also stores and retrieves a string value in the cache. The `PING` and `CLIENT LIST` commands are also executed.
131
-
132
-
1. Close the *App.java*.
148
+
### [Access key authentication](#tab/accesskey)
133
149
134
-
## Build and run the app
150
+
```java
151
+
package example.demo;
135
152
136
-
1. First, if you haven't already, you must set the environment variables as noted previously.
This code shows you how to connect to an Azure Cache for Redis instance using the cache host name and key environment variables. The code also stores and retrieves a string value in the cache. The `PING` and `CLIENT LIST` commands are also executed.
204
+
205
+
1. Close the **App.java** file.
206
+
207
+
## Build and run the app
208
+
209
+
Execute the following Maven command to build and run the app:
In the following output, you can see that the `Message` key previously had a cached value. The value was updated to a new value using `jedis.set`. The app also executed the `PING` and `CLIENT LIST` commands.
If you continue to use the quickstart code, you can keep the resources created in this quickstart and reuse them.
194
-
195
-
Otherwise, if you're finished with the quickstart sample application, you can delete the Azure resources created in this quickstart to avoid charges.
196
-
197
-
> [!IMPORTANT]
198
-
> Deleting a resource group is irreversible and that the resource group and all the resources in it are permanently deleted. Make sure that you do not accidentally delete the wrong resource group or resources. If you created the resources for hosting this sample inside an existing resource group that contains resources you want to keep, you can delete each resource individually instead of deleting the resource group.
199
-
>
200
-
201
-
1. Sign in to the [Azure portal](https://portal.azure.com) and select **Resource groups**.
202
-
203
-
1. In the **Filter by name** textbox, type the name of your resource group. The instructions for this article used a resource group named *TestResources*. On your resource group in the result list, select **...** then **Delete resource group**.
204
-
205
-
:::image type="content" source="media/cache-java-get-started/azure-cache-redis-delete-resource-group.png" alt-text="Screenshot of the Azure portal that shows the Resource groups page with the Delete resource group button highlighted." lightbox="media/cache-java-get-started/azure-cache-redis-delete-resource-group.png":::
206
-
207
-
1. Type the name of your resource group to confirm deletion and then select **Delete**.
208
-
209
-
After a few moments, the resource group and all of its contained resources are deleted.
0 commit comments