RedisListTrigger Azure Function (preview)
The RedisListTrigger
pops new elements from a list and surfaces those entries to the function.
Scope of availability for functions triggers
Tier | Basic | Standard, Premium | Enterprise, Enterprise Flash |
---|---|---|---|
Lists | Yes | Yes | Yes |
Important
Redis triggers aren't currently supported for functions running in the Consumption plan.
Example
The following sample polls the key listTest
at a localhost Redis instance at 127.0.0.1:6379
:
The isolated process examples aren't available in preview.
The following sample polls the key listTest
at a localhost Redis instance at redisLocalhost
:
@FunctionName("ListTrigger")
public void ListTrigger(
@RedisListTrigger(
name = "entry",
connectionStringSetting = "redisLocalhost",
key = "listTest",
pollingIntervalInMs = 100,
messagesPerWorker = 10,
count = 1,
listPopFromBeginning = false)
String entry,
final ExecutionContext context) {
context.getLogger().info(entry);
}
This sample uses the same index.js
file, with binding data in the function.json
file.
Here's the index.js
file:
module.exports = async function (context, entry) {
context.log(entry);
}
From function.json
, here's the binding data:
{
"bindings": [
{
"type": "redisListTrigger",
"listPopFromBeginning": true,
"connectionStringSetting": "redisLocalhost",
"key": "listTest",
"pollingIntervalInMs": 1000,
"messagesPerWorker": 100,
"count": 10,
"name": "entry",
"direction": "in"
}
],
"scriptFile": "index.js"
}
This sample uses the same run.ps1
file, with binding data in the function.json
file.
Here's the run.ps1
file:
param($entry, $TriggerMetadata)
Write-Host $entry
From function.json
, here's the binding data:
{
"bindings": [
{
"type": "redisListTrigger",
"listPopFromBeginning": true,
"connectionStringSetting": "redisLocalhost",
"key": "listTest",
"pollingIntervalInMs": 1000,
"messagesPerWorker": 100,
"count": 10,
"name": "entry",
"direction": "in"
}
],
"scriptFile": "run.ps1"
}
This sample uses the same __init__.py
file, with binding data in the function.json
file.
The Python v1 programming model requires you to define bindings in a separate function.json file in the function folder. For more information, see the Python developer guide.
Here's the __init__.py
file:
import logging
def main(entry: str):
logging.info(entry)
From function.json
, here's the binding data:
{
"bindings": [
{
"type": "redisListTrigger",
"listPopFromBeginning": true,
"connectionStringSetting": "redisLocalhost",
"key": "listTest",
"pollingIntervalInMs": 1000,
"messagesPerWorker": 100,
"count": 10,
"name": "entry",
"direction": "in"
}
],
"scriptFile": "__init__.py"
}
Attributes
Parameter | Description | Required | Default |
---|---|---|---|
ConnectionStringSetting |
Name of the setting in the appsettings that holds the cache connection string (for example, <cacheName>.redis.cache.windows.net:6380,password=... ). |
Yes | |
Key |
Key to read from. This field can be resolved using INameResolver . |
Yes | |
PollingIntervalInMs |
How often to poll Redis in milliseconds. | Optional | 1000 |
MessagesPerWorker |
How many messages each functions instance should process. Used to determine how many instances the function should scale to. | Optional | 100 |
Count |
Number of entries to pop from Redis at one time. These are processed in parallel. Only supported on Redis 6.2+ using the COUNT argument in LPOP and RPOP . |
Optional | 10 |
ListPopFromBeginning |
Determines whether to pop entries from the beginning using LPOP , or to pop entries from the end using RPOP . |
Optional | true |
Annotations
Parameter | Description | Required | Default |
---|---|---|---|
name |
"entry" | ||
connectionStringSetting |
The name of the setting in the appsettings that contains the cache connection string. For example: <cacheName>.redis.cache.windows.net:6380,password... |
Yes | |
key |
This field can be resolved using INameResolver. | Yes | |
pollingIntervalInMs |
How often to poll Redis in milliseconds. | Optional | 1000 |
messagesPerWorker |
How many messages each functions instance should process. Used to determine how many instances the function should scale to. | Optional | 100 |
count |
Number of entries to read from Redis at one time. These are processed in parallel. | Optional | 10 |
listPopFromBeginning |
Whether to delete the stream entries after the function has run. | Yes | true |
Configuration
The following table explains the binding configuration properties that you set in the function.json file.
function.json Property | Description | Optional | Default |
---|---|---|---|
type |
Name of the trigger. | No | |
listPopFromBeginning |
Whether to delete the stream entries after the function has run. Set to true . |
Yes | true |
connectionString |
The name of the setting in the appsettings that contains the cache connection string. For example: <cacheName>.redis.cache.windows.net:6380,password... |
No | |
key |
This field can be resolved using INameResolver . |
No | |
pollingIntervalInMs |
How often to poll Redis in milliseconds. | Yes | 1000 |
messagesPerWorker |
How many messages each functions instance should process. Used to determine how many instances the function should scale to. | Yes | 100 |
count |
Number of entries to read from the cache at one time. These are processed in parallel. | Yes | 10 |
name |
? | Yes | |
direction |
Set to in . |
No |
See the Example section for complete examples.
Usage
The RedisListTrigger
pops new elements from a list and surfaces those entries to the function. The trigger polls Redis at a configurable fixed interval, and uses LPOP
and RPOP
to pop entries from the lists.
Output
Note
Once the RedisListTrigger
becomes generally available, the following information will be moved to a dedicated Output page.
StackExchange.Redis.RedisValue
Output Type | Description |
---|---|
StackExchange.Redis.RedisValue |
string , byte[] , ReadOnlyMemory<byte> : The entry from the list. |
Custom |
The trigger uses Json.NET serialization to map the message from the channel from a string to a custom type. |
Note
Once the RedisListTrigger
becomes generally available, the following information will be moved to a dedicated Output page.
Output Type | Description |
---|---|
byte[] |
The message from the channel. |
string |
The message from the channel. |
Custom |
The trigger uses Json.NET serialization to map the message from the channel from a string into a custom type. |
Related content
Feedback
Submit and view feedback for