8.5 Redis Commands, Expiration, SCAN and Pipelining (Week 8 • Redis & Performance)
1. Core Concept & Internal Working
Redis Commands, Expiration, SCAN and Pipelining (Redis & Performance) covers `EXPIRE`/`PEXPIRE`, `TTL`/`PTTL`, cursor-based `SCAN 0 MATCH prefix:* COUNT 100`, `UNLINK` (async non-blocking memory free vs blocking `DEL` on huge keys!), and `redis.pipeline()` batching `20` commands into `1` TCP round-trip!. In production software engineering, it is used to Using `pipeline()` to execute 15 Redis commands in `0.6ms` (`1` RTT) instead of `15 * 0.6ms = 9ms` sequential! Mastering its underlying execution rules and edge-case boundaries lets you write reliable, maintainable code.
2. Real-World Engineering Use Case
Using `pipeline()` to execute 15 Redis commands in `0.6ms` (`1` RTT) instead of `15 * 0.6ms = 9ms` sequential!
3. Granular Subtopics Covered
- `EXPIRE`/`PEXPIRE`: Core foundation of Redis Commands, Expiration, SCAN and Pipelining: Using `pipeline()` to execute 15 Redis commands in `0.6ms` (`1` RTT) instead of `15 * 0.6ms = 9ms` sequential!
- `TTL`/`PTTL`: Master '`TTL`/`PTTL`' inside Redis Commands, Expiration, SCAN and Pipelining across real-world inputs.
- Cursor-based `SCAN 0 MATCH prefix:* COUNT 100`: Master 'Cursor-based `SCAN 0 MATCH prefix:* COUNT 100`' inside Redis Commands, Expiration, SCAN and Pipelining across real-world inputs.
- `UNLINK` (async non-blocking memory free vs blocking `DEL` on huge keys!): Master '`UNLINK` (async non-blocking memory free vs blocking `DEL` on huge keys!)' inside Redis Commands, Expiration, SCAN and Pipelining across real-world inputs.
- Production Pitfall Guard (Redis Commands, Expiration, SCAN and Pipelining): Prevent common defect: Calling `DEL` on a 2-million-member Set synchronously instead of non-blocking `UNLINK`!
- Hands-On Verification (Redis Commands, Expiration, SCAN and Pipelining): Implement prefix invalidation using `scanStream` + batched `UNLINK` pipeline (zero `KEYS`!).
4. Reference Implementation
// Production Redis rules: SCAN (never KEYS *); UNLINK large keys (never blocking DEL); pipeline() multi-ops!
5. Common Mistakes to Avoid
- Calling `DEL` on a 2-million-member Set synchronously instead of non-blocking `UNLINK`!
- Skipping boundary, null/empty, or error-state verification when implementing Redis Commands, Expiration, SCAN and Pipelining.
- Pushing untested Redis Commands, Expiration, SCAN and Pipelining changes without clean naming and Git commit context.
6. Hands-On Exercise
Implement prefix invalidation using `scanStream` + batched `UNLINK` pipeline (zero `KEYS`!).
7. Technical Interview Checkpoints
- Q: What problem does Redis Commands, Expiration, SCAN and Pipelining solve in Redis & Performance, and what fails if it is misused?
Key Focus: Using `pipeline()` to execute 15 Redis commands in `0.6ms` (`1` RTT) instead of `15 * 0.6ms = 9ms` sequential! Guard against: Calling `DEL` on a 2-million-member Set synchronously instead of non-blocking `UNLINK`! - Q: Explain the internal working of Redis Commands, Expiration, SCAN and Pipelining (`EXPIRE`/`PEXPIRE`, `TTL`/`PTTL`, cursor-based `SCAN 0 MATCH prefix:* COUNT 100`, `UNLINK` (async non-blocking memory free vs blocking `DEL` on huge keys!), and `redis.pipeline()` batching `20` commands into `1` TCP round-trip!).
Key Focus: Walk step-by-step through `EXPIRE`/`PEXPIRE`, `TTL`/`PTTL`, cursor-based `SCAN 0 MATCH prefix:* COUNT 100`, `UNLINK` (async non-blocking memory free vs blocking `DEL` on huge keys!), and `redis.pipeline()` batching `20` commands into `1` TCP round-trip! with a concrete code example. - Q: How did you apply and verify Redis Commands, Expiration, SCAN and Pipelining in your hands-on lab?
Key Focus: Implement prefix invalidation using `scanStream` + batched `UNLINK` pipeline (zero `KEYS`!).