nodejs限制IP一段时间内的访问次数


const Redis = require('ioredis');
const {getmac)= require(' getmac');
getmac();//获取mac地址
const cache = new Redis({
    port: 6300, // Redis port
    host: "192.100.50.256", // Redis host
    password: "123"
});
cache.get('eggsy').then(data => {
    console.log(15, data)
    if (data > 5) {
        throw new Error('big than 5');
    }
    if (!data) {
        cache.set('eggsy', 1, 'EX', 60);//设置60秒内访问次数大于5次,报错
    } else {
        cache.incr('eggsy');
    }

}).catch(err => {
    console.log(err)
})


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM