My Redis Adventure: A Sysadmin's Morning - Life-Saving Terminal Commands
It was early in the morning... As usual, I was going through my routine tasks. Servers looked fine, logs were clean, everything seemed under control. Until—Redis, the cache server I used in my Drupal project, crashed out of nowhere.
Redis had been my loyal companion for years. It ran locally, did its job quietly, and never complained. But that morning... it had enough and said:
"I'm not working today, ustad!"
First thing I did—check the Redis service status:
systemctl status redis
Glorious red error screen. The service wouldn't stop, nor would it start properly.
Straight into the logs:
journalctl -u redis --since "1 hour ago"
The cause? The database had ballooned. Redis had become a RAM monster, locking up the system with a 17 GB dump.rdb
file.
Disk check:
df -h
RAM check:
htop
I couldn't believe my eyes. A Redis instance meant for caching had grown to 17 GB?! Time for action.
I shut down Redis and backed up the files:
systemctl stop redis
cp /var/lib/redis/dump.rdb /root/dump.rdb.backup
cp /var/lib/redis/appendonly.aof /root/appendonly.aof.backup
mv /var/lib/redis/dump.rdb /var/lib/redis/dump.rdb.old
mv /var/lib/redis/appendonly.aof /var/lib/redis/appendonly.aof.old
Then brought Redis up clean:
systemctl start redis
But was that enough? Of course not. A smart sysadmin learns from mistakes. It was high time to set a memory limit for Redis.
Edited the Redis config:
nano /etc/redis/redis.conf
Added the following:
maxmemory 4gb
maxmemory-policy allkeys-lru
Then restarted the service:
systemctl restart redis
And there it was... Clean system, memory under control, Redis behaving like a gentleman.
What did I learn from this adventure?
Never use Redis like a database
Always set a memory limit
Never operate without backups
Always read your logs
With patience, composure, and terminal skills—any issue can be solved
And so, as the morning calmed down, I took a sip of my coffee and gave the terminal one last glance:
redis-cli ping
The response:
PONG
As every seasoned sysadmin would say: "Server's up, system's stable, life's good."
See you in the next terminal tale!