Why configuration matters in Redis - Performance Analysis
When using Redis, the way it is set up can change how fast commands run.
We want to see how configuration affects the time it takes to do tasks.
Analyze the time complexity of the following Redis commands with different configurations.
# Using default maxmemory policy
CONFIG SET maxmemory 100mb
CONFIG SET maxmemory-policy noeviction
# Adding keys
SET key1 value1
SET key2 value2
...
SET keyN valueN
# Using volatile-lru policy
CONFIG SET maxmemory-policy volatile-lru
This snippet shows changing Redis memory settings and adding keys under different eviction policies.
Look for repeated actions that affect performance.
- Primary operation: Adding keys with SET command repeatedly.
- How many times: Once per key, so N times for N keys.
- Additional operation: Eviction checks when memory limit is reached, depending on policy.
As more keys are added, Redis may need to remove old keys if memory is full.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 SET commands, few or no evictions |
| 100 | 100 SET commands, some evictions if memory full |
| 1000 | 1000 SET commands, many evictions depending on policy |
Pattern observation: More keys mean more work, especially if eviction policy triggers extra steps.
Time Complexity: O(n)
This means the time grows roughly in direct proportion to the number of keys added, but configuration can add extra work per key.
[X] Wrong: "Changing configuration does not affect command speed."
[OK] Correct: Some settings cause Redis to do extra work like evicting keys, which slows down commands as data grows.
Understanding how configuration affects performance shows you know how systems work beyond just writing commands.
"What if we changed the eviction policy to noeviction? How would the time complexity change when memory is full?"