Redis interview questions

Redis interview questions

Top Redis Interview Questions and answers

Download Redis interview questions PDF

Below are the list of Best Redis interview questions and Answers

Redis is an open-source released under BSD licensed, in-memory data structure store, it can be used as a database, cache and message broker.

Following are some advantages of Redis

  • Exceptionally Faster than others
  • Supports for rich data types like Hashes, Sets, bitmaps
  • Rich client-side library.
  • Support for server-side locking.
  • Operations are atomic.

Some commonly used Redis commands list

Command NameDescription
APPENDAppend a value to a key
AUTHAuthenticate to the server
BGREWRITEAOFAsynchronously rewrite the append-only file
BGSAVEAsynchronously save the dataset to disk
BITCOUNTCount set bits in a string
CLIENT LISTGet the list of client connections
CLUSTER INFOProvides info about Redis Cluster node state

Read more from Redis Commands List

Redis is NoSql  based Key-value Database, which is written in ANSI C

REPL stands for Read Eval Print Loop. It an interactive mode where the user types commands and get replies.

redis-cli is the Redis command-line interface, a simple program that allows sending commands to Redis, and read the replies sent by the server, directly from the terminal.

The differences between Redis and Memcached are as follows:

REDISMEMCACHED
It was released in 2009.It was released in 2003.
It was developed by Salvatore Sanfilippo.It was developed by Danga Interactive.
It uses single cores.It uses multiple cores.
In Redis, the maximum key length is 2GB.In Memcached, maximum key length is 250 bytes.
It is simple and easier to install as compared to Memcached.It is difficult to install.
It uses list, strings, hashes, sorted sets and bitmaps as data structure.It uses only string and integers as data structure.
Its reads and writes speed is slower than Memcached.Its reads and writes speed is higher than Redis.
It supports Master-Slave Replication and Multi-Master Replication methods.It does not support any replication method.
It is more durable than Memcached.It is less durable than Redis.
It has Document Store, Graph DBMS, Search Engine, and Time Series DBMS as secondary database models.It has no secondary database models.
It uses persistent data.It does not use persistent data.
It supports Sharding.It does not support any partitioning method.

Some operation keys of Redis are listed bellow:

CommandDescription
APPEND key valueAppend a value to a key
AUTH passwordAuthenticate to the server
BGREWRITEAOFAsynchronously rewrite the append-only file
BITPOS key bit [start] [end]Find the first-bit set or clear in a string
BLPOP key [key ...] timeoutRemove and get the first element in a list, or block until one is available
CLIENT LISTGet the list of client connections
CLIENT PAUSE timeoutStop processing commands from clients for some time
CLUSTER FORGET node-idRemove a node from the nodes table
CLUSTER INFOProvides info about Redis Cluster node state
CLUSTER KEYSLOT keyReturns the hash slot of the specified key
CLUSTER MEET ip portForce a node cluster to handshake with another node
CLUSTER NODESGet Cluster config for the node
CLUSTER SAVECONFIGForces the node to save cluster state on disk
CLUSTER SLAVES node-idList slave nodes of the specified master node
CLUSTER SLOTSGet an array of Cluster slot to node mappings
COMMANDGet an array of Redis command details
COMMAND COUNTGet the total number of Redis commands
COMMAND GETKEYSExtract keys are given a full Redis command
CONFIG GET parameterGet the value of a configuration parameter
CONFIG REWRITERewrite the configuration file with the in-memory configuration
CONFIG SET parameter valueSet a configuration parameter to the given value
CONFIG RESETSTATReset the stats returned by INFO
DBSIZEReturn the number of keys in the selected database
DEBUG OBJECT keyGet debugging information about a key
DEBUG SEGFAULTMake the server crash
DECR keyDecrement the integer value of a key by one
DECRBY key decrementDecrement the integer value of a key by the given number
DEL key [key ...]Delete a key
DISCARDDiscard all commands issued after MULTI
DUMP keyReturn a serialized version of the value stored at the specified key.
ECHO messageEcho the given string
EXECExecute all commands issued after MULTI
EXPIRE key secondsSet a key's time to live in seconds
GET keyGet the value of a key
GETBIT key offsetReturns the bit value at offset in the string value stored at key
GETRANGE key start endGet a substring of the string stored at a key
GETSET key valueSet the string value of a key and return its old value
HDEL key field [field ...]Delete one or more hash fields
HEXISTS key fieldDetermine if a hash field exists
HGET key fieldGet the value of a hash field
HGETALL keyGet all the fields and values in a hash
HKEYS keyGet all the fields in a hash
HLEN keyGet the number of fields in a hash
HSET key field valueSet the string value of a hash field
HSETNX key field valueSet the value of a hash field, only if the field does not exist
HSTRLEN key fieldGet the length of the value of a hash field
HVALS keyGet all the values in a hash
INCR keyIncrement the integer value of a key by one
INCRBY key incrementIncrement the integer value of a key by the given amount
INFO [section]Get information and statistics about the server
KEYS patternFind all keys matching the given pattern
LASTSAVEGet the UNIX timestamp of the last successful save to a disk
LINDEX key indexGet an element from a list by its index
LLEN keyGet the length of a list
LPOP keyRemove and get the first element in a list
LPUSHX key valuePrepend a value to a list, only if the list exists
LRANGE key start stopGet a range of elements from a list
LREM key count valueRemove elements from a list
LSET key index valueSet the value of an element in a list by its index
LTRIM key start stopTrim a list to the specified range
MGET key [key ...]Get the values of all the given keys
MONITORListen for all requests received by the server in real-time
MOVE key dbMove a key to another database
MULTIMark the start of a transaction block
PERSIST keyRemove the expiration from a key
PFCOUNT key [key ...]Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).
PING [message]Ping the server
PTTL keyGet the time to live for a key in milliseconds
QUITClose the connection
RANDOMKEYReturn a random key from the keyspace
READONLYEnables read queries for a connection to a cluster slave node
READWRITEDisables read queries for a connection to a cluster slave node
RENAME key newkeyRename a key
ROLEReturn the role of the instance in the context of replication
RPOP keyRemove and get the last element in a list
RPUSHX key valueAppend a value to a list, only if the list exists
SAVESynchronously save the dataset to disk
SCARD keyGet the number of members in a set
SCRIPT FLUSHRemove all the scripts from the script cache.
SCRIPT KILLKill the script currently in execution.
SCRIPT LOAD scriptLoad the specified Lua script into the script cache.
SDIFF key [key ...]Subtract multiple sets
SELECT indexChange the selected database for the current connection
SETNX key valueSet the value of a key, only if the key does not exist
SINTER key [key ...]Intersect multiple sets
SLAVEOF host portMake the server a slave of another instance, or promote it as master
SMEMBERS keyGet all the members in a set
SPOP key [count]Remove and return one or multiple random members from a set
STRLEN keyGet the length of the value stored in a key
SWAPDB index indexSwaps two Redis databases
SYNCAn internal command used for replication
TIMEReturn the current server time
TOUCH key [key ...]Alters the last access time of a key(s). Returns the number of existing keys specified.
TTL keyGet the time to live for a key
TYPE keyDetermine the type stored at key
UNLINK key [key ...]Delete a key asynchronously in another thread. Otherwise, it is just as DEL, but non-blocking.
UNWATCHForget about all watched keys

ZSET refers to the Redis Sorted Set where a Redis data type documented. In a sorted set, Each key has multiple values inside that is associated with a floating value score. In Redis, It has the unique property of being able to be accessed by a member like a HASH but items can also be accessed by the sorted order and values of the scores.

Redis hashes are defined as the hashes that map string names to string values. They are containers of unique fields and their values. It is a perfect way to represent an object as a Redis data structure. It provides constant time basic operations such as get, set, exists, etc.

Redis supports following Data Structures
  • Strings
  • Hashes
  • Lists
  • Sets
  • Sorted sets with range queries
  • bitmaps
  • Hyperloglogs
  • Geospatial indexes with radius queries
Below are some Redis Clients supported by PHP Programming Language
  • amphp/redis
  • cheprasov/php-redis-client
  • Credis
  • PHP Redis implementation / wrapper
  • PHP Sentinel Client
  • phpredis
Redis supports a wide range of programming language. Some major programming languages supported by Redis are PHP, Java, Python, Scala, Perl, Ruby, C#, and C++.

Also Read Related Redis interview questions

Memcached Interview QuestionsRabbitmq Interview Questions