Skip to content

Redis Commands ​

Redis is the in-memory cache and queue server used by Zal Ultra for caching, sessions, and background job processing.

🟠 MEDIUM RISK

Restarting Redis will clear all cached data and may cause temporary slowdowns. Queue jobs will resume after restart.


Table of Contents ​

  1. Service Management
  2. Redis CLI
  3. Cache Management
  4. Queue Monitoring
  5. Memory Management
  6. Troubleshooting

Service Management ​

Check Redis Status ​

bash
sudo systemctl status redis-server

Start Redis ​

bash
sudo systemctl start redis-server

Stop Redis ​

🟠 CACHE LOSS

Stopping Redis will clear all cached data and interrupt queue processing.

bash
sudo systemctl stop redis-server

Restart Redis ​

🟠 CACHE CLEARED

Restart clears all cached data. Application will rebuild cache on demand.

bash
sudo systemctl restart redis-server

Enable on Boot ​

bash
sudo systemctl enable redis-server

Redis CLI ​

Connect to Redis ​

bash
redis-cli

Ping Redis (Test Connection) ​

bash
redis-cli ping
# Expected: PONG

Check Redis Info ​

bash
redis-cli info

Check Specific Section ​

bash
redis-cli info memory
redis-cli info clients
redis-cli info stats

Cache Management ​

View All Keys (Use with Caution) ​

🟠 PERFORMANCE IMPACT

On large databases, KEYS * can block Redis. Use SCAN instead in production.

bash
redis-cli KEYS "*"

Count All Keys ​

bash
redis-cli DBSIZE

Search Keys by Pattern ​

bash
redis-cli KEYS "laravel_cache:*"
redis-cli KEYS "laravel_database_*"

Get Key Value ​

bash
redis-cli GET "key_name"

Delete Specific Key ​

bash
redis-cli DEL "key_name"

Delete Keys by Pattern ​

🟠 DATA DELETION

This permanently deletes matching keys.

bash
redis-cli KEYS "laravel_cache:*" | xargs redis-cli DEL

Clear All Cache (FLUSHDB) ​

🔴 CLEARS ALL DATA

This removes ALL data from the current database.

bash
redis-cli FLUSHDB

Clear All Databases (FLUSHALL) ​

🔴 CLEARS EVERYTHING

This removes ALL data from ALL Redis databases.

bash
redis-cli FLUSHALL

Clear Laravel Cache via Artisan ​

bash
# Preferred method - clears only Laravel cache
cd /var/www/html
php artisan cache:clear

Queue Monitoring ​

Check Queue Length ​

bash
redis-cli LLEN "queues:default"
redis-cli LLEN "queues:sms"
redis-cli LLEN "queues:high"

View Queue Contents ​

bash
redis-cli LRANGE "queues:default" 0 10

Check Failed Jobs Queue ​

bash
redis-cli LLEN "queues:failed"

Monitor Redis in Real-time ​

bash
redis-cli MONITOR

Press Ctrl+C to stop.


Memory Management ​

Check Memory Usage ​

bash
redis-cli INFO memory

Key Memory Stats ​

bash
redis-cli INFO memory | grep -E "used_memory_human|maxmemory_human|mem_fragmentation"

Check Memory for Specific Key ​

bash
redis-cli MEMORY USAGE "key_name"

Find Largest Keys ​

bash
redis-cli --bigkeys

Set Memory Limit ​

bash
# In redis.conf or via CLI
redis-cli CONFIG SET maxmemory 512mb
redis-cli CONFIG SET maxmemory-policy allkeys-lru

Check Current Memory Policy ​

bash
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy

Troubleshooting ​

Common Issues ​

Redis Won't Start ​

bash
# Check error log
sudo tail -100 /var/log/redis/redis-server.log

# Check permissions
sudo chown -R redis:redis /var/lib/redis

Connection Refused ​

bash
# Check if Redis is running
sudo systemctl status redis-server

# Check if listening
sudo netstat -tlnp | grep 6379

# Check bind address in config
sudo grep "bind" /etc/redis/redis.conf

Memory Full ​

bash
# Check memory usage
redis-cli INFO memory

# Clear old cache
redis-cli FLUSHDB

# Or set memory limit with eviction
redis-cli CONFIG SET maxmemory 1gb
redis-cli CONFIG SET maxmemory-policy allkeys-lru

Slow Performance ​

bash
# Check slow log
redis-cli SLOWLOG GET 10

# Check connected clients
redis-cli CLIENT LIST | wc -l

Configuration File ​

bash
sudo nano /etc/redis/redis.conf

Important Settings ​

conf
# Memory limit
maxmemory 1gb

# Eviction policy
maxmemory-policy allkeys-lru

# Persistence (disable for pure cache)
save ""
appendonly no

# Bind address (localhost only for security)
bind 127.0.0.1

After config changes:

bash
sudo systemctl restart redis-server

Check Redis Version ​

bash
redis-server --version
redis-cli --version

Quick Reference Card ​

ActionCommand
Check statussudo systemctl status redis-server
Startsudo systemctl start redis-server
Stopsudo systemctl stop redis-server
Restartsudo systemctl restart redis-server
Connect CLIredis-cli
Ping testredis-cli ping
Memory inforedis-cli INFO memory
Key countredis-cli DBSIZE
Clear cacheredis-cli FLUSHDB
Queue lengthredis-cli LLEN "queues:default"
Monitorredis-cli MONITOR
Config file/etc/redis/redis.conf
Log file/var/log/redis/redis-server.log

www.onezeroart.com