Giter Club home page Giter Club logo

access-limit's Introduction

GitHub tag (latest SemVer) GitHub All Releases

Access Limit - 频次控制器

本工具包可用于对资源访问频次的记录与控制,具有以下特性:

  • 资源控制粒度可自定义。
  • 频次监控类型包括:每分钟,每小时,每天三个统计单位。
  • 支持分布式环境部署。
  • 支持警告,禁用两种拦截方式。

依赖

  • redis

项目中通过maven引用方式

<dependency>
  <groupId>io.github.lix511</groupId>
  <artifactId>access-limit</artifactId>
  <version>1.0</version>
</dependency>

代码使用说明

//构造函数第二个参数:是根据需要控制的粒度起的一个名称,例如你想控制视频播放频次,那么这里传入"video"
AccessLimiter al = new AccessLimiter(jedisPool, "video");
...

//以下代码在需要进行频次控制的地方调用
try {
    //参数"userIdentify"可以是userId,username等能唯一标识用户的值
    al.inc("userIdentify");
} catch (AccessLimitException e) {
    //如果超过设定的调用频次限制,则会抛出AccessLimitException异常
    AccessLimitStats stats = e.getStats();
    //todo 可以根据得到的相关控制信息,进行后续的业务逻辑处理
} 

access-limit's People

Stargazers

itcamel avatar  avatar

Watchers

itcamel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.