Overview of Azure functions for Azure Cache for Redis (preview)
This article describes how to use Azure Cache for Redis with Azure Functions to create optimized serverless and event-driven architectures.
Azure Functions provide an event-driven programming model where triggers and bindings are key features. With Azure Functions, you can easily build event-driven serverless applications. Azure Cache for Redis provides a set of building blocks and best practices for building distributed applications, including microservices, state management, pub/sub messaging, and more.
Azure Cache for Redis can be used as a trigger for Azure Functions, allowing you to initiate a serverless workflow. This functionality can be highly useful in data architectures like a write-behind cache, or any event-based architectures.
You can integrate Azure Cache for Redis and Azure Functions to build functions that react to events from Azure Cache for Redis or external systems.
Action | Direction | Type | Preview |
---|---|---|---|
Triggers on Redis pub sub messages | N/A | RedisPubSubTrigger | Yes |
Triggers on Redis lists | N/A | RedisListsTrigger | Yes |
Triggers on Redis streams | N/A | RedisStreamsTrigger | Yes |
Scope of availability for functions triggers
Tier | Basic | Standard, Premium | Enterprise, Enterprise Flash |
---|---|---|---|
Pub/Sub | Yes | Yes | Yes |
Lists | Yes | Yes | Yes |
Streams | Yes | Yes | Yes |
Important
Redis triggers aren't currently supported for functions running in the Consumption plan.
Install extension
Functions run in an isolated C# worker process. To learn more, see Guide for running C# Azure Functions in an isolated worker process.
Add the extension to your project by installing this NuGet package.
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Redis --prerelease
Install bundle
Create a Java function project. You could use Maven:
mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=8
Add the extension bundle by adding or replacing the following code in your host.json file:
{ "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview", "version": "[4.11.*, 5.0.0)" } }
Warning
The Redis extension is currently only available in a preview bundle release.
Add the Java library for Redis bindings to the
pom.xml
file:<dependency> <groupId>com.microsoft.azure.functions</groupId> <artifactId>azure-functions-java-library-redis</artifactId> <version>${azure.functions.java.library.redis.version}</version> </dependency>
Add the extension bundle by adding or replacing the following code in your host.json file:
{ "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview", "version": "[4.11.*, 5.0.0)" }
}
>[!WARNING]
>The Redis extension is currently only available in a preview bundle release.
>
Redis connection string
Azure Cache for Redis triggers and bindings have a required property for the cache connection string. The connection string can be found on the Access keys menu in the Azure Cache for Redis portal. The Redis trigger or binding looks for an environmental variable holding the connection string with the name passed to the ConnectionStringSetting
parameter. In local development, the ConnectionStringSetting
can be defined using the local.settings.json file. When deployed to Azure, application settings can be used.
Related content
Feedback
Submit and view feedback for