Skip to content

ReJSON keyspace notification #95

Closed

Description

@dominiksimek

Hello,
I'm trying to use keyspace notification along with ReJSON module. I cannot find any information about how to enable this feature. I'm using redigo project (GO language) for accesing Redis database. Enabling keyspace notification for "raw" Redis command is quite simple:

// subscribe keyspace notification
if _, err := conn.Do("CONFIG", "SET", "notify-keyspace-events", "KEA"); err != nil {
  return err
}
psc := redis.PubSubConn{Conn: conn}
if err := psc.PSubscribe("__key*__:*"); err != nil {
  return err
}

// and receive notifications
for {
  switch msg := psc.Receive().(type) {
  case redis.Message:
    log.Warnf("pattern: %s, channel: %s, data: %s, ", msg.Pattern, msg.Channel, msg.Data)
  case redis.Subscription:
    log.Warnf("Subscription: %s %s %d", msg.Kind, msg.Channel, msg.Count)
  case error:
    log.Errorf("error: %v\n", msg)
    return
  }
}

Code above works fine for "original" Redis commands like "SET", "EXPIRE" etc., but doesn't work for ReJSON commands. E.g. "JSON.SET" command doesn't trigger any key event or notification. Could you provide some hints, how to enable this feature? Or there is no support for notifications in the ReJSON?

Thank you.

Activity

  1. itamarhaber commented on Nov 5, 2018

    @itamarhaber
    Collaborator

    Hello @dominiksimek

    ReJSON does not generate keyspace notifications - I'm sorry you spent time finding this out. As a workaround, you can call the regular PUBLISH after every update to one of its keys from your Golang code.

  2. Berkodev commented on Dec 6, 2018

    @Berkodev

    @itamarhaber Are there any plans to make ReJSON generate keyspace notifications? I'd like to be able to use that as well.

    What's the current rationale behind not generating keyspace notifications? Is it a performance overhead concern or just that somebody needs to do it? If the latter, I may try making a PR myself.

  3. itamarhaber commented on Dec 6, 2018

    @itamarhaber
    Collaborator

    @Berkodev My main concern at the moment is indeed performance - using RedisModule_Call to PUBLISH (twice) had quite an impact iirc. I suggest this should wait for proper resolution in https://github.com/antirez/redis/issues/5668 before implementing it.

  4. github-actions commented on Sep 12, 2019

    @github-actions

    Stale issue message

  5. StephenHaney commented on Jul 16, 2020

    @StephenHaney

    Hello just a quick question – the issue mentioned appears to be solved now. Is this issue still relevant or does ReJSON now generate keyspace notifications? Thanks!

  6. ajvirgona commented on Jul 31, 2020

    @ajvirgona

    Also interested in keyspace events on JSON keys. Any update on this?

  7. gkorland commented on Mar 9, 2022

    @gkorland
    Contributor

    ref #317

  8. xino1010 commented on Oct 24, 2023

    @xino1010

    Is this working?

    I have the flag notify-keyspace-events KEA.

    I'm using the latest version of the node-redis package and the keyevent is not received in the subscriber.

    Only works with primitive values await client.set("foo", "bar");

    const redis = require("redis");
    
    const client = redis.createClient();
    
    (async () => {
      client.on("error", (error) => {
        console.error("Redis Publisher Error:", error);
      });
    
      client.on("ready", () => {
        console.log("Redis Publisher connected");
      });
    
      await client.connect();
    
      const   user = {
         id: uuidv4(),
         name: "Jack"
      };
      await client.json.set(`user:${user.id}`, "$", user);
    })();
    const redis = require("redis");
    
    (async () => {
      const subscriber = redis.createClient();
    
      subscriber.on("error", (error) => {
        console.error("Redis Subscriber Error:", error);
      });
    
      subscriber.on("ready", () => {
        console.log("Redis Subscriber connected");
      });
    
      subscriber.subscribe("__keyevent@0__:set", (key, event) => {
        console.log("subscribe set", { key, event });
      });
    
      subscriber.subscribe("__keyevent@0__:del", (key, event) => {
        console.log("subscribe del", { key, event });
      });
     
     subscriber.subscribe("__keyevent@0__:expired", (key, event) => {
        console.log("subscribe exp", { key, event });
      });
    
      await subscriber.connect();
    })();
  9. Sokharev commented on Feb 21, 2024

    @Sokharev

    it works now, it's not reflected in docs but you should just subscribe with this pattern:
    "__keyevent@0__:json.set"

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions