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