Integrate Azure Cache for Redis with Service Connector

This page shows supported authentication methods and clients, and shows sample code you can use to connect Azure Cache for Redis to other cloud services using Service Connector. You might still be able to connect to Azure Cache for Redis in other programming languages without using Service Connector. This page also shows default environment variable names and values (or Spring Boot configuration) you get when you create the service connection.

Supported compute services

Service Connector can be used to connect the following compute services to Azure Cache for Redis:

  • Azure App Service
  • Azure Functions
  • Azure Container Apps
  • Azure Spring Apps

Supported Authentication types and client types

The table below shows which combinations of authentication methods and clients are supported for connecting your compute service to Azure Cache for Redis using Service Connector. A “Yes” indicates that the combination is supported, while a “No” indicates that it is not supported.

Client type System-assigned managed identity User-assigned managed identity Secret / connection string Service principal
.NET No No Yes No
Go No No Yes No
Java No No Yes No
Java - Spring Boot No No Yes No
Node.js No No Yes No
Python No No Yes No
None No No Yes No

This table indicates that the only supported authentication method for all client types in the table is the Secret / connection string method. Other authentication methods are not supported for any of the client types to connect to Azure Cache for Redis using Service Connector.

Default environment variable names or application properties and sample code

Use the environment variable names and application properties listed below to connect compute services to Redis Server. For each example below, replace the placeholder texts <redis-server-name>, and <redis-key> with your own Redis server name and key. For more information about naming conventions, check the Service Connector internals article.

Connection String

Default environment variable name Description Example value
AZURE_REDIS_CONNECTIONSTRING StackExchange. Redis connection string <redis-server-name>.redis.cache.windows.net:6380,password=<redis-key>,ssl=True,defaultDatabase=0

Sample code

Refer to the steps and code below to connect to Azure Cache for Redis using a connection string.

  1. Install dependencies.

    dotnet add package StackExchange.Redis --version 2.6.122
    
  2. Get the Redis connection string from the environment variable added by Service Connector.

    using StackExchange.Redis;
    var connectionString = Environment.GetEnvironmentVariable("AZURE_REDIS_CONNECTIONSTRING");
    var _redisConnection = await RedisConnection.InitializeAsync(connectionString: connectionString);
    

Next steps

Follow the tutorials listed below to learn more about Service Connector.