Start a Project

Getting started with Redis

Introduction

 

Redis is a NoSQL or non-relational, advanced key-value store and in-memory database server. It’s open source with BSD Licensing.

Redis is written in C. And as it supports wide range of Data Structures, it’s also known as Data Structure server. The supported data types include strings, lists, hashes, sets & sorted sets.

Redis supports pipelining which means the client can send multiple requests to the server without having to wait for the replies at all, and finally reads the replies in a single step.

Since Redis is NoSQL, there are no tables & no database-defined.

 

Features

 

Above features make Redis a viable candidate for Caching solution.

But there can be limitations as mentioned below.

 

 

Supported Data Types

 

   Source:- https://redislabs.com

 

 

Backup Policy

 

Redis offers two ways to write/backup data to persistent storage.

Restoring from Snapshot is really fast. In case the DB crashes before the next Snapshot is made, you can only restore what last successful snapshot has saved. So, the changes in data after the last backup cannot be restored.

Restoring from AOF can be a time intensive process as every single write query will be executed. You may have queries which took longer time so they would cause more delay. Redis doesn’t write queries to disk straightaway. Rather it flushes the queries/data to buffers and then it’s the responsibility of OS to write them to disk.

 

 

How Redis compares with other databases

 

Source:- https://redislabs.com

 

 

Setup

 

Install the Redis-server using below command.

Redis-Cli is a command line redis client interface used to connect to local/remote redis-server.

Type “redis-cli” on terminal to start the client interface.

By default it connects to local redis-server on default port(6379). These default values can be changed by using command line options.

Redis-cli lets you manage server and its configuration.

Some examples:-

Above we map the key “name” to value “myfirstkeypair”

Above we added values to set “myfirstset”.

Notice the return integer. Integer 1 means new value added to SET and int 0 means value already present.

Similarly many other operations can be peformed.

Run “redis-benchmark” to benchmark your redis installation, it performs 100000 operations on different data types.

 

 

APIs Support

 

Redis has a great support for APIs. Check https://redis.io/clients for available options.

Now, we will check how Redis DB can be managed using Python API.

We need install Python library “redis” first. We are using Python3.

Note:- Use apt install python3-pip to install pip3 if needed.

Below code snippet creates a set & then deletes the set.

The output of file is:-

As the output shows, five values(numbered from 0 to 4) were successfully added.

 

In the next blog, we will see how Redis can be used for Session management.

 

Thank you for Reading this!! Hope it helps.

Exit mobile version