Redis connection fails with Microsoft Entra for cache authentication

小牟禮大樹 20 Reputation points
2025-04-18T23:44:01.8466667+00:00

Hello everyone,

I’m trying to connect to Azure Cache for Redis (Enterprise tier) using Microsoft Entra ID for cache authentication, but the connection fails.

The error message I receive is:

2025-04-18T23:39:49.653148192Z result = redis.ping()
2025-04-18T23:39:49.653150519Z ^^^^^^^^
2025-04-18T23:39:49.653152887Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/commands/core.py", line 1212, in ping
2025-04-18T23:39:49.653155554Z return self.execute_command("PING", **kwargs)
2025-04-18T23:39:49.653158021Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653160403Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/client.py", line 559, in execute_command
2025-04-18T23:39:49.653162935Z return self._execute_command(*args, **options)
2025-04-18T23:39:49.653165337Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653167785Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/client.py", line 565, in _execute_command
2025-04-18T23:39:49.653181065Z conn = self.connection or pool.get_connection(command_name, **options)
2025-04-18T23:39:49.653183704Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653186168Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 1422, in get_connection
2025-04-18T23:39:49.653188711Z connection.connect()
2025-04-18T23:39:49.653190998Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 369, in connect
2025-04-18T23:39:49.653193513Z self.on_connect()
2025-04-18T23:39:49.653195884Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 434, in on_connect
2025-04-18T23:39:49.653198570Z auth_response = self.read_response()
2025-04-18T23:39:49.653200996Z ^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653203452Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 592, in read_response
2025-04-18T23:39:49.653211713Z response = self._parser.read_response(disable_decoding=disable_decoding)
2025-04-18T23:39:49.653215219Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653218056Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/_parsers/resp2.py", line 15, in read_response
2025-04-18T23:39:49.653220695Z result = self._read_response(disable_decoding=disable_decoding)
2025-04-18T23:39:49.653223128Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653225644Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/_parsers/resp2.py", line 38, in _read_response
2025-04-18T23:39:49.653228328Z raise error
2025-04-18T23:39:49.653230723Z redis.exceptions.AuthenticationError: invalid username-password pair

Here is the configuration I’ve applied:

  • On the Redis Enterprise cluster
    • Microsoft Entra Authentication is enabled on the Redis Enterprise cluster.
  • On the Web App:
    • System-assigned managed identity is enabled.
    • The appropriate Azure role to the managed identity via IAM.

Below is the python code I’m using to connect:

cred = DefaultAzureCredential()
token = cred.get_token("https://redis.azure.com/.default").token
redis = redis.Redis(**{
    host=
Microsoft Entra
Microsoft Entra
A group of Microsoft multicloud identity and access solutions.
2,560 questions
{count} votes

Accepted answer
  1. Mahesh Kurva 3,985 Reputation points Microsoft External Staff Moderator
    2025-04-21T07:41:26.8466667+00:00

    Hi 小牟禮大樹,

    Greetings!

    As I understand it, you're encountering an authentication issue when trying to connect to Azure Cache for Redis (Enterprise tier) using Microsoft Entra ID.

    User's image

    Ensure that Microsoft Entra authentication is supported for the tier you're using. As of now, Microsoft Entra authentication isn't supported in the Enterprise tiers of Azure Cache for Redis.

    For more information, please refer the document: https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-azure-active-directory-for-authentication

    Hope this helps. Do let us know if you any further queries.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.