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"
1) "notify-keyspace-events"
2) "xK"
zz null 1 undefined undefined undefined
redis2.subscribe('__keyevent@0__:expired', (x, y, c, v, b) => {
console.log('zz', x, y, c, v, b);
});
1550539085.729667 [0 192.168.0.3:56496] "info"
1550539085.750826 [0 192.168.0.3:56498] "info"
1550539085.751758 [0 192.168.0.3:56498] "set" "test" "12" "EX" "1"
1550539085.751925 [0 192.168.0.3:56498] "set" "test" "12" "EX" "2"
1550539085.752053 [0 192.168.0.3:56498] "subscribe" "__keyevent@0__:expired"
5.0.0