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?"
Practice
protected-mode?Solution
Step 1: Understand what protected mode does
Protected mode is designed to keep Redis safe by limiting who can connect to it.Step 2: Identify the main purpose
It prevents unauthorized access by restricting connections unless properly configured.Final Answer:
To limit connections and keep Redis safe by default -> Option BQuick Check:
Protected mode = Limits connections [OK]
- Thinking it improves performance
- Confusing it with backup features
- Assuming it allows open access
Solution
Step 1: Identify the correct syntax for the setting
The Redis config usesprotected-modewith a dash, not underscore or other variations.Step 2: Determine the value to disable it
Settingprotected-mode nodisables protected mode.Final Answer:
protected-mode no -> Option AQuick Check:
Disable protected mode = protected-mode no [OK]
- Using underscore instead of dash
- Setting value to 'yes' to disable
- Using invalid config keys
protected-mode yes bind 127.0.0.1
What will happen if a client tries to connect from a remote IP?
Solution
Step 1: Analyze protected mode and bind settings
Protected mode is enabled and Redis is bound only to localhost (127.0.0.1).Step 2: Understand remote connection behavior
Clients from remote IPs cannot connect because Redis listens only on localhost and protected mode blocks unsafe access.Final Answer:
Connection will be rejected due to protected mode and bind settings -> Option AQuick Check:
Protected mode + bind localhost = reject remote [OK]
- Assuming remote connections are allowed
- Thinking Redis crashes on remote connect
- Believing password alone allows connection
protected-mode no in your Redis config but remote clients still cannot connect. What is the most likely cause?Solution
Step 1: Check the effect of disabling protected mode
Disabling protected mode allows remote connections if no other restrictions exist.Step 2: Identify other config restrictions
Ifbind 127.0.0.1is set, Redis only listens on localhost, blocking remote clients.Final Answer:
Thebindsetting restricts connections to localhost -> Option CQuick Check:
Bind localhost blocks remote even if protected mode off [OK]
- Assuming protected mode disables instantly without config reload
- Ignoring bind restrictions
- Thinking password is mandatory for remote connect
Solution
Step 1: Understand risks of disabling protected mode
Disabling protected mode requires securing Redis by other means like authentication.Step 2: Combine settings for safe remote access
Binding to all interfaces (0.0.0.0) allows remote connections, but a strong password is needed to secure access.Final Answer:
Disable protected mode, bind to all interfaces, and require a strong password -> Option DQuick Check:
Safe remote access = disable protected mode + bind all + password [OK]
- Disabling protected mode without password
- Binding only to localhost for remote access
- Allowing open access without authentication
Ready to prove it?
Pass the test and this pattern moves unknown
