- Install the Azure Functions Core Tools.
- Install the .NET SDK
- Create a .NET function project with the following commands:
mkdir RedisFunctions cd RedisFunctions func init --worker-runtime dotnet
- Install the Redis Extension
dotnet add package Microsoft.Azure.WebJobs.Extensions.Redis --prerelease
- Create a
Function.cs
file with the following code:using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Redis; using Microsoft.Extensions.Logging; public static class Function { [FunctionName(nameof(PubSubTrigger))] public static void PubSubTrigger( [RedisPubSubTrigger("Redis", "pubsubTest")] string message, ILogger logger) { logger.LogInformation($".NET 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", "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!