skip to Main Content

I am trying to setup a node client to subscribe to expired key events, doing something like this

  export async function redisSubscriber(): Promise<void> {
    await redis.config("SET", "notify-keyspace-events", "Ex");

    const subscribe = redisServer.duplicate();

    subscribe.subscribe("__keyevent@0__:expired", async (key): Promise<any> => {
      logger.info("key expired=> " + key);
    });
}

redisSubscriber().catch((err: unknown) => {
  logger.error(
    `error in redis subscriber: ${
      err instanceof Error ? err.message : inspect(err)
    }`
  );
});

However I am getting this error

error in redis subscriber: ERR unknown command `config`, with args beginning with: `SET`, `notify-keyspace-events`, `Ex`

I am assuming this is due to config being a restricted command.

How do I execute the config command from a node script to enable expired key events when redis runs as elasticache in aws?

I have tried adding a Parameter Group in aws and assigned it to my instance and I can receive expired events using the redis-cli tool, however it does not seem to work inside a node script

redis-cli -h <host> -p 6379 -a <token> --tls --csv subscribe '__keyevent@0__:expired'

2

Answers


  1. Chosen as BEST ANSWER

    I was able to get it working by adding a Parameter Group with notify-keyspace-events set to Ex and tie it to the redis instance. For some reason I could not get the ioredis.subscribe to work, however it works using the default redis library.


  2. You can not. Elasticache Redis is a customized implementation of Redis and AWS blocks some of the commands.
    Config is one such command.
    The doc is here – https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/RestrictedCommands.html
    If they change it sometime in the future, the doc should get updated soon after that.

    Cheers.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search