Show how the redis works with Python (Django).

Overview

Redis Leaderboard Python (Django)

Show how the redis works with Python (Django).

How it works

Try it out deploying on Heroku

Deploy to Heorku

Deploy with Vercel

Run on Google Cloud (See notes: How to run on Google Cloud)

How to run on Google Cloud

If you don't have redis yet, plug it in (https://spring-gcp.saturnism.me/app-dev/cloud-services/cache/memorystore-redis). After successful deployment, you need to manually enable the vpc connector as shown in the pictures:

  1. Open link google cloud console.

1 step

  1. Click "Edit and deploy new revision" button.

2 step

  1. Add environment.

3 step

  1. Select vpc-connector and deploy application.

4  step

Problem with unsupported flags when deploying google cloud run button

1. How the data is stored

  1. The AAPL's details - market cap of 2,6 triillions and USA origin - are stored in a hash like below:
     HSET "company:AAPL" symbol "AAPL" market_cap "2600000000000" country USA
  2. The Ranks of AAPL of 2,6 trillions are stored in a ZSET.
    ZADD  companyLeaderboard 2600000000000 company:AAPL

2. How the data is accessed

  1. Top 10 companies:
    ZREVRANGE companyLeaderboard 0 9 WITHSCORES
  2. All companies:
    ZREVRANGE companyLeaderboard 0 -1 WITHSCORES
  3. Bottom 10 companies:
    ZRANGE companyLeaderboard 0 9 WITHSCORES
  4. Between rank 10 and 15:
    ZREVRANGE companyLeaderboard 9 14 WITHSCORES
  5. Show ranks of AAPL, FB and TSLA:
    ZREVRANGE  companyLeaderBoard company:AAPL company:FB company:TSLA
  6. Adding 1 billion to market cap of FB company:
    ZINCRBY companyLeaderBoard 1000000000 "company:FB"
  7. Reducing 1 billion of market cap of FB company:
    ZINCRBY companyLeaderBoard -1000000000 "company:FB"
  8. Companies between 500 billion and 1 trillion:
    ZCOUNT companyLeaderBoard 500000000000 1000000000000
  9. Companies over a Trillion:
    ZCOUNT companyLeaderBoard 1000000000000 +inf

How to run it locally?

Development local env

git clone https://github.com/redis-developer/basic-redis-leaderboard-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
  • DJANGO_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.9

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. In case you need to run it separately, please see README in the client folder.

Owner
Tom Xu
Software Engineer, AI/ML SaaS Advocate, Scientific Simulations and Optimizations.
Tom Xu
django-reversion is an extension to the Django web framework that provides version control for model instances.

django-reversion django-reversion is an extension to the Django web framework that provides version control for model instances. Requirements Python 3

Dave Hall 2.8k Jan 02, 2023
Basic Form Web Development using Python, Django and CSS

thebookrain Basic Form Web Development using Python, Django and CSS This is a basic project that contains two forms - borrow and donate. The form data

Ananya Dhulipala 1 Nov 27, 2021
Strawberry-django-plus - Enhanced Strawberry GraphQL integration with Django

strawberry-django-plus Enhanced Strawberry integration with Django. Built on top

BLB Ventures 138 Dec 28, 2022
A Django backed for PostgreSQL using Psycopg 3

A Django backend for PostgreSQL using Psycopg 2 The backend passes the entire Django test suite, but it needs a few modifications to Django and to i

Daniele Varrazzo 42 Dec 16, 2022
Simple reproduction of connection leak with celery/django/gevent

Redis connection leak with celery/django/gevent Reproduces celery issue at https://github.com/celery/celery/issues/6819 using gevented django web serv

2 Apr 03, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

10.1k Jan 08, 2023
A helper for organizing Django project settings by relying on well established programming patterns.

django-configurations django-configurations eases Django project configuration by relying on the composability of Python classes. It extends the notio

Jazzband 953 Dec 29, 2022
An API was build with Django to store and retrieve information about various musical instruments.

The project is meant to be a starting point, an experimentation or a basic example of a way to develop an API with Django. It is an exercise on using Django and various python technologies and design

Kostas Ziovas 2 Dec 25, 2021
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 01, 2022
Resolve form field arguments dynamically when a form is instantiated

django-forms-dynamic Resolve form field arguments dynamically when a form is instantiated, not when it's declared. Tested against Django 2.2, 3.2 and

DabApps 108 Jan 03, 2023
demo project for django channels tutorial

django_channels_chat_official_tutorial demo project for django channels tutorial code from tutorial page: https://channels.readthedocs.io/en/stable/tu

lightsong 1 Oct 22, 2021
Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and css.

Chat app (Full Stack Frameworks with Django Project) Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and

1 Jan 19, 2022
Custom Django field for using enumerations of named constants

django-enumfield Provides an enumeration Django model field (using IntegerField) with reusable enums and transition validation. Installation Currently

5 Monkeys 195 Dec 20, 2022
Django admin CKEditor integration.

Django CKEditor NOTICE: django-ckeditor 5 has backward incompatible code moves against 4.5.1. File upload support has been moved to ckeditor_uploader.

2.2k Jan 02, 2023
A standalone package to scrape financial data from listed Vietnamese companies via Vietstock

Scrape Financial Data of Vietnamese Listed Companies - Version 2 A standalone package to scrape financial data from listed Vietnamese companies via Vi

Viet Anh (Vincent) Tran 45 Nov 16, 2022
Django Audit is a simple Django app that tracks and logs requests to your application.

django-audit Django Audit is a simple Django app that tracks and logs requests to your application. Quick Start Install django-audit pip install dj-au

Oluwafemi Tairu 6 Dec 01, 2022
An insecure login and registration website with Django.

An insecure login and registration website with Django.

Luis Quiñones Requelme 1 Dec 05, 2021
Vehicle registration using Python, Django and SQlite3

PythonCrud Cadastro de veículos utilizando Python, Django e SQlite3 Para acessar o deploy no Heroku:

Jorge Thiago 4 May 20, 2022
🏭 An easy-to-use implementation of Creation Methods for Django, backed by Faker.

Django-fakery An easy-to-use implementation of Creation Methods (aka Object Factory) for Django, backed by Faker. django_fakery will try to guess the

Flavio Curella 93 Oct 12, 2022
Getdp-project - A Django-built web app that generates a personalized banner of events to come

getdp-project https://get-my-dp.herokuapp.com/ A Django-built web app that gener

CODE 4 Aug 01, 2022