{"id":21672555,"url":"https://github.com/redis-developer/basic-redis-leaderboard-demo-python","last_synced_at":"2025-04-12T03:52:41.725Z","repository":{"id":51024258,"uuid":"338044989","full_name":"redis-developer/basic-redis-leaderboard-demo-python","owner":"redis-developer","description":"A Basic Redis leaderboard demo app written in Python","archived":false,"fork":false,"pushed_at":"2023-06-27T07:42:46.000Z","size":6594,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T03:52:34.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-11T14:01:43.000Z","updated_at":"2024-11-29T13:18:17.000Z","dependencies_parsed_at":"2022-09-21T01:51:10.992Z","dependency_job_id":null,"html_url":"https://github.com/redis-developer/basic-redis-leaderboard-demo-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/basic-redis-leaderboard-demo-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514209,"owners_count":21116899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T13:30:02.807Z","updated_at":"2025-04-12T03:52:41.704Z","avatar_url":"https://github.com/redis-developer.png","language":"Python","readme":"\u003cdiv style=\"position: absolute; top: 0px; right: 0px;\"\u003e\n    \u003cimg width=\"200\" height=\"200\" src=\"https://redislabs.com/wp-content/uploads/2020/12/RedisLabs_Illustration_HomepageHero_v4.svg\"\u003e\n\u003c/div\u003e\n\n\u003cdiv style=\"height: 150px\"\u003e\u003c/div\u003e\n\n# Basic Redis Leaderboard Demo Python (Django)\n\nShow how the redis works with Python (Django).\n\n![How it works](https://github.com/redis-developer/basic-redis-leaderboard-demo-python/raw/master/docs/screenshot001.png)\n\n# Overview video\n\nHere's a short video that explains the project and how it uses Redis:\n\n[![Watch the video on YouTube](https://github.com/redis-developer/basic-redis-leaderboard-demo-python/raw/master/docs/YTThumbnail.png)](https://www.youtube.com/watch?v=zzinHxdZ34I)\n\n## Try it out\n\n\u003cp\u003e\n    \u003ca href=\"https://heroku.com/deploy\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://www.herokucdn.com/deploy/button.svg\" alt=\"Deploy to Heorku\" width=\"200px\"/\u003e\n    \u003ca\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n    \u003ca href=\"https://vercel.com/new/git/external?repository-url=https://github.com/redis-developer/basic-redis-leaderboard-demo-python/tree/master\u0026env=REDIS_HOST,REDIS_PORT,REDIS_PASSWORD\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://vercel.com/button\" alt=\"Deploy with Vercel\" width=\"200px\" height=\"50px\"/\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n    \u003ca href=\"https://deploy.cloud.run/?dir=google-cloud-run\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://deploy.cloud.run/button.svg\" alt=\"Run on Google Cloud\" width=\"200px\"/\u003e\n    \u003c/a\u003e\n    (See notes: How to run on Google Cloud)\n\u003c/p\u003e\n\n\n## How to run on Google Cloud\n\n\u003cp\u003e\n    If you don't have redis yet, plug it in  (https://spring-gcp.saturnism.me/app-dev/cloud-services/cache/memorystore-redis).\n    After successful deployment, you need to manually enable the vpc connector as shown in the pictures:\n\u003c/p\u003e\n\n1. Open link google cloud console.\n\n![1 step](https://github.com/redis-developer/basic-redis-leaderboard-demo-python/raw/master/docs/1.png)\n\n2. Click \"Edit and deploy new revision\" button.\n\n![2 step](https://github.com/redis-developer/basic-redis-leaderboard-demo-python/raw/master/docs/2.png)\n\n3. Add environment.\n\n![3 step](https://github.com/redis-developer/basic-redis-leaderboard-demo-python/raw/master/docs/3.png)\n\n4.  Select vpc-connector and deploy application.\n\n![4  step](https://github.com/redis-developer/basic-redis-leaderboard-demo-python/raw/master/docs/4.png)\n\n\u003ca href=\"https://github.com/GoogleCloudPlatform/cloud-run-button/issues/108#issuecomment-554572173\"\u003e\nProblem with unsupported flags when deploying google cloud run button\n\u003c/a\u003e\n\n\n# How it works?\n## 1. How the data is stored:\n\u003col\u003e\n    \u003cli\u003eThe AAPL's details - market cap of 2,6 triillions and USA origin - are stored in a hash like below:\n      \u003cpre\u003e \u003ca href=\"https://redis.io/commands/hset\"\u003eHSET\u003c/a\u003e \"company:AAPL\" symbol \"AAPL\" market_cap \"2600000000000\" country USA\u003c/pre\u003e\n     \u003c/li\u003e\n    \u003cli\u003eThe Ranks of AAPL of 2,6 trillions are stored in a \u003ca href=\"https://redislabs.com/ebook/part-1-getting-started/chapter-1-getting-to-know-redis/1-2-what-redis-data-structures-look-like/1-2-5-sorted-sets-in-redis/\"\u003eZSET\u003c/a\u003e. \n      \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zadd\"\u003eZADD\u003c/a\u003e  companyLeaderboard 2600000000000 company:AAPL\u003c/pre\u003e\n    \u003c/li\u003e\n\u003c/ol\u003e\n\n\u003cbr/\u003e\n\n## 2. How the data is accessed:\n\u003col\u003e\n    \u003cli\u003eTop 10 companies: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zrevrange\"\u003eZREVRANGE\u003c/a\u003e companyLeaderboard 0 9 WITHSCORES\u003c/pre\u003e \u003c/li\u003e\n    \u003cli\u003eAll companies: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zrevrange\"\u003eZREVRANGE\u003c/a\u003e companyLeaderboard 0 -1 WITHSCORES\u003c/pre\u003e \u003c/li\u003e\n    \u003cli\u003eBottom 10 companies: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zrange\"\u003eZRANGE\u003c/a\u003e companyLeaderboard 0 9 WITHSCORES\u003c/pre\u003e\u003c/li\u003e\n    \u003cli\u003eBetween rank 10 and 15: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zrevrange\"\u003eZREVRANGE\u003c/a\u003e companyLeaderboard 9 14 WITHSCORES\u003c/pre\u003e\u003c/li\u003e\n    \u003cli\u003eShow ranks of AAPL, FB and TSLA: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zrevrange\"\u003eZREVRANGE\u003c/a\u003e  companyLeaderBoard company:AAPL company:FB company:TSLA\u003c/pre\u003e \u003c/li\u003e\n    \u003c!-- \u003cli\u003ePagination: Show 1st 10 companies: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zscan\"\u003eZSCAN\u003c/a\u003e 0 companyLeaderBoard COUNT 10 7.Pagination: Show next 10 companies: ZSCAN \u0026lt;return value from the 1st 10 companies\u0026gt; companyLeaderBoard COUNT 10 \u003c/li\u003e --\u003e\n    \u003cli\u003eAdding 1 billion to market cap of FB company: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zincrby\"\u003eZINCRBY\u003c/a\u003e companyLeaderBoard 1000000000 \"company:FB\"\u003c/pre\u003e\u003c/li\u003e\n    \u003cli\u003eReducing 1 billion of market cap of FB company: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zincrby\"\u003eZINCRBY\u003c/a\u003e companyLeaderBoard -1000000000 \"company:FB\"\u003c/pre\u003e\u003c/li\u003e\n    \u003cli\u003eCompanies between 500 billion and 1 trillion: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zcount\"\u003eZCOUNT\u003c/a\u003e companyLeaderBoard 500000000000 1000000000000\u003c/pre\u003e\u003c/li\u003e\n    \u003cli\u003eCompanies over a Trillion: \u003cpre\u003e\u003ca href=\"https://redis.io/commands/zcount\"\u003eZCOUNT\u003c/a\u003e companyLeaderBoard 1000000000000 +inf\u003c/pre\u003e \u003c/li\u003e\n\u003c/ol\u003e\n\n\n## How to run it locally?\n\n### Development\n\n```\ngit clone https://github.com/redis-developer/basic-redis-leaderboard-demo-python.git\n```\n\n### Run docker compose or install redis manually\n\nInstall docker (on mac: https://docs.docker.com/docker-for-mac/install/)\n\n```sh\ndocker network create global\ndocker-compose up -d --build\n```\n\n#### 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)\n    - DJANGO_DEBUG: Django debug mode\n    - DJANGO_ALLOWED_HOSTS: Allowed hosts\n    - REDIS_URL: Redis server url\n    - REDIS_HOST: Redis server host\n    - REDIS_PORT: Redis server port\n    - REDIS_DB: Redis server db index\n    - REDIS_PASSWORD: Redis server password\n\n#### Run backend\n\nInstall python, pip and venv (on mac: https://installpython3.com/mac/)\n\nUse python version: 3.9.1\n\n``` sh\npython3 -m venv venv\nsource ./venv/bin/activate\npip3 install -r requirements.txt\npython3 server/manage.py collectstatic\npython3 server/manage.py runserver\n```\n\n#### Run frontend\n\nStatic сontent runs automatically with the backend part. In case you need to run it separately, please see README in the [client](client) folder.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fbasic-redis-leaderboard-demo-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fbasic-redis-leaderboard-demo-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fbasic-redis-leaderboard-demo-python/lists"}