Giter Site home page Giter Site logo

kareem-elsayed / basic-rate-limiting-demo-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redis-developer/basic-rate-limiting-demo-python

0.0 1.0 0.0 6.59 MB

This repo shows a basic rate limiting demo in Python and Django

Shell 3.66% Python 42.50% CSS 2.22% JavaScript 16.56% HTML 31.95% Dockerfile 3.12%

basic-rate-limiting-demo-python's Introduction

Basic Redis Rate-limiting Demo Python (Django)

Show how the redis works with Python (Django).

Try it out

Deploy to Heorku

Deploy with Vercel

Run on Google Cloud

How to run on Google Cloud

1. Click "Run on Google Cloud"

Open up the link under "Manage this application at Cloud Console"

2. Click “Edit and Deploy New Revision”

3. Click “Variables and Secrets”

Supply Redis Enterprise Cloud Endpoint URL

4. Enable HTTP/2

Ensure that you have Redis Enterprise Cloud DB created under GCP.

5. Allow all the traffic

Hence, you should be able to access Rate Limiting app


How it works?

1. How the data is stored:

  1. New responses are added key-ip:
     SETNX your_ip:PING limit_amount
     Example: SETNX 127.0.0.1:PING 10 
    more information

  2. Set a timeout on key:
    EXPIRE your_ip:PING timeout
    Example: EXPIRE 127.0.0.1:PING 1000 
    more information

2. How the data is accessed:

  1. Next responses are get bucket:
    GET your_ip:PING
    Example: GET 127.0.0.1:PING   
    
    more information

  2. Next responses are changed bucket:
    DECRBY your_ip:PING amount
    Example: DECRBY 127.0.0.1:PING 1
    more information

How to run it locally?

git clone https://github.com/redis-developer/basic-rate-limiting-demo-python.git

Run docker compose or install redis manually

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

Run backend

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

Run frontend

Static сontent runs automatically with the backend part.

basic-rate-limiting-demo-python's People

Contributors

ajeetraina avatar dougtidwell avatar oleg4520 avatar rvagapov avatar

Watchers

 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.