Redis Cluster Creation Automation

Mrigank Anand
Tech @ Trell
Published in
5 min readOct 9, 2021

Redis is an open-source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster. — Redis official website

Introduction

It’s been more than one month into Trell, and I have been enjoying the project assigned to me. We are using HyperLogLogs datatype provided by Redis to monitor the daily video watch count of users. So, I have been exploring Redis Cluster for some time. Redis Cluster creation becomes a repetitive process with minor tweaks. So, I was motivated to create a script to automate the process and make it easy for my new people to start Redis Cluster hassle-free.

Redis Cluster Architecture

Where do we use Redis in our ecosystem?

It is being used in the Trell Cash microservice and many other places. Trell cash is a new feature in which users will be rewarded coins for completing milestones(like watching videos, verifying details, and many more) that can be redeemed in Trell Shop.

Trell Cash Screen

Milestones are very simple and easy to complete in Trell Cash

  • Sign up and verifying basic details will give you 70 Trell Coins.
  • Inviting 5 friends who signup to the platform will give 100 Trell Coins.
  • Watching 25 videos regularly for n days straight on our platform, you’ll earn a whopping 500 Trell Coins.

Watching videos milestone alone stands up for 500 out of 670 coins you can earn. That is where Redis comes to the show to make it all possible.

When a user watches videos on Trell Application for more than 10 seconds, the video will be eligible to count in the streak. It will send a request to the content tracking API. And, the video watch count for the user against today’s key gets updated in Redis. When a user watches videos, a streak popup will come up, which initially sends a request to Trell cash micro-service where the user streak gets computed from the watch history of the user (which gets stored in MYSQL) and, today’s watch video count that is being fetched from Redis, if the streak is complete, their coins get updated in Trell Shop, and, their wallet gets synced with the new balance and streak history is sent to the user that is shown in the popup.

After receiving Trell Cash

Redis Features

  1. Redis Sentinel is a stand-alone distributed system that helps developers calibrate their instances to be highly available for clients. Sentinel uses a series of monitoring processes, notifications, and automatic failovers to inform users when there is something wrong with master and slave instances, while automatically reconfiguring new connections for applications when necessary.
  2. Redis Cluster is a distributed implementation of Redis that automatically splits datasets among multiple nodes. This supports higher performance and scalability of database deployments while ensuring continuous operations if node subsets are unable to communicate with the rest of the cluster.
  3. Redis Pub/Sub — As Redis supports the use of publish and subscribe commands, users can design high-performance chat and messaging services across all their applications and services. This includes the ability to use list data structures to run atomic operations and blocking capabilities.
  4. Redis Persistence — Redis uses persistent disk storage designed to survive process outages and network bottlenecks. Redis can persist datasets by taking regular snapshots of data and appending them with changes as they become available. Redis can then be configured to generate these database backups on-demand or at automatic intervals to ensure database durability and integrity.

Use Cases Redis

  • Monitoring
  • Location-based applications
  • Caching for databases
  • Real Time Analytics

What does the Script do?

The script creates a cluster-configuration directory. Inside that creates a directory for various ports on which Redis-server needs to get started to form a Redis Cluster. In the following steps configuration file for the Redis server is created. Then necessary permissions are given to the files that contain a command to start the Redis server on different ports. After all, the Redis servers get started on the required ports. Redis Cluster is created using all the given Redis Servers. Redis Cluster is up and running.

Starting Redis Cluster in your machine in one go🤖

I have created a bash script available on Github which makes it super easy to start Redis in cluster mode in Mac and Linux machines.

Prerequisites

The stable version of Redis should be installed in your system. If not installed download and install it from here.

Step 1 :

Step 2 :

Step 3 :

If on a Mac execute the command given below

If on a Linux machine execute this command

References and Links🔗

--

--

Mrigank Anand
Tech @ Trell

GSoC 2022, 2021 @ OWASP, Ex SDE Intern Morphle Labs, Eugenie.ai, BharatPe, Trell