🔴 Setup Redis — In-Memory Data Store

Deploy Redis on Ubuntu with Docker — the ultra-fast in-memory database used for caching, session storage, queues, and pub/sub messaging. Auto-generates a secure password.

⚠️ This script is provided for demo and testing purposes only. Not intended for production use.

📦 Resources & Setup Scripts

Grab the automated bash script from GitHub to follow along with the video.

Automated install script — auto-generates a secure Redis password.
View on GitHub

Quick Install:

wget https://raw.githubusercontent.com/mhmdali94/Docker/main/databases/redis/redis-ubuntu.sh
chmod +x redis-ubuntu.sh
sudo bash redis-ubuntu.sh

Tutorial Steps

1 Download & Run the Script

The script installs Docker if needed, generates a secure random password, and starts Redis with authentication enabled.

wget https://raw.githubusercontent.com/mhmdali94/Docker/main/databases/redis/redis-ubuntu.sh
chmod +x redis-ubuntu.sh
sudo bash redis-ubuntu.sh

2 Save Your Generated Password

At the end of the script, your auto-generated Redis password is displayed. Save it now — you'll need it to connect.

3 Connect with redis-cli

redis-cli -h <server-ip> -p 6379 -a <generated-password>

4 Test the Connection

Once connected, run a quick test:

PING
# Expected response: PONG

SET mykey "hello"
GET mykey
# Expected response: "hello"

Ports Used

PortPurpose
6379Redis

Overview

Redis (Remote Dictionary Server) is an open-source, in-memory data structure store used as a database, cache, and message broker. It supports strings, hashes, lists, sets, sorted sets, bitmaps, and streams. Its sub-millisecond latency makes it indispensable for applications that require real-time performance.

Why Use It

Redis is the fastest general-purpose data store available — it answers reads and writes in under a millisecond because all data lives in RAM. Any application that queries a slow database repeatedly benefits immediately from a Redis caching layer. Beyond caching, Redis replaces heavyweight message brokers for pub/sub, eliminates the need for sticky sessions in load-balanced deployments, and powers real-time features like live counters and leaderboards.

When You Need It

    Who Should Use It

      Real Use Cases

        Main Features

          How to Use After Installation

            Security Best Practices

              Ports and Firewall Notes

              Redis runs on port 6379 by default. This port must NEVER be open to the public internet — Redis has no built-in rate limiting or brute-force protection. Allow port 6379 only from your application server's private IP. On UFW: ufw allow from <app-server-ip> to any port 6379. If Redis and your app run on the same server, bind Redis to 127.0.0.1 and block external access entirely.

              Backup and Maintenance

                Common Mistakes

                  Troubleshooting

                    Alternatives

                    Memcached is simpler and faster for pure key-value caching but lacks Redis's data structures, persistence, and pub/sub. Valkey is a Redis 7.2 fork (open-source, Linux Foundation) with API compatibility — a drop-in replacement if Redis's SSPL license is a concern. KeyDB is a multi-threaded Redis fork for extreme throughput on multi-core hardware. DragonflyDB claims to be orders of magnitude faster but is newer and less battle-tested. For most self-hosted deployments, standard Redis is the right choice.

                    When Not to Use It

                    Don't use Redis as your only database for critical business data — RAM is expensive and data can be lost if persistence isn't configured. If your application doesn't have a caching or queuing requirement, Redis adds operational complexity with no benefit. For simple job queues with moderate volume, database-backed queues (like Laravel's database driver) are simpler and require no extra service. If your server has very limited RAM (under 512 MB), a Redis instance may compete with your application for memory.

                    PrismaTechWork Professional Help

                    PrismaTechWork provides end-to-end infrastructure services — from initial deployment and security hardening to ongoing monitoring, automated backups, and dedicated support. Whether you need a single-server setup or a multi-site network, our team ensures your infrastructure is built right, secured properly, and maintained reliably.

                      Contact Us

                      Frequently Asked Questions

                      Is Redis free and open source?

                      Redis is open source but its license changed in 2024 from BSD to SSPL (Server Side Public License) for versions 7.4+. SSPL is not OSI-approved. If the license is a concern, Valkey is a fully open-source Redis 7.2 fork under the BSD license, maintained by the Linux Foundation, and is a drop-in replacement.

                      What's the difference between Redis cache and Redis queue?

                      They're the same Redis instance used differently. As a cache, your app writes data with a TTL and reads it back to skip slow queries. As a queue, your app pushes jobs to a Redis List and a worker process pops and executes them. You can use separate Redis databases (SELECT 0 for cache, SELECT 1 for queue) or separate Redis instances to isolate them.

                      Does Redis lose data when the server restarts?

                      By default, yes — all data is in RAM. Enable RDB snapshots (save directives in redis.conf) for periodic dumps to disk, or AOF (appendonly yes) to log every write command. With both enabled, Redis survives restarts with minimal data loss. For pure caching use cases, losing cache data on restart is acceptable since apps rebuild the cache automatically.

                      How do I connect my Laravel app to Redis?

                      Set REDIS_HOST, REDIS_PORT, and REDIS_PASSWORD in your .env file. Set CACHE_DRIVER=redis and QUEUE_CONNECTION=redis to use Redis for caching and queuing. Make sure the predis/predis package or the phpredis PHP extension is installed. Run php artisan config:cache after updating .env.

                      Can Redis handle millions of keys?

                      Yes. Redis can hold hundreds of millions of keys as long as RAM is sufficient. Each key-value pair has a small overhead (~60–80 bytes for a simple string). A server with 8 GB RAM can comfortably hold tens of millions of typical cache entries. Monitor memory with redis-cli INFO memory and set a maxmemory limit with an eviction policy like allkeys-lru.

                      How do I secure Redis from the internet?

                      Three layers: (1) Bind Redis to localhost or a private IP — never 0.0.0.0 on a public server. (2) Set a strong requirepass. (3) Block port 6379 at the firewall. On UFW: ufw deny 6379 and only allow specific IPs that need access. Never expose Redis directly to the internet even with a password — it has no brute-force protection.

                      What is Redis Sentinel and do I need it?

                      Redis Sentinel provides automatic failover for high-availability setups — if the primary Redis instance goes down, Sentinel promotes a replica automatically. You need it if Redis is critical infrastructure and downtime is unacceptable. For most self-hosted setups with a single server, Sentinel is overkill — just enable persistence and monitor the service with Uptime Kuma.

                      How do I monitor Redis performance?

                      Use redis-cli INFO all for a full stats dump. Key metrics: used_memory (RAM consumed), connected_clients (active connections), keyspace_hits/misses (cache hit rate), total_commands_processed (throughput). For real-time monitoring, run redis-cli MONITOR in dev (never production). For dashboards, connect Redis Exporter with Prometheus + Grafana, or use Beszel which includes Redis metrics.