https://github.com/redis-developer/basic-redis-leaderboard-demo-nodejs
Basic Redis Leaderboard demo written in Nodejs
https://github.com/redis-developer/basic-redis-leaderboard-demo-nodejs
Last synced: 11 months ago
JSON representation
Basic Redis Leaderboard demo written in Nodejs
- Host: GitHub
- URL: https://github.com/redis-developer/basic-redis-leaderboard-demo-nodejs
- Owner: redis-developer
- License: mit
- Created: 2021-01-19T03:13:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-27T07:41:56.000Z (over 2 years ago)
- Last Synced: 2025-04-12T03:53:05.484Z (11 months ago)
- Language: JavaScript
- Size: 7.48 MB
- Stars: 10
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Basic Redis Leaderboard Demo NodeJS
Show how the redis works with NodeJS, Express.
## Screenshots

# Overview video
Here's a short video that explains the project and how it uses Redis:
[](https://www.youtube.com/watch?v=zzinHxdZ34I)
## Try it out
(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.

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

3. Add environment.

4. Select vpc-connector and deploy application.

Problem with unsupported flags when deploying google cloud run button
# How it works?
## 1. How the data is stored:
- The company data is stored in a hash like below:
HSET "company:AAPL" symbol "AAPL" market_cap "2600000000000" country USA
- The Ranks are stored in a ZSET.
ZADD companyLeaderboard 2600000000000 company:AAPL
## 2. How the data is accessed:
- Top 10 companies:
ZREVRANGE companyLeaderboard 0 9 WITHSCORES
- All companies:
ZREVRANGE companyLeaderboard 0 -1 WITHSCORES
- Bottom 10 companies:
ZRANGE companyLeaderboard 0 9 WITHSCORES
- Between rank 10 and 15:
ZREVRANGE companyLeaderboard 9 14 WITHSCORES
- Show ranks of AAPL, FB and TSLA:
ZSCORE companyLeaderBoard company:AAPL company:FB company:TSLA
- Adding market cap to companies:
ZINCRBY companyLeaderBoard 1000000000 "company:FB"
- Reducing market cap to companies:
ZINCRBY companyLeaderBoard -1000000000 "company:FB"
- Companies over a Trillion:
ZCOUNT companyLeaderBoard 1000000000000 +inf
- Companies between 500 billion and 1 trillion:
ZCOUNT companyLeaderBoard 500000000000 1000000000000
## How to run it locally?
#### Copy `.env.example` to create `.env`. And provide the values for environment variables
- REDIS_ENDPOINT_URI: Redis server URI
- REDIS_PASSWORD: Password to the server
#### Run frontend
```sh
cd client
yarn
yarn serve
```
#### Run backend
```sh
yarn
yarn dev
```