Skip to content

Latest commit

 

History

History
64 lines (58 loc) · 2.12 KB

SetupGuide_DotnetIsolated.md

File metadata and controls

64 lines (58 loc) · 2.12 KB

Setup Function Project

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

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-isolated",
        "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!