Top 40 Redis Interview Questions And Answers

 

1) What is Redis?

Redis is an open source, advanced key-value store. It is often referred to as a data structure server, since the keys can contain strings, hashes, lists, sets and sorted sets. Redis is use in building high performance, scalable web applications.


2) Redis is written in which language?

Redis is written in C language.


3) What are the key features of Redis?

Following are the key features of Redis:

● Redis holds its database entirely in the memory, using the disk only for persistence which makes it much faster.
● Redis has a relatively rich set of data types when compared to many key-value data stores.
● Redis can easily replicate data to any number of slaves.


4) What are the advantages of Redis?

Following are the advantages of Redis:

● Redis natively supports most of the datatypes so it is easy to integrate.
● Redis is very fast as it holds its database in memory.
● All Redis operations are atomic, which ensures that if two clients concurrently access, Redis server will receive the updated value.
● Redis is a multi-utility tool and can be used in a number of use cases such as caching, messaging-queues etc.


5) How to install Redis on Ubuntu?

Following commands can be use to install Redis on Ubuntu:

$sudo apt-get update 
$sudo apt-get install redis-server


6) How to set Redis configurations?

Following command can be use to set Redis configurations:

redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME


7) How to edit configuration of Redis?

Following command can be use to edit Redis configurations:

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE


8) What do you mean by this statement "Strings in Redis are binary safe"?

Strings in Redis are binary safe means they have a known length not determined by any special terminating characters. Thus, you can store anything up to 512 megabytes in one string.


9) What is Redis hash?

Redis hash is a collection of key value pairs. Redis Hashes are maps between string fields and string values. So, they are used to represent objects.


10) What is the storing capacity of each hash in Redis?

Every hash can store up to 2 power(32) - 1 field-value pairs.


11) What is HMSET and HGETALL in Redis?

HMSET is use to set the hash whereas HGETALL is use to get the value of the hash.


12) What are Redis Lists?

Redis Lists are simply lists of strings, sorted by insertion order. Elements can be added to a Redis List on the head or on the tail.


13) How to set and access Redis Lists?

Redis List can be set using lpush command whereas this list can be access via lrange command.


14) What are Redis Sets?

Redis Sets are an unordered collection of strings. In Redis sets, values can be added, removed, and tested for the existence of members in O(1) time complexity.


15) How to set and access Redis Sets?

Redis Set can be set using sadd command whereas this Set can be accessed via smembers command.


16) What are the Sorted Sets in Redis?

Redis Sorted Sets are similar to Redis Sets, non-repeating collections of Strings. The difference is, every member of a Sorted Set is associated with a score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, the scores may be repeated.


17) How to set and access Redis Sorted Sets?

Redis Sorted Set can be set using zadd command whereas this sorted Set can be accessed via ZRANGEBYSCORE command.


18) How to run commands on Redis remote server?

To run commands on Redis remote server, it need to connect to the server by client redis-cli. Below is the syntax:

$ redis-cli -h host -p port -a password


19) What are Redis keys commands?

Redis keys commands are used for managing keys in Redis. Following is the syntax for using redis keys commands.

redis 127.0.0.1:6379> COMMAND KEY_NAME


20) How to set and delete the Redis keys?

DEL command is use to delete the keys in Redis whereas SET command is use to set the keys.


21) What is EXPIRE key command in Redis?

In Redis EXPIRE key command sets the expiry of the key after the specified time.


22) What is EXPIREAT key command in Redis?

In Redis EXPIREAT sets the expiry of the key after the specified time. Here time is in Unix timestamp format.


23) What is KEYS pattern command in Redis?

KEYS pattern command finds all keys matching the specified pattern.


24) What is MOVE key command in Redis?

MOVE key command in Redis is use to move a key to another database.


25) What is PERSIST key command in Redis?

PERSIST key command in Redis is use to removes the expiration from the key.


26) What is PTTL key command in Redis?

PTTL key command in Redis is use to gets the remaining time in keys expiry in milliseconds.


27) What is RANDOMKEY command in Redis?

RANDOMKEY command in Redis is use to return a random key from Redis.


28) What is RENAMENX command in Redis?

RENAMENX command in Redis is use to rename the key, if a new key doesn't exist.


29) What is GETRANGE command in Redis?

GETRANGE command in Redis is use to get a substring of the string stored at a key.


30) What is GETBIT command in Redis?

GETBIT command in Redis is use to return the bit value at the offset in the string value stored at the key.


31) What is MGET command in Redis?

MGET command in Redis is use to get the values of all the given keys.


32) What is SETBIT command in Redis?

SETBIT command in Redis is use to sets or clears the bit at the offset in the string value stored at the key.


33) What is SETEX command in Redis?

SETEX command in Redis is use to sets the value with the expiry of a key.


34) What is SETNX command in Redis?

SETNX command in Redis is use to sets the value of a key, only if the key does not exist.


35) What is MSET command in Redis?

MSET command in Redis is use to set multiple keys to multiple values.


36) What is MSETNX command in Redis?

MSETNX command in Redis is use to set multiple keys to multiple values, only if none of the keys exist.


37) What is PSETEX command in Redis?

PSETEX command in Redis is use to set the value and expiration in milliseconds of a key.


38) What is INCR command in Redis?

INCR command in Redis is use to increment the integer value of a key by one.


39) What is INCRBY command in Redis?

INCRBY command in Redis is use to increment the integer value of a key by the given amount.


40) What is INCRBYFLOAT command in Redis?

INCRBYFLOAT command in Redis is use to increment the float value of a key by the given amount.


 

Related links: