redis.subscribe('EXPIRE', () => {})
notify-keyspace-events xK
to only enable expired events
CONFIG SET notify-keyspace-events xK
I've mounted redis.conf to /usr/local/etc/redis/redis.conf
and it contains notify-keyspace-events Ex
Code:
redis.set('test', 12, 'EX', 1);
console.log(await redis.get('test')); // return 12
redis.subscribe('__keyevent@0__:expire', (x, y, c, v, b) => {
console.log('zz', x, y, c, v, b);
});
The console.log
return zz null 1 undefined undefined undefined
for the first time then errors
error: Connection in subscriber mode, only subscriber commands may be used
error: Error: Connection in subscriber mode, only subscriber commands may be used
redisSubscribe = new Redis();
1) "notify-keyspace-events"
2) "xE"