Skip to content

Commit e8fd639

Browse files
committed
edits
1 parent bffd2e6 commit e8fd639

File tree

5 files changed

+193
-210
lines changed

5 files changed

+193
-210
lines changed

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

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ author: KarlErickson
55
ms.author: zhihaoguo
66
ms.date: 01/04/2022
77
ms.topic: quickstart
8-
98
ms.devlang: java
109
ms.custom: devx-track-java, devx-track-javaee, mode-api, mvc, devx-track-extended-java, ignite-2024
1110
---
@@ -31,7 +30,6 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
3130

3231
[!INCLUDE [redis-setup-working-environment](includes/redis-setup-working-environment.md)]
3332

34-
3533
## Create a new Java app
3634

3735
1. Use maven to generate a new quickstart app:
@@ -47,8 +45,8 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
4745
-Dversion=1.0
4846
```
4947

50-
1. Change to the new **redis-jedis-test** project directory.
51-
1. Open the *pom.xml* file. In the file, you see a dependency for [Jedis](https://github.com/xetorthio/jedis):
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):
5250

5351
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
5452

@@ -66,7 +64,6 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
6664
</dependency>
6765
```
6866

69-
7067
### [Access Key Authentication](#tab/accesskey)
7168

7269
[!INCLUDE [redis-access-key-alert](includes/redis-access-key-alert.md)]
@@ -78,31 +75,31 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
7875
<version>5.1.0</version> <!-- {x-version-update;redis.clients:jedis;external_dependency} -->
7976
</dependency>
8077
```
81-
82-
---
8378

84-
1. Close the *pom.xml* file.
85-
1. Open *App.java* and see the code with the following code:
86-
79+
1. Close the **pom.xml** file.
80+
81+
1. Open **App.java** and see the code with the following code:
82+
8783
### [Microsoft Entra ID Authentication (recommended)](#tab/entraid)
88-
```java
84+
85+
```java
8986
package example.demo;
90-
87+
9188
import com.azure.identity.DefaultAzureCredential;
9289
import com.azure.identity.DefaultAzureCredentialBuilder;
9390
import com.azure.core.credential.TokenRequestContext;
9491
import redis.clients.jedis.DefaultJedisClientConfig;
9592
import redis.clients.jedis.Jedis;
96-
93+
9794
/**
9895
* Redis test
9996
*
10097
*/
101-
public class App
98+
public class App
10299
{
103100
public static void main( String[] args )
104101
{
105-
102+
106103
boolean useSsl = true;
107104

108105
//Construct a Token Credential from Identity library, e.g. DefaultAzureCredential / ClientSecretCredential / Client CertificateCredential / ManagedIdentityCredential etc.
@@ -149,62 +146,63 @@ Clone the repo [Java quickstart](https://github.com/Azure-Samples/azure-cache-re
149146
```
150147

151148
### [Access Key Authentication](#tab/accesskey)
149+
152150
```java
153151
package example.demo;
154-
152+
155153
import redis.clients.jedis.DefaultJedisClientConfig;
156154
import redis.clients.jedis.Jedis;
157-
155+
158156
/**
159157
* Redis test
160158
*
161159
*/
162-
public class App
160+
public class App
163161
{
164162
public static void main( String[] args )
165163
{
166-
164+
167165
boolean useSsl = true;
168166
String cacheHostname = System.getenv("REDIS_CACHE_HOSTNAME");
169167
String cachekey = System.getenv("REDIS_CACHE_KEY");
170-
168+
171169
// Connect to the Azure Cache for Redis over the TLS/SSL port using the key.
172170
Jedis jedis = new Jedis(cacheHostname, 6380, DefaultJedisClientConfig.builder()
173171
.password(cachekey)
174172
.ssl(useSsl)
175173
.build());
176-
174+
177175
// Perform cache operations using the cache connection object...
178-
176+
179177
// Simple PING command
180178
System.out.println( "\nCache Command : Ping" );
181179
System.out.println( "Cache Response : " + jedis.ping());
182-
180+
183181
// Simple get and put of integral data types into the cache
184182
System.out.println( "\nCache Command : GET Message" );
185183
System.out.println( "Cache Response : " + jedis.get("Message"));
186-
184+
187185
System.out.println( "\nCache Command : SET Message" );
188186
System.out.println( "Cache Response : " + jedis.set("Message", "Hello! The cache is working from Java!"));
189-
187+
190188
// Demonstrate "SET Message" executed as expected...
191189
System.out.println( "\nCache Command : GET Message" );
192190
System.out.println( "Cache Response : " + jedis.get("Message"));
193-
191+
194192
// Get the client list, useful to see if connection list is growing...
195193
System.out.println( "\nCache Command : CLIENT LIST" );
196194
System.out.println( "Cache Response : " + jedis.clientList());
197-
195+
198196
jedis.close();
199197
}
200198
}
201199
```
200+
202201
---
203-
204-
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.
205202

206-
1. Close the *App.java*.
203+
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.
207204

205+
1. Close the **App.java** file.
208206

209207
## Build and run the app
210208

@@ -235,7 +233,6 @@ Cache Response : id=777430 addr= :58989 fd=22 name= age=1 idle=0 fla
235233

236234
[!INCLUDE [redis-cache-resource-group-clean-up](includes/redis-cache-resource-group-clean-up.md)]
237235

238-
239236
## Next steps
240237

241238
In this quickstart, you learned how to use Azure Cache for Redis from a Java application. Continue to the next quickstart to use Azure Cache for Redis with an ASP.NET web app.

0 commit comments

Comments
 (0)