Protected mode in Redis - Time & Space Complexity
We want to understand how the time cost changes when Redis runs in protected mode.
Specifically, how does enabling protected mode affect the speed of commands?
Analyze the time complexity of the following Redis commands when protected mode is enabled.
# Check if protected mode is on
CONFIG GET protected-mode
# Try to run a command from an external client
PING
# Disable protected mode (requires config set)
CONFIG SET protected-mode no
# Run the same command again
PING
This snippet shows checking protected mode status and how commands behave with it on or off.
Look for repeated checks or command executions that affect time.
- Primary operation: Checking protected mode status and processing commands.
- How many times: Each command runs once, but protected mode check happens internally for each connection.
Protected mode adds a simple check per connection, which does not grow with data size.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks + 10 commands |
| 100 | 100 checks + 100 commands |
| 1000 | 1000 checks + 1000 commands |
Pattern observation: The time grows linearly with the number of commands, but the protected mode check itself is a simple constant-time operation per connection.
Time Complexity: O(n)
This means the time to process commands grows directly with how many commands you send, and protected mode adds only a small constant check each time.
[X] Wrong: "Protected mode makes Redis commands much slower because it adds heavy security checks."
[OK] Correct: Protected mode only adds a quick check per connection, so it does not slow down each command significantly.
Understanding how small security features affect performance helps you explain trade-offs clearly in real projects.
"What if protected mode checked every command in detail instead of just once per connection? How would the time complexity change?"