Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

Azure Function Custom Trigger Base on Azure Redis

Open loges16 opened this issue 7 years ago • 16 comments

Hi I need to trigger an function whenever an update/Insert happens in Azure redis cache is it Possible? to create a custom trigger for redis cache

loges16 avatar Jan 17 '18 05:01 loges16

Nothing there today that will do this. The best way to do a custom trigger currently is have something that can poll or subscribe to redis cache and publish an event to either a queue/topic or event grid when an event occurs. Then you can start building functions that listen to that event grid. One option is a timer based function that wakes up every few seconds and checks Redis, but not sure if the latency of "polling" would be too much. Other option would be some long-running container or VM or process that is subscribed to redis and can publish events.

May be worth adding an ask on our Uservoice for Redis Cache trigger - though I'm not certain how simple that would be to implement given how "close to the bits" Redis SDKs tend to work. Though looks like you beat me to it here 👍

jeffhollan avatar Jan 17 '18 19:01 jeffhollan

@jeffhollan Wouldn't it be possible to take a similar approach like here: https://medium.com/@yuka1984/how-to-make-custom-trigger-with-azure-functions-3bd85551ac5e ?

Thanks.

ChristianWeyer avatar Feb 13 '18 07:02 ChristianWeyer

would love to see redis subscription trigger. It would be super helpful and it would works nicely with your Azure Redis service.

forki avatar May 16 '18 09:05 forki

Agree - but not sure how we could pull it off looking at Redis APIs. Doesn't seem to be a good way to get change notifications on a redis server. Closest I can see is the keyspace notification but that doesn't provide reliable notifications and requires constant listening of events (and server config to send events) which our other triggers don't do in same way. I think best thing to do would be keep voting for the uservoice item linked above, it's a valid ask, but I don't see an 'easy' way to implement this with current Redis version

jeffhollan avatar May 17 '18 02:05 jeffhollan

https://redis.io/commands/subscribe is the command that is interesting here. Subscribing to channels.

forki avatar May 17 '18 05:05 forki

Yes but appears to suffer from same limitations in that you only get messages if are actively subscribed and constantly polling. Also that would be limited to only triggering on PUBLISH commands and initial ask was for trigger on insert/update of keys

jeffhollan avatar May 17 '18 05:05 jeffhollan

Yes the runtime would need to do the subscriptions that's the whole point and the only way how this would make sense in a consumption plan. But it would extremely useful. Especially given that we buy azure functions and redis hosting from Microsoft

forki avatar May 17 '18 05:05 forki

@jeffhollan, Redis' aren't key-space-notifications similar in concept to servicebus?

patriziobruno avatar Apr 27 '19 18:04 patriziobruno

I think a big distinction would be what I just read in the docs for this:

Because Redis Pub/Sub is fire and forget currently there is no way to use this feature if your application demands reliable notification of events, that is, if your Pub/Sub client disconnects, and reconnects later, all the events delivered during the time the client was disconnected are lost

That’s a bit tricky for functions where they are offline by design for periods at a time and expected to wake up and retrieve a message after getting a notification.

But I suspect there may be something here - just don’t know enough about redis if there’s some “task queue” we could pull from after getting a notification

jeffhollan avatar Apr 27 '19 18:04 jeffhollan

The function is offline - the function runtime is not

Jeff Hollan [email protected] schrieb am Sa., 27. Apr. 2019, 20:42:

I think a big distinction would be what I just read in the docs for this:

Because Redis Pub/Sub is fire and forget currently there is no way to use this feature if your application demands reliable notification of events, that is, if your Pub/Sub client disconnects, and reconnects later, all the events delivered during the time the client was disconnected are lost

That’s a bit tricky for functions where they are offline by design for periods at a time and expected to wake up and retrieve a message after getting a notification.

But I suspect there may be something here - just don’t know enough about redis if there’s some “task queue” we could pull from after getting a notification

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Azure/Azure-Functions/issues/658#issuecomment-487310032, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAOANCVOWYVRP3CIBBTO5DPSSNCBANCNFSM4EMDL6RQ .

forki avatar Apr 28 '19 09:04 forki

The function is offline - the function runtime is not

The function and the runtime both go offline. We have an additional component called the scale controller which can monitor your event source and activate your function if an event is present, but it's not a persistent connection. It checks for events briefly on a source, and then disconnects and checks again after some interval.

When we say your function can scale to zero we mean it. There are definitely instances of your function app after inactivity where nothing will be listening to the event source. Given what I'm seeing about Redis that's a big question is how to make sure if something happens when nothing is listening, we can still see something happened in the past and activate to consume it.

jeffhollan avatar Apr 28 '19 15:04 jeffhollan

Is there any plans by the Azure Functions team to provide an Azure Cache for Redis trigger? I'm currently working a contract where the main source of data is Cosmos DB and we are using the Cosmos DB trigger to replicate the data to the cache but the dev team want to update the cache and have that push an update back to Cosmos DB.

dh-technology-co-uk avatar Oct 07 '19 19:10 dh-technology-co-uk

Checking back into this thread to check if there is azure function trigger support for redis? I believe its not possible to create a consumption plan based custom trigger at this time, unless new releases have made this possible?

gorillapower avatar Jan 09 '22 12:01 gorillapower

@gorillapower , @dh-technology-co-uk , @forki

Update: there is now Azure Function Trigger support for Redis

Pubsub channels (including keyspace and keyevent notifications) are supported, as are Lists and Streams. Here's the actual repo for the functions extension.

And here is a basic getting started tutorial, plus a more advanced write-behind tutorial using Azure SQL DB.

MSFTeegarden avatar Nov 01 '23 00:11 MSFTeegarden

@gorillapower , @dh-technology-co-uk , @forki

Update: there is now Azure Function Trigger support for Redis

Pubsub channels (including keyspace and keyevent notifications) are supported, as are Lists and Streams. Here's the actual repo for the functions extension.

And here is a basic getting started tutorial, plus a more advanced write-behind tutorial using Azure SQL DB.

Awesome work @MSFTeegarden! Don't suppose I can ask when Consumption plan functions will be supported? 👀

willvelida avatar Nov 01 '23 00:11 willvelida

Hi @willvelida! Hope you're doing well. 😊 We plan on supporting Consumption functions in the march timeframe. Note that consumption functions won't help very much with the pubsub trigger since Redis pubsub is fire and forget.

Bindings are also supported now, by the way. There is documentation in the extension repo, although we haven't added to our public Azure docs yet.

MSFTeegarden avatar Nov 01 '23 15:11 MSFTeegarden