Prev Next

Database / REDIS

1. What is Redis? 2. What is a Redis key? 3. What is the purpose of the EXPIRE command? 4. List few Redis Datatypes. 5. What is a Redis Sorted Set? 6. Advantages of Redis. 7. What programming languages does Redis support? 8. What is a Redis Hash used for? 9. What is a Redis Set data type used for? 10. Explain Replication in Redis. 11. What is the purpose of the INCR command? 12. Explain about REDIS security. 13. What is a Redis Stream? 14. Expand REDIS. 15. Define a Redis Bitmap? 16. In which language Redis is developed? 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. Define eviction policies in Redis? 30. Mention few LIST operations in REDIS. 31. What is Redis Sentinel used for? 32. Mention Spring Boot Drivers for REDIS. 33. Explain about redisson client for redis. 34. What is Redis Cluster? 35. How do you connect to Redis using the CLI? 36. Why is Redis often faster than a traditional relational database for caching? 37. What is a Cache Penetration Problem? 38. What is Valkey, and how does it relate to Redis? 39. How I/O Multiplexing Works in 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 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. Supports Multiple data structures. Built in Replication.

Read full answer

2. 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, the same way a variable name addresses a value in a program. SET user:1001:name "Al...

Read full answer

3. 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 stale forever. SET session:abc123 "user-data" ...

Read full answer

4. List few Redis Datatypes.

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

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 structure that's simultaneously a unique-membership set and an ordered ranki...

Read full answer

6. Advantages of Redis.

Very Flexible. No Schema and column names. Very fast, can perform around 110K Set per second and 81K GETS per second. Rich Datatype support, command level Atomic Operation, Caching & Disk Persistence.

Read full answer

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

8. 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 update individual fields of that object directly. HSET user:1001 name "Alex" age "30" email "...

Read full answer

9. 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 item exists, and combining multiple sets via union, intersection...

Read full answer

10. 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

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, add 1, write it back" sequence performed in application co...

Read full answer

12. Explain about REDIS security.

Redis is designed to be accessed by trusted clients. REDIS can be restricted to certain interfaces. Data encryption not supported and hence do not allow external access/internet exposure.

Read full answer

13. 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 by multiple independent readers at their own pace, including reade...

Read full answer

14. Expand REDIS.

Redis stands for REmote DIctionary Server.

Read full answer

15. 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 512MB, a single key can represent billions of individual boolean fla...

Read full answer

16. 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

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 # publisher, fr...

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 guarantee. MULTI SET account:1:ba...

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. When key holds a value that is not a list, an error is returned. Usage: LPUSH key value [value ...] redis> LPUSH mylist "W...

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 than a running log, restarting from an RDB file is fa...

Read full answer

22. Limitations of REDIS.

REDIS is single threaded. It has got limited client support for consistent hashing. It has significant overhead for persistence. It cannot be deployed widely.

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 the start to rebuild the exact dataset state. # redis...

Read full answer

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

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.

Read full answer

25. Difference between Memcached and REDIS.

Memcached . REDIS . Memcached is multi-threaded. Redis is single threaded. Memcached only does caching information. Redis does caching information and also supports persistence and replication. Memcached supports the functionality of LRU (Least Recently Used) eviction of values. Redis does not su...

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 "on" # stored in d...

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, e.g. 3599 TTL nonexist...

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. If key does not exist, a new set is created before adding the specified members. An error is returned when the value stored at key is not a set. Usage: SADD key member [member ...

Read full answer

29. 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 instead simply reject new writes with an out-of-memory error once t...

Read full answer

30. 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. LPOP removes the first element from a list and returns it. RPOP removes the last element from a list and returns it. LLEN gets the length of a list. LRANGE gets a range of elements from a list.

Read full answer

31. 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 to follow the new master, without ...

Read full answer

32. 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. Supported Redis Drivers Lettuce This is the default Redis client used in ...

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 and data structures, such as Map, List, Queu...

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 nodes, each of which can also ha...

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 loca...

Read full answer

36. 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 seek, and its data structures (hash tables, skip lists, linked lists) are purpose-bu...

Read full answer

37. 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 Bloom filter to pre-chec...

Read full answer

38. 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. Valkey started from the last BSD-licensed Redis release (7.2...

Read full answer

39. 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 single connection. S...

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. Append-only log of every write command, in order. Faster...

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 — since only one thread ever touches th...

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 cache is supposed to gracefully lose its...

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 slot is computed as CRC16(key) mod 16384 , so which node a ...

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 right fit when a single master's capacity (memory and ...

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, subjectivel...

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 enters queuing mod...

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 collections — Redis automatically stores smal...

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 , maxmemory , and me...

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 maxmemory-poli...

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 and replication. flowcha...

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 across a sequence of separate commands, where Redis offers ...

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). Ordered by an exp...

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 key is only set if it doesn't already exist (so only one client ca...

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 types offer. XGROUP CRE...

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 — live dashboards, real-time notific...

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 — instead of relying on server-local in-memory sessi...

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 a new table, move every entry, free the old one) would briefly block every ...

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 yes appendfsync everysec auto-aof-rewri...

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. Sharding logic implemented entirely in applicat...

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 the middle, the same guarantee a single native command gets. -...

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 sense when messaging is a second...

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 shared-password requirepass model, which offered no p...

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 of keys, that can mean a multi-second (or longer) f...

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 that support it well. # pseudoc...

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 hash slot, e.g. via CRC16] --> B[Client sends command to th...

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 a replica's data can lag slightly behind the master at a...

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 consistency (every replica always refl...

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 — a database that was comfortably handling load with the cache in front...

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 that initial transfer. Disk-based Replication Diskless Replication M...

Read full answer

«
»

Comments & Discussions