How to get old and new values on Redis notification

redistrigger

I need to implement a feature like: once any specific key in Redis is updated, call a C function with the old and new values as arguments.

Currently, I know Redis notification and I could use hiredis to subscribe a keyspace event. While Redis notification doesn't tell me the old or new value. My current solution is getting old and new value in another session rathen than the one subscrbing the event. Once event occurs, get the new value then.

But I believe this solution may have potential bug. Say if the value is updated twice in a very short interval, I could get notified, but when I call get value, I may only get the second value, since the first value has been flushed very quickly.

Is my worry necessary? Is there any solution to implement Redis notification with old and new values?

Thanks in advance.

Best Answer

As a workaround, you could have a field OLD_VALUE that is filled by your application logic together with the real field in a transaction. Doing so, you would also get a notification for the old value