16

I have a program that utilizes a redis key with an expire time set. I want to detect when there is a new entry to the data set. I can tell when there is a removal by listening for the "expired" event, but the "set" and "expire" events are fired every time the key is set, even if it's already in the database.

Is there a keyspace event for a NEW key appearing?

1
  • don't think there is in the current official version, but maybe you can achieve that by a lua script
    – sel-fish
    Aug 6, 2016 at 5:35

1 Answer 1

2

There's no keyspace configuration that detects that a key was overwritten vs. newly added.

If you are primarily using the SET command, you may be able to take advantage of the NX option and publish a custom event based on the result. Obviously this isn't an ideal approach, but it's something. https://redis.io/commands/set

Example of a custom event:

PUBLISH __keyevent@0__:new_data_entry new_key

Details on that here: https://redis.io/topics/notifications#type-of-events

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.