×
Community Blog Create Online Game Leaderboard on Redis

Create Online Game Leaderboard on Redis

In this tutorial, we'll show you how you can create a simple gaming leaderboard with Redis on Alibaba Cloud.

You can access all the tutorial resources, including deployment script (Terraform), related source code, sample data, and instruction guidance, from the GitHub project: https://github.com/alibabacloud-howto/solution-online-leaderboard-redis

For more tutorials around Alibaba Cloud Database, please refer to: https://github.com/alibabacloud-howto/database

Project URL

https://github.com/alibabacloud-howto/solution-online-leaderboard-redis

Architecture Overview

1

Deployment

Terraform

Use terraform to provision ECS and Redis instances that used in this solution against this .tf file: https://github.com/alibabacloud-howto/solution-online-leaderboard-redis/blob/main/deployment/terraform/main.tf

For more information about how to use Terraform, please refer to this tutorial: https://www.youtube.com/watch?v=zDDFQ9C9XP8

In the file: https://github.com/alibabacloud-howto/solution-online-leaderboard-redis/blob/main/deployment/terraform/main.tf

If you do not specify the provider parameters in the environment, please set your Alibaba Cloud access key, secret key here.

provider "alicloud" {
  #   access_key = "${var.access_key}"
  #   secret_key = "${var.secret_key}"
  region = "ap-southeast-1"
}

Run Demo

Step 1: Log in to ECS & Set up Environment

  • Get the EIP of the ECS, and then logon to ECS via SSH. Please use the account root/N1cetest, the password has been predefined in Terraform script for this tutorial. If you changed the password, please use the correct password accordingly.

2
3

ssh root@<EIP_ECS>
  • Run the following command to install required utilities on the instance, including JDK and Maven:
sudo apt-get update
sudo apt-get install openjdk-8-jdk
apt install maven

Step 2: Modify & Run Application

  • Run the following command to download and untar the source code of the demo:
wget https://github.com/alibabacloud-howto/solution-online-leaderboard-redis/raw/main/source.tar.gz
tar xvf source.tar.gz && cd source
  • Vim to modify the Java code to replace the Redis access endpoint URL and password accordingly in the Step 1.

4

vim src/main/java/test/GameRankSample.java

5

  • Build the source code and package, then run the demo:
mvn clean package assembly:single -DskipTests
java -classpath target/demo-0.0.1-SNAPSHOT.jar test.GameRankSample

Running result:

6

0 0 0
Share on

ApsaraDB

459 posts | 98 followers

You may also like

Comments

ApsaraDB

459 posts | 98 followers

Related Products