Skip to content

Latest commit

 

History

History
65 lines (60 loc) · 2.39 KB

SetupGuide_Python.md

File metadata and controls

65 lines (60 loc) · 2.39 KB

Setup Function Project

  1. Follow the Configure your local environment instructions for python.

  2. Install the .NET SDK

  3. Create a Python function project with the following commands:

     mkdir RedisFunctions
     cd RedisFunctions
     func init --worker-runtime python
    
  4. Install the Redis Extension (manually for now, while the extension has not been added to the Microsoft.Azure.Functions.ExtensionBundle)

    1. Remove extensionBundle from host.json
    2. Run func extensions install --package Microsoft.Azure.WebJobs.Extensions.Redis --version <version>
      • <version> should be the latest version of the extension from NuGet
  5. Create a folder PubSubTrigger, and add the following two files into the folder:

    function.json:

    {
      "bindings": [
        {
          "type": "redisPubSubTrigger",
          "connection": "Redis",
          "channel": "pubsubTest",
          "name": "message",
          "direction": "in"
        }
      ],
      "scriptFile": "__init__.py"
    }

    __init__.py:

    import logging
    
    def main(message: str):
        logging.info("Python 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": "python",
        "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!