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
Copy file name to clipboardExpand all lines: articles/service-connector/how-to-integrate-redis-cache.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,12 @@ author: maud-lv
5
5
ms.author: malev
6
6
ms.service: service-connector
7
7
ms.topic: how-to
8
-
ms.date: 03/14/2025
8
+
ms.date: 07/23/2025
9
9
---
10
10
11
11
# Integrate Azure Cache for Redis with Service Connector
12
12
13
-
This article covers supported authentication methods, clients, and sample code you can use to connect your apps to Azure Cache for Redis using Service Connector.In this article, you'll also find default environment variable names, values, and configuration obtained when creating service connections.
13
+
This article covers supported authentication methods, clients, and sample code you can use to connect your apps to Azure Cache for Redis using Service Connector.In this article, you'll also find default environment variable names, values, and configuration obtained when creating service connections.
14
14
15
15
## Supported compute services
16
16
@@ -28,13 +28,13 @@ The following table shows which combinations of authentication methods and clien
28
28
29
29
| Client type | System-assigned managed identity | User-assigned managed identity | Secret / connection string | Service principal |
Copy file name to clipboardExpand all lines: articles/service-connector/includes/code-redis-me-id.md
+7-234Lines changed: 7 additions & 234 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ author: xfz11
3
3
description: Code example
4
4
ms.service: service-connector
5
5
ms.topic: include
6
-
ms.date: 1/2/2025
6
+
ms.date: 07/23/2025
7
7
ms.author: xiaofanzhou
8
8
---
9
9
@@ -42,250 +42,23 @@ ms.author: xiaofanzhou
42
42
43
43
#### [Java](#tab/java)
44
44
45
-
1. Add the following dependency in your `pom.xml` file:
45
+
Follow the instructions at [Connect to Azure Managed Redis](https://redis.io/docs/latest/develop/clients/jedis/amr/) for using the `redis-authx-entraid` package.
1. Add the authentication logic with environment variables set by Service Connector. For more information, see [Azure-AAD-Authentication-With-Jedis](https://aka.ms/redis/aad/sample-code/java-jedis).
// Create Jedis client and connect to Azure Cache for Redis over the TLS/SSL port using the access token as password.
98
-
// Note, Redis Cache host name and port are required below.
99
-
Jedis jedis = new Jedis(cacheHostname, 6380, DefaultJedisClientConfig.builder()
100
-
.password(token) // Microsoft Entra access token as password is required.
101
-
.user(username) // Username is Required
102
-
.ssl(useSsl) // SSL Connection is Required
103
-
.build());
104
-
105
-
// Set a value against your key in the Redis cache.
106
-
jedis.set("Az:key", "testValue");
107
-
System.out.println(jedis.get("Az:key"));
108
-
109
-
// Close the Jedis Client
110
-
jedis.close();
111
-
```
112
47
#### [Spring Boot](#tab/springBoot)
48
+
113
49
Not supported yet.
114
50
115
51
#### [Python](#tab/python)
116
52
117
-
1. Install dependencies.
118
-
119
-
```bash
120
-
pip install redis azure-identity
121
-
```
122
-
123
-
1. Add the authentication logic with environment variables set by Service Connector. For more information, see [azure-aad-auth-with-redis-py](https://aka.ms/redis/aad/sample-code/python).
124
-
125
-
```python
126
-
import os
127
-
import time
128
-
import logging
129
-
import redis
130
-
import base64
131
-
import json
132
-
from azure.identity import DefaultAzureCredential
133
-
134
-
host = os.getenv('AZURE_REDIS_HOST')
135
-
scope = "https://redis.azure.com/.default"
136
-
port = 6380 # Required
137
-
138
-
def extract_username_from_token(token):
139
-
parts = token.split('.')
140
-
base64_str = parts[1]
141
-
142
-
if len(base64_str) % 4 == 2:
143
-
base64_str += "=="
144
-
elif len(base64_str) % 4 == 3:
145
-
base64_str += "="
146
-
147
-
json_bytes = base64.b64decode(base64_str)
148
-
json_str = json_bytes.decode('utf-8')
149
-
jwt = json.loads(json_str)
150
-
151
-
return jwt['oid']
152
-
153
-
def re_authentication():
154
-
_LOGGER = logging.getLogger(__name__)
155
-
# Uncomment the following lines corresponding to the authentication type you want to use.
return not token or token.expires_on - time.time() < refresh_offset
210
-
211
-
if __name__ == '__main__':
212
-
re_authentication()
213
-
```
53
+
Follow the instructions at [Connect to Azure Managed Redis](https://redis.io/docs/latest/develop/clients/redis-py/amr/) for using the `redis-entra-id` package.
214
54
215
55
#### [Go](#tab/go)
216
-
Not supported yet.
217
56
218
-
#### [Node.js](#tab/nodejs)
219
-
220
-
1. Install dependencies.
57
+
Follow the instructions at [Connect to Azure Managed Redis](https://redis.io/docs/latest/develop/clients/go/amr/) for using the `go-redis-entraid` package.
221
58
222
-
```bash
223
-
npm install redis @azure/identity
224
-
```
225
-
226
-
1. Add the authentication logic with environment variables set by Service Connector. For more information, see [Azure Cache for Redis: Microsoft Entra ID with node-redis client library](https://aka.ms/redis/aad/sample-code/js-noderedis).
227
-
228
-
```javascript
229
-
import { createClient } from "redis";
230
-
import { DefaultAzureCredential } from "@azure/identity";
Follow the instructions at [Connect to Azure Managed Redis](https://redis.io/docs/latest/develop/clients/nodejs/amr/) for using the `@redis/entraid` package.
0 commit comments