0
0
Redisquery~10 mins

Maxmemory setting in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Maxmemory setting
Start Redis Server
Check maxmemory config
Is maxmemory set?
NoUse unlimited memory
Yes
Limit memory usage to maxmemory
When memory usage > maxmemory
Apply eviction policy
Free memory
Continue running
Redis starts and checks if maxmemory is set. If yes, it limits memory usage and applies eviction when needed.
Execution Sample
Redis
CONFIG SET maxmemory 100mb
INFO memory
-- simulate memory usage --
-- memory > 100mb triggers eviction --
Set maxmemory to 100mb and observe memory usage and eviction when limit exceeded.
Execution Table
StepActionMemory Usagemaxmemory SettingEviction TriggeredResult
1Start Redis server0mbNot setNoServer runs with unlimited memory
2Set maxmemory to 100mb0mb100mbNoMemory limit applied
3Memory usage grows to 80mb80mb100mbNoNo eviction needed
4Memory usage grows to 105mb105mb100mbYesEviction policy activated
5Eviction frees 20mb85mb100mbNoMemory usage below limit
6Memory usage stable at 85mb85mb100mbNoServer continues running
💡 Memory usage is controlled by maxmemory; eviction triggers when usage exceeds limit.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
Memory Usage0mb0mb80mb105mb85mb85mb
maxmemoryNot set100mb100mb100mb100mb100mb
Eviction TriggeredNoNoNoYesNoNo
Key Moments - 3 Insights
Why does Redis start without any memory limit if maxmemory is not set?
As shown in execution_table row 1, if maxmemory is not set, Redis uses unlimited memory by default.
When exactly does Redis trigger eviction?
Eviction triggers when memory usage exceeds maxmemory, as seen in execution_table row 4 where usage is 105mb > 100mb.
Does eviction reduce memory usage below maxmemory immediately?
Yes, eviction frees memory to bring usage below maxmemory, shown in row 5 where usage drops from 105mb to 85mb.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the maxmemory setting after step 2?
ANot set
B100mb
C0mb
DUnlimited
💡 Hint
Check the 'maxmemory Setting' column at step 2 in the execution_table.
At which step does eviction get triggered according to the execution_table?
AStep 5
BStep 3
CStep 4
DStep 6
💡 Hint
Look at the 'Eviction Triggered' column to find when it changes to 'Yes'.
If maxmemory was set to 200mb instead of 100mb, what would happen at step 4?
AMemory usage would be below maxmemory, no eviction
BEviction would trigger
CRedis would crash
DMemory usage would reset to 0
💡 Hint
Compare memory usage at step 4 (105mb) with a hypothetical maxmemory of 200mb.
Concept Snapshot
Maxmemory setting limits Redis memory use.
If memory usage exceeds maxmemory, eviction frees memory.
Without maxmemory, Redis uses unlimited memory.
Set maxmemory with CONFIG SET maxmemory <bytes>.
Eviction policy controls which keys to remove.
Helps prevent Redis from using too much RAM.
Full Transcript
Redis starts and checks if maxmemory is set. If not set, Redis uses unlimited memory. When maxmemory is set, Redis limits memory usage to that value. If memory usage grows beyond maxmemory, Redis triggers eviction to free memory. Eviction reduces memory usage below the limit so Redis can continue running smoothly. This process repeats as memory usage changes. Setting maxmemory helps control Redis memory consumption and avoid crashes.