CLOUD
Guides

Redis: Setting Up Caching to Speed Up Your App

CLOUD|February 5, 2026|Updated September 6, 2026|3 min read|494 views
Redis: Setting Up Caching to Speed Up Your App

Redis stores repeated data in memory. Speeds up your app 10-100x. We explain installation and setup with Laravel.

What Is Redis and Why Do You Need It?

Redis is an in-memory data store that functions as an extremely fast database, cache service, and message broker. Its response time is measured in microseconds compared to milliseconds for traditional databases.

Why Redis specifically?

  • Maximum speed: processes over one million operations per second
  • Multiple data types: strings, lists, sets, hashes, sorted sets
  • Built-in TTL: automatic data expiration
  • Pub/Sub: built-in messaging system
  • Optional persistence: data saved to disk

Installation on Ubuntu

# Update system
apt update && apt upgrade -y

# Install Redis
apt install redis-server -y

# Start and enable on boot
systemctl start redis-server
systemctl enable redis-server

# Verify installation
redis-cli ping
# PONG

# Show server information
redis-cli info server

Basic Configuration

nano /etc/redis/redis.conf
# Memory limit (50% of server RAM as a baseline)
maxmemory 2gb

# Eviction policy when memory is full
maxmemory-policy allkeys-lru

# Listen on localhost only (more secure)
bind 127.0.0.1

# Password (optional but recommended)
requirepass your_strong_password_here

# Data persistence settings
save 900 1
save 300 10
save 60 10000
# Restart after modification
systemctl restart redis-server

Integration with Laravel

# Install predis library
composer require predis/predis

# Or use phpredis (faster)
pecl install redis
echo "extension=redis.so" >> /etc/php/8.2/fpm/conf.d/redis.ini
# .env
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=your_strong_password_here
REDIS_PORT=6379

Caching Strategies

Cache Aside (Most Common)

// Application checks cache first
$product = Cache::remember("product:{$id}", 3600, function use ($id) {
 return Product::with('category', 'images')->find($id);
});
// Store a group of data under one tag
Cache::tags(['products', 'category:electronics'])->put(
 "product:{$id}",
 $product,
 3600
);

// Flush all product-related cache at once
Cache::tags(['products'])->flush;

Session Data Caching

// config/session.php
'driver' => env('SESSION_DRIVER', 'redis'),
'lifetime' => 120,

// This significantly reduces database pressure
// because session reads are very frequent on every request

Redis as Queue Driver

// config/queue.php
'redis' => [
 'driver' => 'redis',
 'connection' => 'default',
 'queue' => env('REDIS_QUEUE', 'default'),
 'retry_after' => 90,
 'block_for' => null,
],

// Dispatch job
SendWelcomeEmail::dispatch($user)->onQueue('emails');

// Run worker
php artisan queue:work redis --queue=emails --tries=3

Redis Pub/Sub for Real-Time Notifications

// Subscriber (listening)
Redis::subscribe(['notifications'], function (string $message) {
 $data = json_decode($message, true);
 // Process notification
});

// Publisher (sending)
Redis::publish('notifications', json_encode([
 'user_id' => 123,
 'message' => 'Your server is ready',
 'type' => 'server_ready',
]));

Monitoring Redis

# Real-time monitoring
redis-cli monitor

# Detailed statistics
redis-cli info stats

# Cache hit/miss rate
redis-cli info stats | grep -E "keyspace_hits|keyspace_misses"

# Show all keys (dev only)
redis-cli keys "*"

# Size of a specific value
redis-cli debug object "cache:product:123"

Key Metrics to Monitor

Metric Target Action
Hit Rate > 90% Review caching strategy
Memory Usage < 80% Increase maxmemory or upgrade server
Connected Clients < 500 Enable connection pooling
Evicted Keys Should be 0 Increase maxmemory

Redis vs Memcached Comparison

Feature Redis Memcached
Data Types Multiple Strings only
Persistence Yes No
Pub/Sub Yes No
Clustering Yes Limited
Common Use cache + queue + session Cache only

Recommendation: Always use Redis. There is no reason to choose Memcached for new projects.

On cloud.net.sa Servers

cloud.net.sa servers use NVMe SSDs and modern processors, allowing Redis to operate at maximum efficiency. When setting up your application, you can dedicate 25-50% of RAM to Redis and 50-75% to the application itself. With the option to add RAM at 600 SAR per 2GB, scaling is straightforward.

Summary

Redis is not optional — it is a necessity for any serious application. Installation takes 10 minutes and Laravel integration takes 30 minutes. The performance impact is immediate: faster response times, reduced database pressure, and an application that handles several times the traffic with the same resources.

Share