Is there a way to trigger a Lua script on every new record added to a Redis stream?

Hi!

long time Redis fan, first time poster here :wink:

Is there a way to have a Lua script trigger on every new record added to a Redis stream? What I’m trying to do is to reconstruct a certain state from, effectively a WRITE-AHEAD-LOG events that are being pushed into a Redis stream. The state itself will be kept in usual Redis structures (hashes, etc.)

Thanks,
Roman.

Hello,

Option 1:
Have you look at the keyspace notification?

The event will be pushed on a Pub/Sub Channel.

Option 2: (my favorite)
You can use Redis Gears module and capture the event on they key and publish this directly on a Streams.

Let me know if you need more information

1 Like

Yes I have looked at keyspace notifications – but I need something sitting inside the database to react to those – I was hoping this could’ve been a Lua script running inside of Redis, but I couldn’t find any examples of that. Would appreciate if you can point me to how this can be done – all I could find was some experimental work that requires patching Redis https://matt.sh/advanced-redis-pubsub-scripts

I didn’t know about Redis Gears – thanks for pointing that out. It looks like the scripting language there is Python tho, and I was hoping for something much lighterwieight like Lua.

What is your concern about Python? Performance? Are you planing to run heavyweight logic?
Notice Gears can:

  1. Run asynchronously --> it won’t impact the key update too much.
  2. Can trigger LUA script if needed and only act as LUA code invoker.

My biggest concern is Python dependency itself – this is Redis in embedded environment and dragging Python int would blow up disk budget 1.5x unfortunately.

hello @rvs , Did you find any way to intercept keyspace events in LUA script ?