Redis Interview Questions
In this post we will look at Redis Interview questions. Examples are provided with explanation.
Q: What is Redis?
A: Redis (Remote Dictionary Server) is an open-source in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, hyperloglogs, bitmaps, streams and spatial indexes.
Q: In which scenario to use Redis?
A: Following are some scenarios we can use Redis-
- Session Cache Session Cache is a caching service that stores and persists HTTP session objects to a remote data grid. The data grid is a general use grid that stores strings and objects. Session Cache remotely leverages the caching capabilities of the data grid and lets you store session data.
- Full Page Cache (FPC) Outside of your basic session tokens, Redis provides a very easy FPC platform to operate in. Going back to consistency, even across restarts of Redis instances, with disk persistence your users won't see a decrease in speed for their page loads-a drastic change from something like PHP native FPC.
- Queues Taking advantage of Redis' in memory storage engine to do list and set operations makes it an amazing platform to use for a message queue. Interacting with Redis as a queue should feel native to anyone used to using push/pop operations with lists in programming languages such as Python.
- Leaderboards/Counting Redis does an amazing job at increments and decrements since it's in-memory. Sets and sorted sets also make our lives easier when trying to do these kinds of operations, and Redis just so happens to offer both of these data structures. So to pull the top 10 users from a sorted set-we'll call it "user_scores"-one can simply run the following: ZRANGE user_scores 0 10
- Pub/Sub Last (but certainly not least) is Redis's Pub/Sub feature. The use cases for Pub/Sub are truly boundless. I've seen people use it for social network connections, for triggering scripts based on Pub/Sub events, and even a chat system built using Redis Pub/Sub! (No, really, check it out.)