Top 50 Interview Question and Answers of Redis

Here is a quick Introduction to Redis

Redis is an open-source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster

1. What is Redis?

Answer: Redis is essentially a Key-Value type in-memory database, much like memcached. The entire database is loaded in the memory for operation, and the database data is flushed to the hard disk for storage periodically through asynchronous operations. Because it is a pure memory operation, Redis has excellent performance. It can handle more than 100,000 reads and write operations per second. It is the fastest known Key-Value DB. The excellence of Redis is not just performance. The biggest charm of Redis is that it supports saving multiple data structures. In addition, the maximum limit of a single value is 1GB. Unlike memcached, which can only store 1MB of data, Redis can be used to achieve many useful things. Function, for example, use his List as a FIFO doubly linked list to realize a lightweight high-performance message queue service, use his Set to make a high-performance tag system, and so on. In addition, Redis can also set the expire time for the stored Key-Value, so it can also be used as an enhanced version of memcached. The main disadvantage of Redis is that the database capacity is limited by physical memory and cannot be used for high-performance reading and writing of massive data. Therefore, the suitable scenarios for Redis are mainly limited to high-performance operations and calculations with a small amount of data.

2. What are the advantages of Redis over Memcached?


(1) All values ​​of memcached are simple strings. Redis, as its replacement, supports richer data types

(2) Redis is much faster than memcached

(3) Redis can persist its data

3. What is the full name of Redis?

Answer: Remote Dictionary Server

4. What physical resources does Redis consume?

Answer: Redis is a high-performance database based on memory — mainly relies on memory.

5. What is the maximum storage capacity for a string type value?

Answer: 512M

6. Under what circumstances will the Redis cluster solution cause the entire cluster to be unavailable?

Answer: In a cluster with three nodes A, B, and C, without a replication model, if node B fails, the entire cluster will think that it lacks slots in the range of 5501-11000 and is unusable.

7. There are 2000w data in MySQL and only 20w data in Redis. How to ensure that the data in Redis are all hot data?

Answers: When the size of the Redis memory data set rises to a certain size, a data elimination strategy will be implemented.]

8. What are the Java clients supported by Redis? Which one is the official recommendation?

Answer: Redisson, Jedis, lettuce, etc., the official recommendation is to use Redisson.

9. What is the relationship between Redis and Redisson?

Answer: Redisson is an advanced distributed coordination Redis customer service terminal that can help users easily implement some Java objects (Bloom filter, BitSet, Set, SetMultimap, ScoredSortedSet, SortedSet, Map, ConcurrentMap, List, ListMultimap, Queue, BlockingQueue, Deque, BlockingDeque, Semaphore, Lock, ReadWriteLock, AtomicLong, CountDownLatch, Publish/Subscribe, HyperLogLog).

10. How to set a password and verify the password for Redis?

Answer: Set password: config set require to pass 123456 Authorization password: auth 123456

11. How are Redis clusters replicated?

Answer: Asynchronous replication

12. What is the maximum number of nodes in a Redis cluster?

Answer: 16,384.

13. How to choose a database for the Redis cluster?

Answer: Redis cluster currently cannot do database selection, the default is 0 database.

14. How to test the connectivity of Redis?

Answer: ping

15. How to understand Redis transaction?

Answers: The transaction is a separate isolated operation: all commands in the transaction are serialized and executed sequentially. During the execution of the transaction, it will not be interrupted by command requests sent by other clients. A transaction is an atomic operation: either all commands in the transaction are executed or none of them are executed.

16. What are the commands related to Redis transactions?

Answers: How to set the expiration time and permanent validity of MULTI, EXEC, DISCARD, WATCH ##28, Redis key? EXPIRE and PERSIST commands.

17. What algorithm does Redis use for recycling?

Answers: **LRU algorithm

18. How does Redis do a large amount of data insertion?

Answers: Redis2.6 started Redis-CLI to support a new mode called pipe mode for performing large amounts of data insertion work.

19. Which clients support consistent hashing?

Answers: Redis-rb, Predis, etc.

20. What command is used to view Redis usage and status information?

Answers: info

21. How to choose a suitable persistence method?

Answers: Generally speaking, if you want to achieve data security comparable to PostgreSQL, you should use both persistence functions. If you care about your data very much, but can still withstand data loss within a few minutes, then you can just use RDB persistence. Many users only use AOF persistence, but this method is not recommended: because regular RDB snapshots (snapshots) are very convenient for database backup, and RDB restores data sets faster than AOF restores, In addition, the use of RDB can also avoid the aforementioned AOF program bugs.

22. ​​How many keys can a Redis instance store at most?

Answer: How many elements can be stored in List, Set, Sorted Set? In theory, Redis can handle up to 232 keys and has been tested in practice. Each instance stores at least 250 million keys. We are testing some larger values. Any list, set, and sorted set can contain 232 elements. In other words, the storage limit of Redis is the available memory value in the system.

23. What happens when Redis’s memory runs out?

Answers: If the set upper limit is reached, Redis write commands will return an error message (but read commands can also return normally.) Or you can use Redis as a cache to use the configuration elimination mechanism. When Redis reaches the memory limit, it will flush out the old content.

24. Why Redis is fast?


25. Why is Redis faster than SQL?


  • Since Redis stores data in primary memory, because of that Read and Write operations will be extremely fast.
  • In RDBMS, Read and Write operations are slow because it stores data in secondary memory.
  • Primary memory is in lesser in size and much expensive than secondary so, Redis cannot store large files or binary data.

26. What are the differences between Redis and RDBMS?


27. Redis SET data-type.


Redis Sets are an unordered collection of Strings. It is possible to add, remove, and test for the existence of members in O(1)
The max number of members in a set is 2³² — 1 (4294967295, more than 4 billion members per set).

28. Redis Hashes data-type.


Redis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects like user-details
Every hash can store up to 2³² — 1 field-value pairs (more than 4 billion).

29. Explain Redis Sorted sets.


Sorted sets are a data type that is similar to a mix between a Set and a Hash. Like sets, sorted sets are composed of unique, non-repeating string elements, so in some sense, a sorted set is a set as well.
However, while elements inside sets are not ordered, every element in a sorted set is associated with a floating-point value, called the score.[in ascending order]

30. What Do You Mean By Data Modeling In Redis?

Answer: Just like any other database, data modeling represents the storage pattern of how and which data structures are used to store the data to achieve a domain requirement. For example in the relational database world, we use the primary key to establish a relationship between two entities. Data stored in relational databases are in a table format, whereas in Redis there are a set of data structures available, which are used to represent the domain data. There is certainly a different design mindset needed to convert the relational data to a Redis dataset.

31. Why Redis Is Different As Compared To Other Key-value Stores?


  • Redis values can contain more complex data types, with atomic operations.
  • Redis is an in-memory but persistent on-disk database.

32. How To Re-start Redis?

Answer: You can restart Redis by using the following path:

/etc/init.d/redis-server restart

33. How To Get All Keys From Redis?

Answer: Use the following commands:

$keyList = $redis->keys(“*”);


/*Array ( [0] => tutorials [1] => name ) */

34. What Do You Mean By “Redis Is Binary Safe”?

Answer: Binary safe means that it has a known length but is not limited by any special character. You can store any value up to the given size. A string value can be 512 MB in length.

35. How Does Redis Differ From Mongodb? Is There A Use Case When For Redis If Using Mongodb?

Answer: MongoDB is an unstructured (at least, in definition) distributed document storage. For clearing purposes, you can think about it as a highly scalable and not-so-high-performance JSON storage (though actually, it uses BSON). It has a simple but effective multitype index system, replication and sharding, and a lot more nice features.

Redis is the simplest key/value store, with transient data caching. It can work as an efficient queue system.

Looking for more specific information you will find a lot of scenarios where both of them are used, Mongo as a true persistent canonical storage, and Redis as a transient/cache storage.

36. How Can You Use Redis With the .net Application?


  • First, Download Redis Server.
  • Install Redis Server.
  • Download Redis Client.
  • Set Configuration into Web.config File.
    Use Redis Client Class.

37. List out the operation keys of Redis?


38. How Do I Move A Redis Database From One Server To Another?


  • use BGSAVE command to Save a spanshot of the database into a dump.rdb
  • Copy this dump.rdb file into another server.

39. Is Redis also Durable besides fast?

Answer: No. Redis compromises with durability to enhance the speed. In Redis, in the case of system failure or crash, it writes to disk but may fall behind and lose the data which is not stored.

40. What are the limitations Of Redis?


41. In which language Redis is written?

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

42. List the programming languages supported by Redis?

Answer: Redis supports a wide range of programming languages. Some major programming languages supported by Redis are PHP, Java, Python, Scala, Perl, Ruby, C#, and C++.

43. What is the use of MGET in Redis?

Answer: 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.

44. How to list all databases in Redis?

Answer: To get a list of all the database connections (16 maximum database connections can be done by default) in Redis, do the following command.

45. How to delete all the cache using pRedis in PHP?

Answer: 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.

46. How to create a 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 databases, 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.

47. What is Express.js?

Answer:Express.js is a framework that helps us to organize our web application into an MVC architecture. We can use a variety of languages like Jade, EJS, etc.

48. What is the difference between Redis and Memcached?


49. What is the difference between Redis and RocksDB?


Redis is efficient but unstable.
Redis is all in -memory.
RocksDB supports a multi-threading library.
RocksDB is in-memory but also uses flash storage.

50. How to set value in Redis?


Rajesh Kumar
Follow me
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x