参考链接: Nodejs中使用Redis来完成定时任务

自己在 window 7下编码实现:

1 > 首先查看redis版本: redis-server -v , 版本要求大于等于2.8

2> 开启 键空间通知redis-cli config set notify-keyspace-events Ex

 

        let subscribeClient = redis.createClient();  //订阅客户端
        let publishClient = redis.createClient();    //发布客户端

        subscribeClient.psubscribe('__keyevent@' + 0 +'__:expired',function () {
            console.log('[service] redis start');
        });
        subscribeClient.on('pmessage',function (channel,msg,expire) {
            //get  键名 then do something
            //TODO
        });

        publishClient.PSETEX('uuid', 9000 , '');//键名,过期时间,键值