You are on page 1of 10

Redis DB

Agenda
 Redis DB Overview
 Merits and Demerits of Redis
 Difference with Cassandra
 Installation Steps
 Most useful Redis command
 Q &A
Overview
Redis is an open-source, advanced key-value store and an apt solution for
building high-performance, scalable web applications. Redis is written in
ANSI C

Redis has three main peculiarities that set it apart.


Its database is entirely in the memory, using the disk only for persistence.
It has a relatively rich set of data types when compared to many key-value
data stores.
It can replicate data to any number of slaves.
Advantages

• Redis is an open-source (BSD licensed)


• Exceptionally fast
• Supports rich data types
• Operations are atomic
• Multi-utility tool
• Supports master-slave asynchronous and synchronous replication
Disadvantages
• When using master-slave cluster, If the Master becomes down then all
slave clusters are very much prone to go down.
• The whole dataset always resides in RAM. It can cause performance
degradation if the correct implementation is not in place.
• There is no easy way to run something like SELECT COUNT(*) FROM
REDIS WHERE KEY LIKE '*key*'
Differences
Redis DB Cassandra DB

• It uses a key-value store as a primary database and •  It uses a wide-column store as a primary database
that helps the tool to be more dynamic and handle model, making it easy to store huge databases. The
varying datasets. It is also used as a message wide-column store acts as a two-dimensional key-
broker process, and queuing process. value store as the record keys are not fixed in this
model.

• It is much faster than Cassandra, but it gets slower • It is more focussed on giving you stability, and
if you use it for huge data sets and is ideally suited hence like SQL, you can store huge data sets. But,
for rapidly changing datasets it is slower in speed than that of Redis.

• It works on C programming. It is also schema-free, • It works on java programming, it is schema-free,


and it uses the telnet protocol for API. and it uses thrift protocol for API fetching.

• It is used more in session caching, queuing, • It is more useful when you have distributed, linearly
counting, publish-subscribe pattern, and in full-page scalable, write-oriented, and democratic peer to
caching. It is more useful when you have in-memory peer database or data structure
data storage, vertically scalable database
Steps to install redis on
Centos

• sudo yum install epel-release sudo yum update


• sudo yum install redis
• sudo systemctl start redis

Check if redis is working or not :


• redis-cli
• This will open a redis prompt >> redis 127.0.0.1:6379>
• So server is installed successfully
Useful Redis command
To connect to redis server :
./redis-cli -h 10.xx.xx.xx -p <<port_no>>
AUTH <<Password>>
To select one DB :
SELECT <<DB Number>> (exp: SELECT 1, SELECT 2)
To Insert new Key in DB :            
SET <<KEY_NAME>> redis
To Delete key from DB :
DEL <<KEY_NAME>>
To check whether key  exists or not :
EXISTS <<KEY_NAME>>
Useful Redis command
To get a list of all the keys available in Redis :
KEYS *
To get the remaining time of the key expiry in seconds :
TTL <<KEY_NAME>>
To set the expiry of a key in seconds :
Expire <<KEY_NAME>> <<TIME_IN_SECONDS>>
To get the data type of the key :
TYPE <<KEY_NAME>>
To get the value stored in the key :
GET <<KEY_NAME>>
Thank You

You might also like