Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Added Rate Limit Management Support in Redis #18

Merged
merged 2 commits into from
Apr 28, 2024

Conversation

JeffersonGibin
Copy link
Owner

@JeffersonGibin JeffersonGibin commented Apr 28, 2024

What has been implemented?

Support for Redis has been added, allowing rate limit management directly via Redis. New properties have been added: strategyCache and redis.

Important

  • For those using a custom cache where it is necessary to inform the cache field containing the instance of the custom cache, in addition to this field, you will need to add strategyCache: "CUSTOM". If you were using in-memory cache, don't worry, nothing has changed.

Example of Use

  • For more details, please consult the README.md.

Redis

import {  RateLimitExpress,  Redis } from "express-rate-limiter-core"; 

const redisClient = Redis.createClient({
    url: 'redis://localhost:6379'
});

redisClient.connect();

const rateLimit = RateLimitExpress({
  // This field is optional and support IN_MEMORY, REDIS and CUSTOM
  strategyCache: 'REDIS',
  
  redis: redisClient,

  policy: {
    type: "REQUEST_PER_SECONDS", // REQUEST_PER_SECONDS, REQUEST_PER_MINUTES

    periodWindow: 10,

    maxRequests: 10,
  },
});

Custom Cache

import {  RateLimitExpress } from "express-rate-limiter-core"; 

class CustomCacheExemple implements CustomCache {}

// Exemple RateLimitExpress with custom cache
const rateLimit = RateLimitExpress({
  // This field is optional and support IN_MEMORY, REDIS and CUSTOM
  strategyCache: 'CUSTOM',

  cache: new CustomCacheExemple(),

  policy: {
    type: "REQUEST_PER_SECONDS", // REQUEST_PER_SECONDS, REQUEST_PER_MINUTES

    periodWindow: 10,

    maxRequests: 10,
  },
});

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.
@JeffersonGibin JeffersonGibin merged commit 22582f0 into main Apr 28, 2024
1 check passed
JeffersonGibin added a commit that referenced this pull request Apr 28, 2024
* New Feature: Added Rate Limit Management Support in Redis (#18)
* install prettier & settings
* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0 (#19)
* Update README.md
* fix: add logic to get IP + exemple docker
JeffersonGibin added a commit that referenced this pull request Apr 28, 2024
* install prettier & settings

* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Hotfix/missing validation header x forwarded for (#20)

* New Feature: Added Rate Limit Management Support in Redis (#18)
* install prettier & settings
* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0 (#19)
* Update README.md
* fix: add logic to get IP + exemple docker
JeffersonGibin added a commit that referenced this pull request Apr 28, 2024
* install prettier & settings

* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Hotfix/missing validation header x forwarded for (#20)

* New Feature: Added Rate Limit Management Support in Redis (#18)
* install prettier & settings
* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0 (#19)
* Update README.md
* fix: add logic to get IP + exemple docker
JeffersonGibin added a commit that referenced this pull request Apr 28, 2024
* install prettier & settings

* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0

* Bump patch version to 2.0.1

* Feature/redis cache strategy implementation (#22)

* install prettier & settings

* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Hotfix/missing validation header x forwarded for (#20)

* New Feature: Added Rate Limit Management Support in Redis (#18)
* install prettier & settings
* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0 (#19)
* Update README.md
* fix: add logic to get IP + exemple docker
JeffersonGibin added a commit that referenced this pull request Apr 28, 2024
* install prettier & settings

* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0

* Bump patch version to 2.0.1

* Feature/redis cache strategy implementation (#22)

* install prettier & settings

* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Hotfix/missing validation header x forwarded for (#20)

* New Feature: Added Rate Limit Management Support in Redis (#18)
* install prettier & settings
* Add support cache redis

- New fields have been added to the ISettings interface (strategyCache, redis).
- A strategy to support storage in Redis has been implemented. Deletion is done automatically.

* Bump major version to 2.0.0 (#19)
* Update README.md
* fix: add logic to get IP + exemple docker
@JeffersonGibin JeffersonGibin mentioned this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant