Rename dangerous commands in Redis - Time & Space Complexity
When we rename dangerous commands in Redis, we want to see how the time to do this changes as we rename more commands.
We ask: How does the work grow when we rename many commands?
Analyze the time complexity of the following Redis commands.
CONFIG SET rename-command CONFIG ""
CONFIG SET rename-command FLUSHALL ""
CONFIG SET rename-command SHUTDOWN ""
CONFIG SET rename-command DEBUG ""
This code renames or disables dangerous Redis commands by setting their new names to empty strings.
Look for repeated actions in the code.
- Primary operation: Each CONFIG SET command renames one dangerous command.
- How many times: Once per command you want to rename or disable.
As you rename more commands, the total work grows in a simple way.
| Input Size (n) | Approx. Operations |
|---|---|
| 1 | 1 operation |
| 5 | 5 operations |
| 10 | 10 operations |
Pattern observation: The work grows directly with the number of commands renamed. More commands mean more operations.
Time Complexity: O(n)
This means the time to rename commands grows in a straight line with how many commands you rename.
[X] Wrong: "Renaming one command will take the same time as renaming many commands at once."
[OK] Correct: Each rename is a separate action, so doing more commands takes more time, not the same.
Understanding how work grows when renaming commands helps you think about managing Redis safely and efficiently in real projects.
"What if we batch rename commands in a single CONFIG SET call? How would the time complexity change?"
Practice
Solution
Step 1: Understand the purpose of renaming commands
Renaming dangerous commands helps avoid accidental execution that could harm data or server stability.Step 2: Evaluate other options
Speed, memory, or user concurrency are not affected by renaming commands.Final Answer:
To prevent accidental or harmful use of those commands -> Option CQuick Check:
Renaming commands = Safety [OK]
- Thinking renaming improves performance
- Believing renaming makes commands easier to remember
- Confusing renaming with user access control
FLUSHALL command to disable it in Redis configuration?Solution
Step 1: Recall Redis rename-command syntax
To disable a command, rename it to an empty string "" in redis.conf or via CONFIG SET.Step 2: Check each option
Only rename-command FLUSHALL "" uses the empty string "" which disables the command.Final Answer:
rename-command FLUSHALL "" -> Option AQuick Check:
Disable command = rename to empty string [OK]
- Using words like 'disable' or 'off' instead of empty string
- Forgetting to use quotes around empty string
- Confusing rename-command syntax with other commands
rename-command CONFIG "", what happens when a client tries to run the CONFIG command?Solution
Step 1: Understand renaming to empty string effect
Renaming a command to "" disables it, so Redis will reject attempts to run it.Step 2: Analyze client behavior
Clients trying to run CONFIG will get an error because the command is disabled.Final Answer:
The command is disabled and returns an error -> Option DQuick Check:
Rename to "" disables command = error on use [OK]
- Assuming command still runs normally
- Thinking command runs partially
- Confusing rename with aliasing
DEL command to an empty string to disable it, but your application still deletes keys. What is the most likely cause?Solution
Step 1: Understand command disabling effect
Disabling DEL by renaming to "" should block DEL usage.Step 2: Consider alternative commands
Redis has other commands like UNLINK that also delete keys and may be used by the app.Final Answer:
The application uses a different command likeUNLINKto delete keys -> Option AQuick Check:
Other delete commands bypass DEL disable [OK]
- Assuming disabling DEL disables all delete operations
- Believing Redis does not support renaming commands
- Ignoring alternative commands in the app
FLUSHDB and FLUSHALL commands but keep DEL enabled. Which configuration lines correctly achieve this?Solution
Step 1: Identify correct syntax to disable commands
Disabling commands requires renaming them to empty string "".Step 2: Check which commands to disable
Only FLUSHDB and FLUSHALL should be disabled; DEL remains enabled.Step 3: Evaluate options
rename-command FLUSHDB "" rename-command FLUSHALL "" disables FLUSHDB and FLUSHALL correctly; others disable wrong commands or use invalid syntax.Final Answer:
rename-command FLUSHDB "" rename-command FLUSHALL "" -> Option BQuick Check:
Disable FLUSHDB and FLUSHALL only by renaming to "" [OK]
- Disabling DEL when it should stay enabled
- Using invalid rename-command values like 'off' or 'disable'
- Forgetting to rename both commands
Ready to prove it?
Pass the test and this pattern moves unknown
