Show how the redis works with Python (Django).
Open up the link under "Manage this application at Cloud Console"
Supply Redis Enterprise Cloud Endpoint URL
Ensure that you have Redis Enterprise Cloud DB created under GCP.
Hence, you should be able to access Rate Limiting app
- 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
git clone https://github.com/redis-developer/basic-rate-limiting-demo-python.git
Install docker (on mac: https://docs.docker.com/docker-for-mac/install/)
docker network create global
docker-compose up -d --build
Open directory server (cd server/configuration): copy .env.example to create .env (copy .env.example .env or cp .env.example .env). And provide the values for environment variables (if needed)
- DJANGO_DEBUG: Django debug mode
- ALLOWED_HOSTS: Allowed hosts
- REDIS_URL: Redis server url
- REDIS_HOST: Redis server host
- REDIS_PORT: Redis server port
- REDIS_DB: Redis server db index
- REDIS_PASSWORD: Redis server password
Install python, pip and venv (on mac: https://installpython3.com/mac/)
Use python version: 3.8
python3 -m venv venv
source ./venv/bin/activate
pip3 install -r requirements.txt
python3 server/manage.py collectstatic
python3 server/manage.py runserver
Static сontent runs automatically with the backend part.