Skip to content

Latest commit

 

History

History
58 lines (54 loc) · 1.94 KB

SetupGuide_Dotnet.md

File metadata and controls

58 lines (54 loc) · 1.94 KB

Setup Function Project

  1. Install the Azure Functions Core Tools.
  2. Install the .NET SDK
  3. Create a .NET function project with the following commands:
     mkdir RedisFunctions
     cd RedisFunctions
     func init --worker-runtime dotnet
    
  4. Install the Redis Extension
    dotnet add package Microsoft.Azure.WebJobs.Extensions.Redis --prerelease
    
  5. 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'.");
      }
    }

Setup Redis Cache

  1. Set up an Azure Cache for Redis instance or install Redis locally.
  2. 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>"
      }
    }

Run Function

  1. Start the function locally:
    func start
    
  2. Connect to your Redis cache using redis-cli, RedisInsight or some other Redis client.
  3. Publish a message to the channel pubsubTest:
    PUBLISH pubsubTest testing
    
  4. Your function should trigger!