Title: Redis Data Structures And Use Cases — LearnCoachAssist

Q: What does the acronym Redis stand for?
A: REmote DIctionary Server

Q: In which language is Redis written?
A: C

Q: What is the default port number for Redis?
A: 6379

Q: How is Redis primarily classified architecturally?
A: An in-memory key-value data store used as a database, cache, and message broker

Q: Which is the most basic Redis data type, storing a single binary-safe value per key?
A: String

Q: What is the maximum size of a single string value in Redis?
A: 512 MB

Q: What does the GETSET command do?
A: Atomically sets a key to a new value and returns the previous one

Q: What is the difference between SETNX and SET with the NX option?
A: SETNX is the legacy form; SET ... NX is the modern atomic form that also supports expiration

Q: Which command atomically sets a value only if the key already exists?
A: SET key value XX

Q: What is the difference between SETEX and SET with PX?
A: SETEX takes seconds; SET ... PX takes milliseconds for finer TTL control

Q: What command atomically increments the integer value of a key?
A: INCR

Q: What happens if you run INCR on a key whose value is not an integer?
A: Redis returns an error

Q: Which command appends a value to an existing string?
A: APPEND

Q: What command returns the length of a string value?
A: STRLEN

Q: What does MGET do?
A: Returns the values of multiple keys in a single round trip

Q: Which Redis type stores an unordered collection of unique strings?
A: Set

Q: What is the time complexity of SADD?
A: O(1) per element added

Q: What is the time complexity of SMEMBERS?
A: O(N) where N is the set size

Q: What does SISMEMBER do?
A: Returns 1 if the member is in the set, 0 otherwise

Q: What is the difference between SMEMBERS and SSCAN?
A: SMEMBERS returns the full set in one call; SSCAN iterates incrementally with a cursor, avoiding blocking on large sets

Q: What does SUNIONSTORE do?
A: Stores the union of multiple sets into a destination key

Q: What does SDIFF return?
A: The set of members in the first set that are not in the others

Q: What command returns random members from a set without removing them?
A: SRANDMEMBER

Q: What is the difference between SRANDMEMBER and SPOP?
A: SRANDMEMBER does not remove the element; SPOP removes and returns it

Q: What is a typical use case for Redis Sets?
A: Tagging, unique visitor tracking, and set-intersection recommendations

Q: Which Redis type stores an ordered collection of unique members with a score per member?
A: Sorted Set (ZSET)

Q: What data structure backs a Sorted Set?
A: A skip list plus a hash table

Q: What is the time complexity of ZADD?
A: O(log N)

Q: Which command returns the rank of a member with 0 meaning the highest score?
A: ZREVRANK

Q: What does ZSCORE return?
A: The score of a member, or nil if it does not exist

Q: What is the difference between ZRANGE and ZRANGEBYSCORE?
A: ZRANGE selects by index range; ZRANGEBYSCORE selects by score range

Q: Which command atomically increments a member's score?
A: ZINCRBY

Q: What is a typical use case for Sorted Sets?
A: Leaderboards, rate limiting by time, and time-series indexes

Q: How can a Sorted Set implement a sliding-window rate limiter?
A: Store timestamps as scores; use ZREMRANGEBYSCORE to drop old entries and ZCARD to count recent ones

Q: Which Redis type is an ordered list of strings by insertion order?
A: List

Q: What underlying structure backs a small Redis list?
A: A listpack (previously ziplist)

Q: What is the time complexity of LPUSH?
A: O(1)

Q: Which list command blocks until an element is available or a timeout elapses?
A: BRPOP or BLPOP

Q: What is the classic producer/consumer pattern built with Redis Lists?
A: LPUSH to enqueue and BRPOP to dequeue gives a simple message queue

Q: What is the difference between LPUSH and RPUSH?
A: LPUSH inserts at the head (left); RPUSH inserts at the tail (right)

Q: What does LTRIM do?
A: Removes elements outside the specified index range, modifying the list in place

Q: How would you implement a recent-activity feed with a Redis List?
A: LPUSH new items and LTRIM to keep only the latest N items

Q: What command returns the length of a list?
A: LLEN

Q: What does LMOVE do that RPOPLPUSH also did?
A: Atomically pops an element from one list and pushes it to another, with a configurable direction

Q: Which Redis type maps field-value pairs within a single key?
A: Hash

Q: What is the time complexity of HGET?
A: O(1)

Q: What does HGETALL return?
A: All fields and values in the hash as a flat list

Q: What is the difference between HGETALL and HVALS?
A: HGETALL returns fields and values; HVALS returns only values

Q: Which command increments the integer value of a hash field?
A: HINCRBY

Q: What is a typical use case for Redis Hashes?
A: Storing object attributes (e.g., user, product, session) under one key

Q: Why prefer a Hash over many String keys for an object?
A: Hashes use less memory and allow partial-field reads and writes

Q: What command removes one or more fields from a hash?
A: HDEL

Q: What command sets the TTL on a single hash field?
A: HEXPIRE (Redis 7.4+)

Q: What is a Redis Stream?
A: An append-only log data structure with consumer groups, message IDs, and acknowledgments

Q: What is the structure of a Redis Stream entry ID?
A: Milliseconds-time plus a sequence number for that millisecond

Q: Which command appends an entry to a stream?
A: XADD

Q: Which command reads entries from one or more streams?
A: XREAD

Q: What does XREADGROUP enable?
A: Consuming a stream in a consumer group so each entry is delivered to only one consumer

Q: What is the purpose of XACK?
A: Acknowledges processing of a stream entry so it can be trimmed or deleted

Q: What does XADD with the MAXLEN ~ N option do?
A: Approximate trimming of a stream to roughly N most recent entries with low overhead

Q: What problem do Streams solve compared to Pub/Sub or Lists?
A: Durable, replayable messaging with per-consumer delivery and acknowledgment

Q: What is a Redis HyperLogLog used for?
A: Counting unique items with a fixed 12 KB footprint regardless of cardinality

Q: What is the typical error rate of a HyperLogLog?
A: About 0.81% standard error

Q: What is the time complexity of PFADD and PFCOUNT?
A: O(1) per key

Q: What is a typical use case for HyperLogLog?
A: Daily unique visitors, unique queries, or unique IPs

Q: What is a Redis Bitmap?
A: A string value treated as an array of bits addressable by index via SETBIT/GETBIT

Q: What command sets a single bit at an offset in a bitmap?
A: SETBIT

Q: Which command performs bitwise operations across multiple keys?
A: BITOP (AND, OR, XOR, NOT)

Q: What is a typical use case for Redis Bitmaps?
A: Daily active user tracking, feature flags, or boolean state per user

Q: What backs a Redis geospatial index?
A: A sorted set with latitude/longitude encoded as a 52-bit geohash score

Q: Which command adds a location to a geospatial index?
A: GEOADD

Q: Which command returns places within a given radius?
A: GEOSEARCH (replaces GEORADIUS from Redis 6.2)

Q: What does GEODIST return?
A: The distance between two members of a geospatial index

Q: What is the time complexity of GEOSEARCH?
A: O(N + log M) where N is items in the radius and M is the total

Q: What is a Bloom filter used for in Redis?
A: A probabilistic membership test with possible false positives but no false negatives

Q: Which Redis module provides Bloom and Cuckoo filters?
A: RedisBloom

Q: What is a typical use case for a Bloom filter?
A: Avoiding expensive database lookups for likely-nonexistent keys (e.g., username or cache-miss checks)

Q: What is a Redis keyspace notification?
A: An event published on a channel when a key is created, modified, expired, or evicted

Q: Which configuration enables keyspace notifications?
A: notify-keyspace-events in redis.conf

Q: How do you subscribe to expiration events?
A: Subscribe to __keyevent@0__:expired (or the relevant db index)

Q: What is Redis key eviction controlled by?
A: The maxmemory directive and the maxmemory-policy

Q: What does the volatile-lru policy do?
A: Evicts the least recently used keys among those with a TTL

Q: What does the allkeys-lru policy do?
A: Evicts the least recently used keys regardless of TTL

Q: What does the noeviction policy do?
A: Returns write errors when memory is full instead of evicting any data

Q: What is the default maxmemory-policy in Redis?
A: noeviction

Q: What does the volatile-ttl policy do?
A: Evicts the key with the shortest remaining TTL among keys that have one

Q: What is the LFU eviction policy?
A: Evicts the least frequently used keys (volatile-lfu or allkeys-lfu)

Q: How does Redis persist data via RDB?
A: Point-in-time snapshots are written to dump.rdb at configured intervals

Q: What does AOF persistence do?
A: Appends every write command to appendonly.aof, which is replayed at restart

Q: What is the purpose of AOF rewrite?
A: Compacts the AOF file from the current dataset to keep it from growing unbounded

Q: What does appendfsync everysec mean?
A: AOF is fsynced once per second, balancing durability and performance

Q: What is the main durability difference between RDB and AOF?
A: AOF with appendfsync always is stronger; RDB may lose the last seconds or minutes of writes

Q: What is the default RDB save rule in redis.conf?
A: Snapshot after 1 hour if ≥1 change, after 5 min if ≥100, after 1 min if ≥10000

Q: What is Redis replication?
A: Replica nodes asynchronously copy data from a primary to provide read scaling and HA

Q: What is the role of WAIT in Redis?
A: Blocks the client until a given number of replicas acknowledge the write

Q: What is Redis Sentinel?
A: A built-in HA system that monitors masters/replicas and performs automatic failover

Q: What is Redis Cluster?
A: A native sharding solution that distributes keys across nodes using 16384 hash slots

Q: How are keys mapped to hash slots in Redis Cluster?
A: CRC16(key) mod 16384

Q: What is a hash tag?
A: A substring within { } braces used by Cluster to force keys into the same slot

Q: What is a CROSSSLOT error?
A: Returned when a multi-key command touches keys in different slots

Q: What is the difference between a MOVED and an ASK redirection?
A: MOVED is permanent and points to the slot's owner; ASK is a transient hint during slot migration

Q: What is the recommended minimum Redis Cluster topology for production?
A: 3 masters with 1 replica each (6 nodes) for availability

Q: What is a Redis transaction?
A: A group of commands executed atomically using MULTI and EXEC, isolated from other clients

Q: What does WATCH do?
A: Monitors a key for changes; if it is modified before EXEC, the transaction aborts

Q: What is the difference between MULTI/EXEC and a Lua script?
A: Both are atomic, but Lua supports conditional logic and complex cross-key operations

Q: What does EVALSHA do?
A: Runs a previously cached Lua script by its SHA1 hash to avoid resending the script body

Q: What is a NOSCRIPT error?
A: Returned when EVALSHA is called but the script is not in the cache; clients should fall back to EVAL

Q: What is Redis Pub/Sub?
A: A messaging model where publishers send to channels and subscribers receive in real time

Q: What is the main limitation of Pub/Sub compared to Streams?
A: Pub/Sub is fire-and-forget: messages are not stored and are lost without a subscriber

Q: Which command subscribes to messages matching a glob pattern?
A: PSUBSCRIBE

Q: What is the SCAN command?
A: A cursor-based iterator over the keyspace that does not block the server

Q: What is the difference between KEYS and SCAN?
A: KEYS returns all matches in one blocking call; SCAN iterates in small batches and is safe on large datasets

Q: What does MATCH do inside SCAN?
A: Filters returned keys to a glob pattern

Q: What is the purpose of the TYPE command?
A: Returns the data type stored at a key (string, list, set, zset, hash, stream)

Q: What does OBJECT ENCODING reveal?
A: The internal encoding of a key, e.g., embstr, int, listpack, skiplist, or hashtable

Q: What is an embstr-encoded string?
A: A small string up to 44 bytes stored inline in the Redis object to save memory

Q: What does OBJECT IDLETIME return?
A: The seconds since the last access of a stored object

Q: What is the purpose of the SLOWLOG?
A: Records commands exceeding a configurable time threshold for diagnostics

Q: Which command returns server statistics and configuration?
A: INFO

Q: What does used_memory represent?
A: The total bytes Redis has allocated to store data, including overhead