Get Notification only if the value of a key has been changed ?

1,518 views
Skip to first unread message

Josef Meier

unread,
Dec 23, 2015, 8:45:39 AM12/23/15
to Redis DB
Hi,

I have a few publishers to my redis database and many subscribers.

I'm trying to find a way to notify the subscribers by the redis-server if a key's value(!)  has been changed (!). Currently I use the keyspace notification mechanism of redis like this:

psubscribe __key*__

The reason for doing that is to minimize the network traffic in my system while publishers are writing into the database.

Example of what I try to gain:

If I send this in redis-cli:

set LULU 1234
set LULU 1234

I only want to get a notification for the first "set" (cause it has changed the value of LULU) and NOT for the second "set" (cause it doesn't change the value of LULU).

How is this possible?

Do I have to patch redis for that :-( ?

Best regards,

Josef



Itamar Haber

unread,
Dec 23, 2015, 9:03:03 AM12/23/15
to redi...@googlegroups.com
Hi Josef,

Do I have to patch redis for that :-( ?

It appears so - Redis doesn't differentiate between an update that actually changes the value and one that doesn't. Alternatively, you could perform the `SET` using a Lua script that also performs the equality check and emit a regualr PubSub (not keyspace notification) message from it to the relevant subscribers.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Chief Developer Advocate
Redis Watch Newsletter | Curator and Janitor
Redis Labs | ~ of Redis

Mobile: +1 (415) 688 2443
Office: +1 (650) 461 4652
Mobile (IL): +972 (54) 567 9692
Office (IL): +972 (3) 720 8515 Ext. 123
Email: ita...@redislabs.com
Twitter: @itamarhaber
Skype: itamar.haber

Blog  |  Twitter  |  LinkedIn


Josef Meier

unread,
Dec 23, 2015, 9:51:43 AM12/23/15
to Redis DB
Dear Itamar,

thanks for your response.

I'm surprised that this performance gain (reduced network load if key value doesn't change) is not supported out of the box by redis.

A global flag in redis which allows to do this verify in the core c code would be easy to implement and should be useful for others to in my opinion. Any chance to open a feature request for that?

Best regards,

Josef

Itamar Haber

unread,
Dec 23, 2015, 11:15:05 AM12/23/15
to redi...@googlegroups.com
Inline

On Wed, Dec 23, 2015 at 4:51 PM, Josef Meier <jo.m...@gmx.de> wrote:
Dear Itamar,

thanks for your response.


My pleasure always.
 
I'm surprised that this performance gain (reduced network load if key value doesn't change) is not supported out of the box by redis.


The gain is offset by the loss - an additional check (compare old and new value) has a computational price on the server :) One of the reasons, perhaps, why this isn't available OOtB is because it wasn't requested.
 
A global flag in redis which allows to do this verify in the core c code would be easy to implement and should be useful for others to in my opinion. Any chance to open a feature request for that?


I don't know how easy/hard it will be to implement, but feature requests can and should be made by anyone. You can discuss them here - usually a good idea - to get feedback from the community. If you feel apt/up to it, you can even make a pull request to the Redis repository with the proposed changes to merge. 
Reply all
Reply to author
Forward
0 new messages