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.

Download and installation guide of Redis is given below.
Download and Installation
- 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
$ make2. Go to the src folder of the Redis file and run the below comment to start the Redis Server.
$ src/redis-server3. 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-cliRedis 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





