This application demonstrates rate limiting using Redis and Spring.
(See notes: How to run on Google Cloud)
- Open link google cloud console.
- Click "Edit and deploy new revision" button.
- Add environment.
- Select vpc-connector and deploy application.
- New responses are added key-ip:
SETNX your_ip:PING limit_amount Example: SETNX 127.0.0.1:PING 10
more information
- Set a timeout on key:
EXPIRE your_ip:PING timeout Example: EXPIRE 127.0.0.1:PING 1000
more information
- Next responses are get bucket:
GET your_ip:PING Example: GET 127.0.0.1:PING
more information
- Next responses are changed bucket:
DECRBY your_ip:PING amount Example: DECRBY 127.0.0.1:PING 1
more information
Open the files server/.env.example to see the available environment variables. You may set these variables when you start the application.
- REDIS_URL: Redis server url
- REDIS_HOST: Redis server host
- REDIS_PORT: Redis server port
- REDIS_PASSWORD: Redis server password
-
Install gradle (Use Gradle 6.3 or later) (on mac: https://gradle.org/install/)
-
Install JDK (use 8 or later version) (on mac: https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-macos.htm)
-
Set any relevant environment variables (if not connecting to Redis on localhost:6379). For example:
$ REDIS_PORT=6379
- From the root directory of the project, run the following commands:
cd server
./gradlew build
./gradlew run
- Point your browser to
localhost:5000
.