node.jsamazon-web-servicesredisamazon-elasticache

How do I run the config command on aws elasticache (redis)


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'

Solution

  • 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.