Authentication with requirepass in Redis - Time & Space Complexity
When Redis requires a password, it checks the password each time a client connects. Understanding how this check grows with more clients helps us see if it slows down as more people connect.
We want to know: How does the time to verify a password change as more clients try to connect?
Analyze the time complexity of the following Redis authentication commands.
CONFIG SET requirepass mysecret
# Client tries to authenticate
AUTH mysecret
# Server checks password
# If correct, client is allowed commands
# If wrong, connection is rejected
This snippet sets a password and shows how clients authenticate by sending the password to Redis, which checks it before allowing commands.
Look for repeated actions that affect time.
- Primary operation: Password comparison for each client authentication.
- How many times: Once per client connection that sends AUTH.
Each time a client connects and sends a password, Redis compares it to the stored password.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 clients | 10 password checks |
| 100 clients | 100 password checks |
| 1000 clients | 1000 password checks |
Pattern observation: The number of password checks grows directly with the number of clients trying to authenticate.
Time Complexity: O(n)
This means the total time to handle authentication grows in a straight line as more clients connect and authenticate.
[X] Wrong: "Checking the password takes longer as the password gets longer or more clients connect at once."
[OK] Correct: Redis compares the password in a simple way that takes about the same time regardless of password length, and each check is independent per client, so more clients just add more checks, not slower checks.
Understanding how authentication scales helps you explain how systems stay fast even when many users connect. This skill shows you can think about real-world system behavior clearly.
"What if Redis stored multiple passwords for different users? How would the time complexity of authentication change?"