Share via


Azure Functions용 RedisListTrigger(미리 보기)

RedisListTrigger는 목록에서 새 요소를 팝하고 해당 항목을 함수에 표시합니다.

Azure Cache for Redis 트리거 및 바인딩에 대한 자세한 내용은 Azure Functions 용 Redis Extension입니다.

함수 트리거의 가용성 범위

계층 기본 표준, 프리미엄 Enterprise, Enterprise Flash
목록

Important

Redis 트리거는 현재 소비 계획에서 실행되는 함수에 대해 지원되지 않습니다.

Important

Functions용 Node.js v4 모델은 Azure Cache for Redis 확장에서 아직 지원되지 않습니다. v4 모델의 작동 방식에 대한 자세한 내용은 Azure Functions Node.js 개발자 가이드를 참조하세요. v3과 v4의 차이점에 대해 자세히 알아보려면 마이그레이션 가이드를 참조하세요.

Important

Functions용 Python v2 모델은 Azure Cache for Redis 확장에서 아직 지원되지 않습니다. v2 모델의 작동 방식에 대한 자세한 내용은 Azure Functions Python 개발자 가이드를 참조하세요.

예시

Important

.NET 함수의 경우 in-process 모델에 대해 격리된 작업자 모델을 사용하는 것이 좋습니다. In-Process 모델과 격리된 작업자 모델을 비교하려면 격리된 작업자 모델과 Azure Functions의 .NET에 대한 In-process 모델 간의 차이점을 참조하세요.

다음 샘플에서는 키를 listTest폴링합니다.

using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.Functions.Worker.Extensions.Redis.Samples.RedisListTrigger
{
    public class SimpleListTrigger
    {
        private readonly ILogger<SimpleListTrigger> logger;

        public SimpleListTrigger(ILogger<SimpleListTrigger> logger)
        {
            this.logger = logger;
        }

        [Function(nameof(SimpleListTrigger))]
        public void Run(
            [RedisListTrigger(Common.connectionStringSetting, "listTest")] string entry)
        {
            logger.LogInformation(entry);
        }
    }
}

다음 샘플에서는 redisLocalhost의 localhost Redis 인스턴스에서 listTest 키를 폴링합니다.

package com.function.RedisListTrigger;

import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.redis.annotation.*;

public class SimpleListTrigger {
    @FunctionName("SimpleListTrigger")
    public void run(
            @RedisListTrigger(
                name = "req",
                connection = "redisConnectionString",
                key = "listTest",
                pollingIntervalInMs = 1000,
                maxBatchSize = 1)
                String message,
            final ExecutionContext context) {
            context.getLogger().info(message);
    }
}

이 샘플에서는 function.json 파일의 바인딩 데이터와 함께 동일한 index.js 파일을 사용합니다.

index.js 파일은 다음과 같습니다.

module.exports = async function (context, entry) {
    context.log(entry);
}

function.json에서 바인딩 데이터는 다음과 같습니다.

{
    "bindings": [
        {
            "type": "redisListTrigger",
            "listPopFromBeginning": true,
            "connection": "redisConnectionString",
            "key": "listTest",
            "pollingIntervalInMs": 1000,
            "maxBatchSize": 16,
            "name": "entry",
            "direction": "in"
        }
      ],
    "scriptFile": "index.js"
}

이 샘플에서는 function.json 파일의 바인딩 데이터와 함께 동일한 run.ps1 파일을 사용합니다.

run.ps1 파일은 다음과 같습니다.

param($entry, $TriggerMetadata)
Write-Host $entry

function.json에서 바인딩 데이터는 다음과 같습니다.

{
    "bindings": [
        {
            "type": "redisListTrigger",
            "listPopFromBeginning": true,
            "connection": "redisConnectionString",
            "key": "listTest",
            "pollingIntervalInMs": 1000,
            "maxBatchSize": 16,
            "name": "entry",
            "direction": "in"
        }
      ],
    "scriptFile": "run.ps1"
}

이 샘플에서는 function.json 파일의 바인딩 데이터와 함께 동일한 __init__.py 파일을 사용합니다.

Python v1 프로그래밍 모델을 사용하려면 함수 폴더의 별도 function.json 파일에서 바인딩을 정의해야 합니다. 자세한 내용은 Python 개발자 가이드참조하세요.

__init__.py 파일은 다음과 같습니다.

import logging

def main(entry: str):
    logging.info(entry)

function.json에서 바인딩 데이터는 다음과 같습니다.

{
    "bindings": [
        {
            "type": "redisListTrigger",
            "listPopFromBeginning": true,
            "connection": "redisConnectionString",
            "key": "listTest",
            "pollingIntervalInMs": 1000,
            "maxBatchSize": 16,
            "name": "entry",
            "direction": "in"
        }
      ],
    "scriptFile": "__init__.py"
}

특성

매개 변수 설명 필수 항목 기본값
Connection 다음과 같이 캐시 연결 문자열 포함하는 애플리케이션 설정이름입니다.<cacheName>.redis.cache.windows.net:6380,password...
Key 읽을 키입니다. 이 필드는 INameResolver를 사용하여 확인할 수 있습니다.
PollingIntervalInMs Redis를 폴링하는 빈도(밀리초)입니다. 선택 사항 1000
MessagesPerWorker 각 함수 인스턴스가 처리해야 하는 메시지 수입니다. 함수의 크기를 조정해야 하는 인스턴스 수를 결정하는 데 사용됩니다. 선택 사항 100
Count Redis에서 한 번에 팝업할 항목 수입니다. 항목은 병렬로 처리됩니다. LPOPRPOP에서 COUNT 인수를 사용하는 Redis 6.2 이상에서만 지원됩니다. 선택 사항 10
ListPopFromBeginning LPOP를 사용하여 처음부터 항목을 팝할지 또는 RPOP를 사용하여 끝에서 항목을 팝할지 여부를 결정합니다. 선택 사항 true

주석

매개 변수 설명 필수 항목 기본값
name "항목"
connection 다음과 같이 캐시 연결 문자열 포함하는 애플리케이션 설정이름입니다.<cacheName>.redis.cache.windows.net:6380,password...
key 이 필드는 INameResolver를 사용하여 확인할 수 있습니다.
pollingIntervalInMs Redis를 폴링하는 빈도(밀리초)입니다. 선택 사항 1000
messagesPerWorker 각 함수 인스턴스가 처리해야 하는 메시지 수입니다. 함수의 크기를 조정해야 하는 인스턴스 수를 결정하는 데 사용됩니다. 선택 사항 100
count Redis에서 한 번에 읽을 항목 수입니다. 이러한 작업은 병렬로 처리됩니다. 선택 사항 10
listPopFromBeginning 함수가 실행된 후 스트림 항목을 삭제할지 여부입니다. true

구성

다음 표에서는 function.json 파일에 설정된 바인딩 구성 속성을 설명합니다.

function.json 속성 설명 선택 사항 기본값
type 트리거의 이름입니다. 아니요
listPopFromBeginning 함수가 실행된 후 스트림 항목을 삭제할지 여부입니다. true로 설정합니다. true
connection 다음과 같이 캐시 연결 문자열 포함하는 애플리케이션 설정이름입니다.<cacheName>.redis.cache.windows.net:6380,password... 아니요
key 이 필드는 INameResolver를 사용하여 분석할 수 있습니다. 아니요
pollingIntervalInMs Redis를 폴링하는 빈도(밀리초)입니다. 1000
messagesPerWorker 각 함수 인스턴스가 처리해야 하는 메시지 수입니다. 함수의 크기를 조정해야 하는 인스턴스 수를 결정하는 데 사용됩니다. 100
count 캐시에서 한 번에 읽을 항목 수입니다. 항목은 병렬로 처리됩니다. 10
name ?
direction in로 설정합니다. 아니요

전체 예제는 예제 섹션을 참조하세요.

사용

RedisListTrigger는 목록에서 새 요소를 팝하고 해당 항목을 함수에 표시합니다. 트리거는 구성 가능한 고정 간격으로 Redis를 폴링하고 LPOPRPOP를 사용하여 목록에서 항목을 표시합니다.

Type 설명
byte[] 채널에서 보낸 메시지입니다.
string 채널에서 보낸 메시지입니다.
Custom 트리거는 Json.NET 직렬화를 사용하여 채널의 메시지를 string에서 사용자 지정 형식으로 매핑합니다.