-
Follow the Configure your local environment instructions for python.
-
Install the .NET SDK
-
Create a Python function project with the following commands:
mkdir RedisFunctions cd RedisFunctions func init --worker-runtime python -
Install the Redis Extension (manually for now, while the extension has not been added to the Microsoft.Azure.Functions.ExtensionBundle)
- Remove
extensionBundlefromhost.json - Run
func extensions install --package Microsoft.Azure.WebJobs.Extensions.Redis --version <version><version>should be the latest version of the extension from NuGet
- Remove
-
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'.")
- Set up an Azure Cache for Redis instance or install Redis locally.
- Add the connection string from your Redis instance to your
local.settings.jsonfile. It should look something like this:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "python", "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!