Redis interview questions For Freshers & Experienced

  • Question 1) What is Redis?
  • Question 2) Enlist major applications of Redis?
  • Question 3) List some popular companies using Redis?
  • Question 4) What is Redis-cli?
  • Question 5) Enlist major Redis commands?
  • Question 6) List some advantages of using Redis?
  • Question 7) What is use of MGET in Redis?
  • Question 8) How to get all keys in Redis cli?
  • Question 9) How to list all databases in Redis?
  • Question 10) Name the PHP module used with Redis?
  • Question 11) How to remove keys in Redis?
  • Question 12) What Redis HDEL do?
  • Question 13) How to delete all the cache using pRedis in php?
  • Sharad Jaiswal
  • 28th Dec, 2019

Redis interview questions
Updated ON

28th Dec, 2019

No. of Questions


Posted In



Sharad Jaiswal

What is Redis?

Redis or Remote Dictionary Server happens to be an open-source and an in-memory data construction project executing a dispersed, in-memory key-value database along with discretionary durability. It allows various kinds of conceptual data structures like lists, maps, strings, spatial indexes, streams, Hyper Loglogs, bitmaps, sorted sets, sets, and streams. Redis offers a data model which is extremely unlikely for an RDBMS or relational database management system, it is also considered a cache and a store along with its being a system.

The Redis execution makes extreme utilization of the fork system call, to replicate the procedure possessing the data, while the parent procedure continues to obey clients, and the child procedure makes a replication of the data on the disks.

Key Features of Redis

Below are few major features of Redis

In Memory Data Store

Open source technology

Flexible data structures

High availability and scalability

Easy Extensible


Supports Transactions

Automatic failover

Data replication

Q1. What is Redis?

An open-source in-memory data structure store that is can be used as a Database. It stores data in key-value format. Redis supports a wide range of data structures like strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes

Q2. Enlist major applications of Redis?

Various applications of Redis.

  • Used as Application Cache.
  • Used as a database.
  • Used message broker.
  • For creating Leaderboards.
  • Storing Multi-Tenant Metrics

Q3. List some popular companies using Redis?

Below is the list of some popular companies who are using Redis:

  • Twitter
  • GitHub
  • Weibo
  • Pinterest
  • Snapchat
  • Craigslist
  • StackOverflow
  • Flickr

Q4. What is Redis-cli?

redis-cli is command-line interface for Redis that allows sending commands to the Redis server directly from the terminal.

Q5. Enlist major Redis commands?

Redis is mainly used by the system admins, and some of the major commands in Redis are,

  • Redis-CLI – to connect to Redis.
  • INFO – to get server statistics
  • CONFIG GET * - to change runtime configuration
  • SELECT “database number” - to select the database by its number
  • FLUSHDB – to drop the currently selected database and its keys
  • FLUSHALL – to drop all the database and its keys
  • BGSAVE – to do a database backups
  • CLIENT LIST – to list all the connections with the database
  • MONITOR – to track all the network traffic

Q6. List some advantages of using Redis?

Some of the significant advantages of using Redis are the following,

  • Redis uses its hashing algorithm called Redis hashing to store the user details as key-value pairs.
  • Insertion of the mass volume of data into the Redis cache is easy.
  • Data replication in Redis is asynchronous (i.e.), when a master node updates, all the slave node gets updated asynchronously.
  • Since Redis offers data replication, it can withstand failures more effectively and offer its service.
  • Redis commands can be executed as a bunch of queues instead of one at a time .
  • The memory required to install Redis us small, so it can be easily installed on arm devices or a raspberry pi.
  • You can store huge data of key-value pairs in Redis as big as 512 MB of data.
  • Redis offers API in programming languages like c, python, java, and Javascript. So, development is made easy in Redis.
  • You can develop a messaging system easily using Redis as it offers a pub/sub messaging mechanism.
  • You can develop a messaging system easily using Redis as it offers pub/sub messaging mechanism.
  • Redis offers a rich set of data types for key-value data stores.
  • Some other advantages of using Redis is its exceptionally fast, atomic operations, and persistent database memory.

Q7. What is use of MGET in Redis?

MGET is a command in Redis that returns the value of the key. You pass the name of the key along with the MGET command, and the value gets returned as an array. MGET returns nil for keys that don’t exist or keys that don’t have any value.

> MGET keyname 
> SET key “keyValue” 
> MGET key 
1) “keyValue” 

Q8. How to get all keys in Redis cli?

KEYS command returns all the available keys in the database. The time complexity for this command is 0(n) where n is the number of available keys. It is fairly high so it shouldn’t be used only in the development time.

KEYS * // this command returns all the keys

KEYS *pattern* //returns all the keys that has the related pattern as the word “pattern”


>MSET keyName keyValue  
> MSET Var Val 
> KEYS * 
1) keyValue 
2) Val 
> KEYS *key?* 
1) keyValue 

Q9. How to list all databases in Redis?

To get a list of all the database connection (16 maximum database connection can be done by default) in redis, do the following command.

$ redis-cli INFO | grep db 

The above command returns the output like the following,


Note: the command only works on redis command line interface.

Q10. Name the PHP module used with Redis?

In order to use PHP with Redis, you need to install PHP Redis client or module. The PHP module is “Phpredis”. To download the module, use the pecl repository. After downloading the module, you can use Redis in PHP in the following way.

$redis = new Redis(); //creates a new Redis object to be used in PHP 
//Connecting to Redis 
$redis->connect('hostname', port);  

You can create a Redis database connection in PHP and do your database operation in PHP using the Phpredis module.

Q11. How to remove keys in Redis?

To delete all the database keys at once, do the following command.

$redis-cli FLUSHALL 

It deletes all the caches, database, and its keys. The time complexity is 0(n) where n is the number of keys.

$redis-cli –n  FLUSHDB

It deletes all the keys of the database that is mentioned in the command. It also has a time complexity of 0(n).

Q12. What Redis HDEL do?

This command is used to remove the fields from the hash that is specified and stored at the key. If the key is not there, then the command returns null (0) or 1 if it is present. If the field is not there then the command is just ignored. The time complexity is 0(n) where n is the number of fields to be removed.

HDEL KEY_NAME FIELD1.. FIELDN // command syntax

>HDEL hashName field1 //command example 
> 1 //returns 1 so, the field1 is removed 
> HDEL hashName field2 
>0 //returns 0 so, the field2 is not there

Q13. How to delete all the cache using pRedis in php?

Redis is one of the powerful PHP Redis clients that enables the user to work with Redis in PHP. To delete all the cache using pRedis in PHP, use the following command.


This command is the Redis equivalent of FLUSHALL that deletes all the cache of the database connected to the Redis.

Q14. How to create new database in Redis?

A single instance of a Redis supports 16 databases indexed from 0 to 15. By default, the Redis used database numbered 0 to work but you can change it at any time. To support more database, you configure it at redis.conf file.

To select a database, use the following command.

>select 2 //select database indexed 2 

After selecting the database, you can do the database operation like storing, retrieving, deleting, etc. Each database has a unique key and it can be moved between the database.

Q15. Which commnad is used to count keys in Redis?

DBSIZE command in Redis is used to return the number of keys in the currently selected database. It returns the number of keys as an integer value.

INFO command returns all the statistics about the database that is connected to the Redis. Here the information like the number of keys is displayed.

About Author :

  • Author of Redis interview questions

    Sharad Jaiswal

    Sharad Jaiswal is Sr. Web Developer from Noida area. He have rich experience in PHP, Angular Js, React, javascript and Node .If you any query or project on these programming you can drop your enquiry in comment section.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.