- Install the Azure Functions Core Tools.
- Install the .NET SDK
- Create a .NET out-of-process function project with the following commands:
mkdir RedisFunctions cd RedisFunctions func init --worker-runtime dotnet-isolated
- Install the Redis Extension
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Redis --prerelease
- Create a
Function.cs
file with the following code:using Microsoft.Extensions.Logging; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Extensions.Redis; public class Function { private readonly ILogger<Function> logger; public Function(ILogger<Function> logger) { this.logger = logger; } [Function("PubSubTrigger")] public void Run( [RedisPubSubTrigger("Redis", "pubsubTest")] string message) { logger.LogInformation($".NET out-of-process function triggered on pub/sub message '{message}' from channel 'pubsubTest'."); } }
- Set up an Azure Cache for Redis instance or install Redis locally.
- Add the connection string from your Redis instance to your
local.settings.json
file. It should look something like this:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", "Redis": "<connectionString>" } }
- Start the function locally:
func start
- Connect to your Redis cache using redis-cli, RedisInsight or some other Redis client.
- Publish a message to the channel
pubsubTest
:PUBLISH pubsubTest testing
- Your function should trigger!