Skip to content

redis-developer/redis-racer

Repository files navigation

This is a game backend starter project creating real-time leaderboards using:

Setup Game Backend with Local Redis

Copy and edit the .env file:

cp .env.example .env

Your .env file should contain the connection string you copied from Redis Cloud.

Your .env.docker file will look similar to .env, but should use the appropriate docker internal URLs. Here is an example:

REDIS_URL="redis://redis:6379"

Next, spin up docker containers:

docker compose up -d

RestAPI Routes

You should have a server running on http://localhost:<port> where the port is set in your .env file (default is 3000). You can test the following routes:

  1. POST http://localhost:<port>/api/leaderboard - Add new entry to leaderboard sorted set, requires content body:

    {
       "key": <leaderboard_key>,
       "score": <score>,
       "member": <initials>
    }
    
  2. GET http://localhost:<port>/api/leaderboard/<leaderboard_key>?count=<number_of_entries> - Get the top scores and the corresponding initials.

Run Only Game Backend Locally

To run the development server outside of docker:

npm install
# then
npm run dev

Connecting to Redis Cloud

If you don't yet have a database setup in Redis Cloud get started here for free.

To connect to a Redis Cloud database, log into the console and find the following:

  1. The public endpoint (looks like redis-#####.c###.us-east-1-#.ec2.redns.redis-cloud.com:#####)
  2. Your username (default is the default username, otherwise find the one you setup)
  3. Your password (either setup through Data Access Control, or available in the Security section of the database page).

Combine the above values into a connection string and put it in your .env and .env.docker accordingly. It should look something like the following:

REDIS_URL="redis://default:<password>@redis-#####.c###.us-west-2-#.ec2.redns.redis-cloud.com:#####"

Learn more

To learn more about Redis, take a look at the following resources:

About

Redis Racer is a UE5 minigame that demonstrates a real-time leaderboard using Redis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published