avatarThenusan Santhirakumar

Summary

The provided content offers an introduction to Redis, detailing its role as an in-memory NoSQL database, its performance benefits, and its use by popular platforms, along with a guide on how to download, install, and interact with Redis using various clients, including the Java-based Jedis client.

Abstract

The article "Introduction to Redis" presents Redis as an open-source, in-memory data structure store that serves as a NoSQL database and cache memory store. It emphasizes Redis's speed and performance due to its in-memory nature, which makes it a preferred choice for developers working with large datasets, as seen in its use by services like Twitter, Stack Overflow, and GitHub. The content provides a step-by-step guide for downloading and installing Redis on a Linux-based system, and introduces RDM for Redis, a GUI management console. It also covers the use of the Redis command-line interface and the Jedis client for Java, showcasing sample code for adding and retrieving key-value pairs from a Redis database. The article concludes by discussing the advantages of Redis, such as high throughput and availability, its open-source community, and the variety of data types it supports, while also acknowledging its limitations, including being single-threaded and requiring significant memory resources.

Opinions

  • The author suggests that Redis's performance and speed are primary reasons for its popularity among developers.
  • The article implies that Redis's in-memory storage and persistence options provide a balance between the need for fast access and data durability.
  • The use of Redis by well-known platforms like Twitter, Stack Overflow, and GitHub is presented as a testament to its reliability and scalability.
  • The inclusion of a download and installation guide, along with examples of using the Jedis client, indicates the author's view that these processes are straightforward and accessible to developers.
  • The mention of Redis's single-threaded nature and high memory requirements is likely intended to provide a balanced view, acknowledging that while Redis has many strengths, it also has trade-offs that users should be aware of when considering its adoption.

Redis Episode -1

Introduction to Redis

Dive into Redis

Relational databases have a long history of software development. Data is stored in tabular format in relational databases. The tabular format allows us to identify and access data concerning another section of data in the database. MySQL, SQLite, Oracle are well known relational databases. Due to lack of performance, huge Storage requirements, limited Scalability, limited availability, NoSQL databases have been introduced to use in software development. In NoSQL databases, Data isn’t organized in tabular format. There are many NoSQL databases available today. Firebase, MongoDB, Redis are well -known NoSQL databases.

Redis is an open-source (BSD Licensed) in-memory data structure store written in C language and mainly support Linux and related Operating systems. Redis can be used as a NoSQL database and Cache memory store. It is a key-value data store, unlike relational databases where data is stored in tabular format. Being in-memory allows Redis to be incredibly fast and performant. It is the main reason for many developers are interested in Redis. Redis allows persistence even though it is in-memory, high scalability and simplicity. Redis works super fast with a super huge data set like Twitter’s timeline. It is implemented in Redis. Other than that Stack overflow and Github also use Redis in their implementation as a Cache memory store.

Throughput, Data size graph in log scale

Download and installation guide of Redis is given below.

Download and Installation

  1. Users can download Redis simply from the Redis website or use the terminal of the Operating system to download the Redis. The below comments may change with version numbers (the current stable version is 6.0.9).
$ wget https://download.redis.io/releases/redis-6.0.9.tar.gz
$ tar xzf redis-6.0.9.tar.gz
$ cd redis-6.0.9
$ make

2. Go to the src folder of the Redis file and run the below comment to start the Redis Server.

$ src/redis-server

3. Users may interact with Redis by Using the built-in client and there is a GUI management console called RDM for Redis ( Download RDM).

to use the built-in Redis client, Run the following command in the Redis folder.

$ src/redis-cli

Redis clients are available for widely used programming languages such as JAVA, Python, NodeJS, PHP etc. JAVA langaRedis client is called Jedis. We may download as external jar files and add them to our projects through the Maven repository. Currently, Jedis 3.3.0 is available. To use Jedis on our project, we have to import the Jedis in our classes to create Jedis objects.

import redis.clients.jedis.Jedis;

There are many different types of constructors are available to create Jedis object according to our purpose of usage.

I list below some simple application code in JAVA using Jedis.

private static Jedis jedis;
private static Jedis database() {
    if (jedis != null)
        return jedis;
    return new Jedis("127.0.0.1", 6379);
}

Above database( ) method is called, while we use Jedis object to add key-value pair or get value for a particular key. This private method checks whether the jedis variable is null or assigned already. If it is null, then the method creates a new Jedis object with the host address and port number. If the jedis variable is not null, The method return that Jedis object. This method ensures that the method does not create unwanted many objects and keeping one instance of Jedis object (Singleton).

public void addValue(String key, String value) {
        System.out.println("Connecting to REDIS to add new key-value pair ");
        database().set(key, value);
}

Above addValue() method is called to add the key to the Redis database. As Redis stores data in key-value pairs, The above method requires two parameters key and value. The database() method is called there to get Jedis object. The set() method of Jedis object is used to add value to the specific key. The getValue() method also works as same as addValue() method. The getValue() method is used to get value for a particular key. The getValue() method is shown below.

public void getValue(String key){
        System.out.println("Connecting to REDIS to get value for a key ");
        String val= database().get(key);
        System.out.println(val);
}

The above sample Jedis codes are available at the below Github link. You can try them https://github.com/sthenusan/redis_initial

Like a coin has two sides, Redis also have advantages and disadvantages.

Advantages: high throughput, high availability, being as an open-sourced tool with a growing community, has a variety of data types, very simple to use.

Disadvantages: single-threaded, requires a huge memory, costly (huge main memory requirement).

I believe that you understand the content that I have discussed above. Thank you for taking your precious time to read this article…

Reference

  1. https://redis.io/
Redis
NoSQL
Persistence
Redis Cluster
Scalability
Recommended from ReadMedium