Prev Next

Database / REDIS

1. What is a Redis key? 2. What is Redis? 3. List few Redis Datatypes. 4. What is the purpose of the EXPIRE command? 5. What is a Redis Sorted Set? 6. Advantages of Redis. 7. What is a Redis Hash used for? 8. What programming languages does Redis support? 9. Explain Replication in Redis. 10. What is a Redis Set data type used for? 11. What is the purpose of the INCR command? 12. Explain about REDIS security. 13. Expand REDIS. 14. What is a Redis Stream? 15. In which language Redis is developed? 16. Define a Redis Bitmap? 17. What is the purpose of Redis Pub/Sub? 18. Difference between SET and MSET command in REDIS. 19. What are Redis transactions? 20. Explain LPUSH command in REDIS. 21. What is RDB persistence in Redis? 22. Limitations of REDIS. 23. What is AOF persistence in Redis? 24. REDIS is fast, but is it also durable? 25. Difference between Memcached and REDIS. 26. What is the purpose of the SELECT command in Redis? 27. What is the purpose of the TTL command? 28. What is SADD command in REDIS? 29. Mention few LIST operations in REDIS. 30. Define eviction policies in Redis? 31. Mention Spring Boot Drivers for REDIS. 32. What is Redis Sentinel used for? 33. Explain about redisson client for redis. 34. What is Redis Cluster? 35. How do you connect to Redis using the CLI? 36. What is a Cache Penetration Problem? 37. Why is Redis often faster than a traditional relational database for caching? 38. How I/O Multiplexing Works in Redis? 39. What is Valkey, and how does it relate to Redis? 40. What is the difference between RDB and AOF persistence? 41. How does Redis achieve high throughput with a mostly single-threaded design? 42. Why should you configure an eviction policy for a Redis instance used as a cache? 43. How does Redis Cluster shard data across nodes? 44. When should you use Redis Sentinel instead of Redis Cluster? 45. What happens when a Redis master fails in a Sentinel-managed setup? 46. Explain the execution flow of a Redis transaction using MULTI/EXEC? 47. How can you optimize Redis memory usage for large datasets? 48. How do you troubleshoot high memory usage in a Redis instance? 49. Why is the maxmemory-policy setting important for a cache-only Redis deployment? 50. Explain the lifecycle of a key with a TTL set in Redis? 51. How does Redis handle atomicity for multi-key operations? 52. What is the difference between a Redis List and Sorted Set for queues? 53. How do you implement a distributed lock using Redis? 54. How does Redis Streams support consumer groups? 55. Which is better and why: Redis Pub/Sub or Redis Streams for event delivery? 56. How do you integrate Redis as a session store in a web application? 57. Explain the internal working of Redis's hash table resizing (rehashing)? 58. How do you configure Redis persistence for a production deployment? 59. What is the difference between Redis Cluster and client-side sharding? 60. How does Redis support Lua scripting for atomic operations? 61. When would you choose Redis Streams over a message broker like Kafka? 62. How do you secure Redis access using ACLs? 63. Why should the KEYS command be avoided in production? 64. How do you configure Redis for cache-aside pattern usage? 65. Explain the execution flow of a Redis Cluster request with a MOVED redirection? 66. How does Redis handle replication lag between a master and its replicas? 67. Why doesn't Redis guarantee strong consistency by default across replicas? 68. How do you mitigate a Cache Avalanche in a Redis-backed system? 69. What is the difference between Redis's diskless replication and disk-based replication?

1. What is a Redis key?

A key is the unique string identifier used to store and retrieve a value in Redis — every piece of data in Redis, regardless of its type (string, hash, list, set, and so on), is addressed by exactly one key,...

Read full answer

2. What is Redis?

Redis is an open source in-memory data structure store which can be used as a database and/or a cache and message broker. NoSQL Key/Value Store.

Read full answer

3. List few Redis Datatypes.

Redis supports, Strings, Lists, Sets, Sorted Sets, Hashes, Bitmaps, Hyperlogs, and Geospatial indexes.

Read full answer

4. What is the purpose of the EXPIRE command?

EXPIRE attaches a time-to-live to an existing key, after which Redis automatically removes it — useful for data that should only be valid temporarily, like a session token, a rate-limit counter, or a cached query result that shouldn't be served...

Read full answer

5. What is a Redis Sorted Set?

A Sorted Set ( ZSET ) stores unique members the same way a plain Set does, but pairs each member with a floating-point score , and Redis automatically keeps the whole collection ordered by that score — giving you a...

Read full answer

6. Advantages of Redis.

Very Flexible. No Schema and column names.

Read full answer

7. What is a Redis Hash used for?

A Hash stores a set of field-value pairs under a single key, similar to a small object or a row in a table — instead of serializing an entire object into one string value, a Hash lets you store and...

Read full answer

8. What programming languages does Redis support?

REDIS supports most of the programming languages including Java, C#, Python, Scala, C++, R, PHP and many more.

Read full answer

9. Explain Replication in Redis.

Redis supports simple master to slave replication. When a relationship is established, data from the master is replicated to the slave.

Read full answer

10. What is a Redis Set data type used for?

A Set stores an unordered collection of unique strings — no duplicates are allowed, and there's no concept of order or position the way a List has. Its core value is fast membership testing and set algebra: checking whether an...

Read full answer

11. What is the purpose of the INCR command?

INCR atomically increments the integer value stored at a key by 1, returning the new value — and because it's atomic, it's safe to call concurrently from many clients without a race condition, unlike a naive "read the current value,...

Read full answer

12. Explain about REDIS security.

Redis is designed to be accessed by trusted clients. REDIS can be restricted to certain interfaces.

Read full answer

13. Expand REDIS.

Redis stands for REmote DIctionary Server.

Read full answer

14. What is a Redis Stream?

A Stream is an append-only log data structure, similar in spirit to a Kafka topic, where each entry gets a unique, time-ordered ID and holds a set of field-value pairs. Unlike Pub/Sub, entries persist in the stream and can be...

Read full answer

15. In which language Redis is developed?

Redis is developed using ANSI C and mostly used for cache solution and session management. It creates unique keys for store values.

Read full answer

16. Define a Redis Bitmap?

A Bitmap isn't a separate data type in Redis — it's a way of treating an ordinary String value as a compact array of individual bits, addressed by offset, using dedicated bit-level commands. Because a String can hold up to...

Read full answer

17. What is the purpose of Redis Pub/Sub?

Pub/Sub lets clients broadcast messages on named channels to any number of subscribers listening at that moment, without Redis storing the message anywhere — it's a pure, ephemeral fire-and-forget messaging mechanism, not a durable queue. # subscriber SUBSCRIBE notifications #...

Read full answer

18. Difference between SET and MSET command in REDIS.

SET command creates one key-value pair while using MSET command, multiple key-value pairs can be created.

Read full answer

19. What are Redis transactions?

A Redis transaction bundles multiple commands so they execute as a single, uninterrupted sequence — no other client's commands can be interleaved in the middle of a transaction once it starts executing, which is what gives Redis transactions their isolation...

Read full answer

20. Explain LPUSH command in REDIS.

LPUSH inserts all the specified values at the head of the list stored at key. If the key does not exist, it is created as an empty list before performing the push operations....

Read full answer

21. What is RDB persistence in Redis?

RDB (Redis Database) persistence works by taking a point-in-time snapshot of the entire in-memory dataset and writing it to a single compact binary file on disk, either on a configured schedule or on demand. Because it's a full snapshot rather...

Read full answer

22. Limitations of REDIS.

REDIS is single threaded. It has got limited client support for consistent hashing.

Read full answer

23. What is AOF persistence in Redis?

AOF (Append Only File) persistence logs every write operation to a file as it happens, in the order it was executed, rather than periodically snapshotting the whole dataset. Recovering from an AOF file means replaying that log of commands from...

Read full answer

24. REDIS is fast, but is it also durable?

No. Redis compromises with durability to enhance the speed.

Read full answer

25. Difference between Memcached and REDIS.

Memcached . REDIS ....

Read full answer

26. What is the purpose of the SELECT command in Redis?

Redis supports multiple numbered logical databases within a single server instance (16 by default, indexed 0-15), and SELECT switches the current connection's active database to a given index, scoping subsequent commands to just that database's keyspace. SELECT 1 SET debug:flag...

Read full answer

27. What is the purpose of the TTL command?

TTL returns how many seconds remain before a key expires, letting an application check a key's remaining lifetime without having to track expiration times itself in separate application logic. SET session:abc123 "data" EX 3600 TTL session:abc123 # returns remaining seconds,...

Read full answer

28. What is SADD command in REDIS?

Add the specified members to the set stored at key. Specified members that are already a member of this set are ignored....

Read full answer

29. Mention few LIST operations in REDIS.

LPUSH adds an element to the beginning of a list. RPUSH add an element to the end of a list....

Read full answer

30. Define eviction policies in Redis?

When Redis is used as a cache with a fixed maxmemory limit, an eviction policy determines which keys get removed once that limit is reached and new writes still need room — without a policy that allows eviction, Redis would...

Read full answer

31. Mention Spring Boot Drivers for REDIS.

Spring Boot primarily supports two main Redis drivers (clients): Lettuce (which is the default) and Jedis. It abstracts these clients using the Spring Data Redis framework, allowing developers to switch between them easily....

Read full answer

32. What is Redis Sentinel used for?

Sentinel is a separate, lightweight process (or set of processes) that monitors a Redis master and its replicas, and automatically handles failover if the master becomes unavailable — promoting a replica to master and reconfiguring the rest of the replicas...

Read full answer

33. Explain about redisson client for redis.

Redisson is a popular, open-source Java client for Redis (and Valkey) that offers a simplified, thread-safe way for Java developers to interact with the Redis data store. It abstracts the complexities of the Redis API by providing familiar Java objects...

Read full answer

34. What is Redis Cluster?

Redis Cluster is Redis's built-in solution for horizontally scaling data across multiple nodes — instead of one server holding the entire dataset, the keyspace is split into 16,384 fixed hash slots, and those slots are distributed across the cluster's master...

Read full answer

35. How do you connect to Redis using the CLI?

redis-cli is Redis's interactive command-line client, and connecting to a running instance is typically a single command specifying the host, port, and (if configured) authentication credentials: redis-cli -h localhost -p 6379 redis-cli -h redis.example.com -p 6379 -a mypassword redis-cli -h...

Read full answer

36. What is a Cache Penetration Problem?

Cache penetration is a performance issue where requests for non-existent data repeatedly bypass the cache and hit the backend database, causing overload, often due to malicious attacks or data deletion. Solutions involve caching null/empty results with short TTLs, using a...

Read full answer

37. Why is Redis often faster than a traditional relational database for caching?

The speed difference comes from where and how data is stored and accessed, not from any single trick. Redis keeps its entire working dataset in RAM, so a read or write is a direct memory access rather than a disk...

Read full answer

38. How I/O Multiplexing Works in Redis?

Redis uses I/O multiplexing to enable its single-threaded core to efficiently handle thousands of concurrent client connections. This technique allows the Redis server to monitor multiple sockets simultaneously and process data on those that are ready, without blocking on any...

Read full answer

39. What is Valkey, and how does it relate to Redis?

Valkey is a Linux Foundation-backed, BSD-3-Clause licensed fork of Redis, created immediately after Redis Ltd. moved the core Redis project off the permissive BSD license to a source-available dual license (SSPLv1/RSALv2) in March 2024....

Read full answer

40. What is the difference between RDB and AOF persistence?

Both write data to disk so a Redis instance can recover its dataset after a restart or crash, but they capture that data in fundamentally different forms, with different trade-offs. RDB AOF Point-in-time binary snapshot of the full dataset....

Read full answer

41. How does Redis achieve high throughput with a mostly single-threaded design?

Redis's core command execution has traditionally run on a single thread, which sounds like it should limit throughput, but it actually sidesteps a large class of overhead that a multi-threaded design would otherwise need to pay for. No lock contention...

Read full answer

42. Why should you configure an eviction policy for a Redis instance used as a cache?

The default noeviction policy means once maxmemory is reached, Redis starts rejecting new write commands outright with an out-of-memory error, rather than making room by removing older data. For a pure caching use case, that's usually the wrong behavior: a...

Read full answer

43. How does Redis Cluster shard data across nodes?

Redis Cluster divides the entire keyspace into 16,384 fixed hash slots, and assigns ownership of ranges of those slots to each master node in the cluster — a 3-master cluster might own roughly 5,461 slots each, for example. A key's...

Read full answer

44. When should you use Redis Sentinel instead of Redis Cluster?

The deciding factor is whether the real need is high availability for a dataset that fits comfortably on one node, or horizontal scaling across many nodes because the dataset or write throughput has outgrown a single instance. Sentinel is the...

Read full answer

45. What happens when a Redis master fails in a Sentinel-managed setup?

Sentinel's failover process follows a defined sequence rather than reacting instantly to any single missed check, specifically to avoid triggering an unnecessary failover from a brief, isolated network blip. flowchart TD A[Sentinel loses contact with master] --> B[Master marked SDOWN,...

Read full answer

46. Explain the execution flow of a Redis transaction using MULTI/EXEC?

Unlike a database transaction that begins actual execution immediately, a Redis MULTI block queues commands on the client's connection without running them, and only EXEC triggers the whole batch to actually execute, uninterrupted. flowchart TD A[Client sends MULTI] --> B[Redis...

Read full answer

47. How can you optimize Redis memory usage for large datasets?

Since Redis keeps data in RAM, memory efficiency directly determines both cost and how much data fits on a given instance, and a handful of concrete techniques typically account for most of the achievable savings. Use compact encodings for small...

Read full answer

48. How do you troubleshoot high memory usage in a Redis instance?

High memory usage troubleshooting starts with distinguishing "memory usage is high but expected" from "memory usage is growing unexpectedly," since the fixes are very different. INFO memory MEMORY DOCTOR redis-cli --bigkeys MEMORY USAGE mykey Check INFO memory for used_memory ,...

Read full answer

49. Why is the maxmemory-policy setting important for a cache-only Redis deployment?

maxmemory-policy is what actually determines Redis's behavior once the configured maxmemory limit is hit, and for a cache-only deployment, getting this setting wrong can turn a memory-pressure event into an application outage rather than a graceful, expected eviction. maxmemory 4gb...

Read full answer

50. Explain the lifecycle of a key with a TTL set in Redis?

A key's TTL doesn't trigger a background timer that fires exactly at expiration — Redis uses a combination of lazy and active strategies to actually reclaim expired keys, which is worth understanding since it explains some otherwise-surprising behavior around memory...

Read full answer

51. How does Redis handle atomicity for multi-key operations?

A single Redis command, even one touching multiple keys (like MSET or SUNIONSTORE ), is always atomic on its own — because command execution is single-threaded, nothing else can run in the middle of it. The harder case is atomicity...

Read full answer

52. What is the difference between a Redis List and Sorted Set for queues?

Both can back a queue, but they fit different queue semantics depending on whether strict FIFO insertion order or a computed priority should determine processing order. List (LPUSH/RPOP) Sorted Set (ZADD/ZPOPMIN) Strict insertion-order FIFO (or LIFO with matching push/pop ends)....

Read full answer

53. How do you implement a distributed lock using Redis?

The basic pattern uses a single atomic command to both acquire the lock and set a safety expiration in one step, so a crashed client can never hold a lock forever: SET lock:resource-1 "unique-client-token" NX PX 30000 NX means the...

Read full answer

54. How does Redis Streams support consumer groups?

A consumer group lets multiple consumers cooperatively process a single stream, with Redis tracking, per group, which entries have been delivered and which have been explicitly acknowledged — behavior much closer to a traditional message queue than Redis's other data...

Read full answer

55. Which is better and why: Redis Pub/Sub or Redis Streams for event delivery?

The two solve overlapping but genuinely different problems, so "better" depends entirely on whether message durability and replay matter for the use case. Pub/Sub is the better fit when messages are only meaningful to clients that are connected right now...

Read full answer

56. How do you integrate Redis as a session store in a web application?

Using Redis for session storage means each user's session data (login state, cart contents, preferences) is stored as a Hash or JSON-serialized String under a key derived from a session ID, with a TTL matching the desired session lifetime —...

Read full answer

57. Explain the internal working of Redis's hash table resizing (rehashing)?

Redis's core keyspace (and large Hash-type values) are backed by a hash table, and as entries are added or removed, the table needs to grow or shrink to keep lookups close to O(1) — but a naive full rehash (allocate...

Read full answer

58. How do you configure Redis persistence for a production deployment?

Production Redis persistence is typically both RDB and AOF enabled together, tuned to balance recovery speed, durability, and operational overhead, rather than relying on just one mechanism alone. # redis.conf save 900 1 save 300 10 save 60 10000 appendonly...

Read full answer

59. What is the difference between Redis Cluster and client-side sharding?

Both split data across multiple Redis instances, but they differ in where the sharding logic and cluster awareness actually live. Redis Cluster Client-Side Sharding Sharding logic (hash slots, redirection) built into Redis and cluster-aware clients....

Read full answer

60. How does Redis support Lua scripting for atomic operations?

Redis embeds a Lua interpreter directly in the server, and EVAL (or the cached, more efficient EVALSHA ) runs a Lua script as a single atomic unit — the entire script executes with no other client command interleaved anywhere in...

Read full answer

61. When would you choose Redis Streams over a message broker like Kafka?

Both give you a durable, replayable, partitioned-ish log with consumer groups, but they're built for different scales and operational footprints, so the choice usually comes down to how large and how critical the messaging workload actually is. Redis Streams makes...

Read full answer

62. How do you secure Redis access using ACLs?

Redis's Access Control List (ACL) system lets you define named users, each with their own password, and fine-grained permissions over which commands they can run and which keys they can touch — a meaningful step up from the older, single...

Read full answer

63. Why should the KEYS command be avoided in production?

KEYS pattern scans the entire keyspace to find matching keys, and because it runs on Redis's single command-execution thread, it blocks every other client from being served for however long that full scan takes — on a dataset with millions...

Read full answer

64. How do you configure Redis for cache-aside pattern usage?

The cache-aside (lazy-loading) pattern keeps the application in control of when data is read from and written to the cache, with Redis itself needing minimal special configuration — the pattern mostly lives in application logic, with a few Redis-side settings...

Read full answer

65. Explain the execution flow of a Redis Cluster request with a MOVED redirection?

A cluster-aware client doesn't need to know in advance exactly which node owns every key, but it does need to handle being told it guessed wrong, which is what the MOVED response mechanism exists for. flowchart TD A[Client computes key's...

Read full answer

66. How does Redis handle replication lag between a master and its replicas?

Redis replication is asynchronous by default: a write completes and is acknowledged to the client as soon as the master processes it, without waiting for any replica to confirm receipt — which is what makes writes fast, but also means...

Read full answer

67. Why doesn't Redis guarantee strong consistency by default across replicas?

Redis's default replication is asynchronous specifically to keep write latency low: a master acknowledges a write as soon as it's processed locally, without pausing to confirm every replica has received it too. That design choice is exactly what makes strong...

Read full answer

68. How do you mitigate a Cache Avalanche in a Redis-backed system?

A Cache Avalanche happens when a large number of cached keys expire at (or near) the same moment, sending a sudden flood of requests through to the backing database all at once, since the cache can no longer absorb them...

Read full answer

69. What is the difference between Redis's diskless replication and disk-based replication?

When a new replica connects (or an existing one falls too far behind to catch up incrementally), the master needs to send it a full copy of the dataset to bootstrap from, and Redis supports two different mechanisms for producing...

Read full answer

«
»

Comments & Discussions