Coder Social home page Coder Social logo

collabnix / basic-redis-leaderboard-demo-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redis-developer/basic-redis-leaderboard-demo-java

1.0 2.0 1.0 2.59 MB

A basic Redis Leaderboard app written in Java

Shell 0.29% HTML 6.14% Java 40.74% JavaScript 5.08% Vue 47.76%

basic-redis-leaderboard-demo-java's Introduction

Basic Redis Leaderboard Demo Java (Spring)

Show how the redis works with Java (Spring).

alt text

Overview video

Here's a short video that explains the project and how it uses Redis:

Watch the video on YouTube

Try it out

Deploy to Heroku

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

How it works?

How it works

How it works?

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

git clone 

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): copy .env.example to create .env (copy .env.example .env or cp .env.example .env). And provide the values for environment variables (if needed)

- 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 gradle (Use Gradle 6.3 or later) (on mac: https://gradle.org/install/)

Install JDK (use 8 or later version) (on mac: https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-macos.htm)

cd server
export $(cat .env | xargs)
./gradlew build
./gradlew run

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.

basic-redis-leaderboard-demo-java's People

Contributors

dougtidwell avatar rvagapov avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

alexrogalskiy

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.