Skip to content

Get keyspace notifications only if key changed #2149

Closed

Description

@zhazhdam3st1

Redis document say:

IMPORTANT all the commands generate events only if the target key is really
modified. For instance an SREM deleting a non-existing element from a Set will
not actually change the value of the key, so no event will be generated.

However, when i tried to set key with value which it already had, i
received notification to.

$ redis-cli config set notify-keyspace-events KEA
$ redis-cli psubscribe '__key*__:*'
$ redis-cli set test 1

Now i'm get "pmessage","__key*__:*","__keyspace@0__:test","set"

$ redis-cli set test 1

Now i'm get it to, but value didn't change! "pmessage","__key*__:*","__keyspace@0__:test","set"

Where I am wrong?

Activity

  1. badboy commented on Nov 19, 2014

    @badboy
    Contributor

    Twice the same value is still considered a real change. Redis doesn't compare values so it can't know if you just reset the same value again or a new one (always checking for equality would be more expensive then just setting it).
    The docu lists only an example for a non-existent key. Deleting something that isn't there is essentially a noop and thus not reported.

  2. zhazhdam3st1 commented on Nov 19, 2014

    @zhazhdam3st1
    Author

    Thank you for explaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions