Skip to content

Commit 910742f

Browse files
authored
update Use Azure Cache for Redis in Java with Redisson Redis client
1 parent e5a7a9f commit 910742f

File tree

2 files changed

+46
-75
lines changed

2 files changed

+46
-75
lines changed

articles/azure-cache-for-redis/cache-java-get-started.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
3131

3232
## Set up the working environment
3333

34-
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:
34+
The following steps show you how to set up the working environment for the Java app. You can choose to authenticate with Azure Cache for Redis using Microsoft Entra ID(recommended) or access keys.
3535

36-
## [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
36+
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
3737

3838
```bash
3939
export REDIS_CACHE_HOSTNAME=<your-host-name>.redis.cache.windows.net
@@ -44,8 +44,15 @@ Replace the placeholders with the following values:
4444

4545
- `<your-host-name>`: The DNS host name, obtained from the *Properties* section of your Azure Cache for Redis resource in the Azure portal.
4646
- `<user-name>`: Object ID of your managed identity or service principal.
47+
- You can get the user name by using the following steps:
4748

48-
## [Access Key Authentication](#tab/accesskey)
49+
1. In the Azure portal, navigate to your Azure Cache for Redis instance.
50+
1. On the navigation pane, select **Data Access Configuration**.
51+
1. On the **Redis Users** tab, find the **Username** column.
52+
53+
:::image type="content" source="media/cache-java-redisson-get-started/user-name.png" alt-text="Screenshot of the Azure portal that shows the Azure Cache for Redis Data Access Configuration page with the Redis Users tab and a Username value highlighted." lightbox="media/cache-java-redisson-get-started/user-name.png":::
54+
55+
### [Access Key Authentication](#tab/accesskey)
4956

5057
```bash
5158
export REDIS_CACHE_HOSTNAME=<your-host-name>.redis.cache.windows.net
@@ -79,7 +86,7 @@ Using Maven, generate a new quickstart app:
7986

8087
1. Open the *pom.xml* file. In the file, you see a dependency for [Jedis](https://github.com/xetorthio/jedis):
8188

82-
## [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
89+
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
8390

8491
```xml
8592
<dependency>
@@ -96,7 +103,7 @@ Using Maven, generate a new quickstart app:
96103
```
97104

98105

99-
## [Access Key Authentication](#tab/accesskey)
106+
### [Access Key Authentication](#tab/accesskey)
100107

101108
```xml
102109
<dependency>
@@ -114,7 +121,7 @@ Using Maven, generate a new quickstart app:
114121

115122
1. Open *App.java* and see the code with the following code:
116123

117-
## [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
124+
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
118125
```java
119126
package example.demo;
120127

@@ -178,7 +185,7 @@ Using Maven, generate a new quickstart app:
178185
}
179186
```
180187

181-
## [Access Key Authentication](#tab/accesskey)
188+
### [Access Key Authentication](#tab/accesskey)
182189
```java
183190
package example.demo;
184191

articles/azure-cache-for-redis/cache-java-redisson-get-started.md

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -33,74 +33,46 @@ This quickstart uses the Maven archetype feature to generate the scaffolding for
3333

3434
## Set up the working environment
3535

36-
The steps in this section show you two options for how to select the Azure identity used for the Redis connection. The sample code looks at the value of the `AUTH_TYPE` environment variable and takes action depending on the value.
36+
The following steps show you how to set up the working environment for the Java app. You can choose to authenticate with Azure Cache for Redis using Microsoft Entra ID(recommended) or access keys.
3737

38-
### Identity option 1: Authentication with Redis Key
39-
40-
Depending on your operating system, add environment variables for your cache's host name and primary access key. Open a command prompt, or a terminal window, and set up the following values:
41-
42-
### [Linux](#tab/bash)
38+
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
4339

4440
```bash
4541
export REDIS_CACHE_HOSTNAME=<your-host-name>.redis.cache.windows.net
46-
export REDIS_CACHE_KEY=<your-primary-access-key>
47-
export AUTH_TYPE=RedisKey
48-
```
49-
50-
### [Windows](#tab/cmd)
51-
52-
```cmd
53-
set REDIS_CACHE_HOSTNAME=<your-host-name>.redis.cache.windows.net
54-
set REDIS_CACHE_KEY=<your-primary-access-key>
55-
set AUTH_TYPE=RedisKey
42+
export USER_NAME=<user-name>
5643
```
5744

58-
---
59-
6045
Replace the placeholders with the following values:
6146

6247
- `<your-host-name>`: The DNS host name, obtained from the *Properties* section of your Azure Cache for Redis resource in the Azure portal.
63-
- `<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.
48+
- `<user-name>`: Object ID of your managed identity or service principal.
49+
- You can get the user name by using the following steps:
6450

65-
### Identity option 2: Authentication with Microsoft Entra ID
51+
1. In the Azure portal, navigate to your Azure Cache for Redis instance.
52+
1. On the navigation pane, select **Data Access Configuration**.
53+
1. On the **Redis Users** tab, find the **Username** column.
6654

67-
Depending on your operating system, add environment variables for your cache's host name and user name. Open a command prompt, or a terminal window, and set up the following values:
55+
:::image type="content" source="media/cache-java-redisson-get-started/user-name.png" alt-text="Screenshot of the Azure portal that shows the Azure Cache for Redis Data Access Configuration page with the Redis Users tab and a Username value highlighted." lightbox="media/cache-java-redisson-get-started/user-name.png":::
6856

69-
### [Linux](#tab/bash)
57+
### [Access Key Authentication](#tab/accesskey)
7058

7159
```bash
7260
export REDIS_CACHE_HOSTNAME=<your-host-name>.redis.cache.windows.net
73-
export USER_NAME=<user-name>
74-
export AUTH_TYPE=MicrosoftEntraID
75-
```
76-
77-
### [Windows](#tab/cmd)
78-
79-
```cmd
80-
set REDIS_CACHE_HOSTNAME=<your-host-name>.redis.cache.windows.net
81-
set USER_NAME=<user-name>
82-
set AUTH_TYPE=MicrosoftEntraID
61+
export REDIS_CACHE_KEY=<your-primary-access-key>
8362
```
8463

85-
---
86-
8764
Replace the placeholders with the following values:
8865

8966
- `<your-host-name>`: The DNS host name, obtained from the *Properties* section of your Azure Cache for Redis resource in the Azure portal.
90-
- `<user-name>`: Object ID of your managed identity or service principal.
91-
- You can get the user name by using the following steps:
67+
- `<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.
9268

93-
1. In the Azure portal, navigate to your Azure Cache for Redis instance.
94-
1. On the navigation pane, select **Data Access Configuration**.
95-
1. On the **Redis Users** tab, find the **Username** column.
69+
---
9670

97-
:::image type="content" source="media/cache-java-redisson-get-started/user-name.png" alt-text="Screenshot of the Azure portal that shows the Azure Cache for Redis Data Access Configuration page with the Redis Users tab and a Username value highlighted." lightbox="media/cache-java-redisson-get-started/user-name.png":::
9871

9972
## Create a new Java app
10073

10174
Using Maven, generate a new quickstart app:
10275

103-
### [Linux](#tab/bash)
10476

10577
```bash
10678
mvn archetype:generate \
@@ -113,38 +85,38 @@ mvn archetype:generate \
11385
-Dversion=1.0
11486
```
11587

116-
### [Windows](#tab/cmd)
117-
118-
```cmd
119-
mvn archetype:generate \
120-
-DarchetypeGroupId=org.apache.maven.archetypes \
121-
-DarchetypeArtifactId=maven-archetype-quickstart \
122-
-DarchetypeVersion=1.3 \
123-
-DinteractiveMode=false \
124-
-DgroupId=example.demo \
125-
-DartifactId=redis-redisson-test \
126-
-Dversion=1.0
127-
```
128-
129-
---
130-
13188
Change to the new *redis-redisson-test* project directory.
13289

13390
Open the *pom.xml* file and add a dependency for [Redisson](https://github.com/redisson/redisson#maven):
13491

135-
```xml
92+
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
93+
94+
```xml
13695
<dependency>
13796
<groupId>com.azure</groupId>
13897
<artifactId>azure-identity</artifactId>
139-
<version>1.8.2</version>
98+
<version>1.11.2</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
14099
</dependency>
100+
101+
<dependency>
102+
<groupId>org.redisson</groupId>
103+
<artifactId>redisson</artifactId>
104+
<version>3.27.0</version> <!-- {x-version-update;org.redisson:redisson;external_dependency} -->
105+
</dependency>
106+
```
107+
108+
109+
### [Access Key Authentication](#tab/accesskey)
141110

111+
```xml
142112
<dependency>
143113
<groupId>org.redisson</groupId>
144114
<artifactId>redisson</artifactId>
145-
<version>3.24.3</version>
115+
<version>3.27.0</version> <!-- {x-version-update;org.redisson:redisson;external_dependency} -->
146116
</dependency>
147-
```
117+
```
118+
119+
---
148120

149121
Save the *pom.xml* file.
150122

@@ -251,19 +223,11 @@ Save *App.java*.
251223

252224
Execute the following Maven command to build and run the app:
253225

254-
### [Linux](#tab/bash)
255226

256227
```bash
257228
mvn compile exec:java -Dexec.mainClass=example.demo.App
258229
```
259230

260-
### [Windows](#tab/cmd)
261-
262-
```cmd
263-
mvn compile exec:java -Dexec.mainClass=example.demo.App
264-
```
265-
266-
---
267231

268232
In the following output, you can see that the `Message` key previously had a cached value, which was set in the last run. The app updated that cached value.
269233

0 commit comments

Comments
 (0)