Redis hard
Why is calling non-deterministic functions like `TIME` or `RANDOMKEY` considered dangerous inside a Lua script when using standard statement-based replication?
- A The script will immediately crash if it detects any system-level library call that is not thread-safe.
- B Non-determinism causes data divergence because the Master and Replica nodes will generate different return values.
- C Lua does not support integer-based numerical precision, leading to rounding errors in high-velocity analytical queries.
- D External library calls bypass the internal Redis Lock Manager, potentially leading to hard system deadlocks.
Answer: B. Non-determinism causes data divergence because the Master and Replica nodes will generate different return values.
If a script calculates 'x = RANDOM()', the Master writes one value, and the Replica (re-running the script) calculates a different one. To fix this, modern Redis often replicates the 'Resulting Commands' rather than the 'Source Script' itself.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- If the Redis memory limit is reached, what specific behavior is exhibited by the `allkeys-lru` eviction policy?
- What is the defining characteristic of a Redis 'Set' data type compared to a standard Redis 'List'?
- In the context of Redis messaging, what is the functional definition of the 'Pub/Sub' feature?
- How does the Redis background snapshotting process (`BGSAVE`) leverage the operating system's `fork()` mechanism to minimize memory overhead?
- Why does Redis proactively disconnect a Pub/Sub client that exhibits high 'output buffer' usage relative to its ingestion rate?
- How does a 'Sorted Set' (ZSET) manage its internal membership and ordering differently from a plain Set?