zoukankan      html  css  js  c++  java
  • 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)
    })
  • 相关阅读:
    boost库:函数对象
    boost库:智能指针
    linux 查看和修改文件时间
    linux正则表达式
    UVA
    UVA
    UVA
    UVA
    UVA
    对JavaScript的认识?
  • 原文地址:https://www.cnblogs.com/qiyc/p/11780639.html
Copyright © 2011-2022 走看看