Chapter

Redis and Laravel

Wire Redis into a Laravel 11 app: connect it, use the Redis facade, and set it as your cache, session, and queue store.

Redis Basics 6 Lessons from courses

About this chapter

Now you take everything you learned in the console and put it to work inside a real Laravel 11 app. You will connect Redis, run commands through the Redis facade, make Redis your cache store, cache with Cache::remember, group entries with tags, and point sessions and queues at Redis.

Lessons from courses

  1. 1 Connecting Redis to Laravel Connect Redis to a Laravel 11 app: the redis config block, REDIS_HOST/PORT/PASSWORD env keys, phpredis vs predis, and a Redis::ping() check.
  2. 2 Using the Redis facade Use the Laravel Redis facade to run raw commands: set, get, hset, del. Covers the default connection and the automatic REDIS_PREFIX on every key.
  3. 3 Redis as the cache driver Make Redis your Laravel 11 cache store with one line, CACHE_STORE=redis. How the Redis cache driver differs from file and array, and why it uses its own database.
  4. 4 Caching in Laravel Cache in Laravel with the Cache facade: remember, put, get, has, forget, flush, rememberForever, add, increment. The Cache::remember pattern, explained.
  5. 5 Cache tags Group cache entries with Laravel cache tags and flush a whole group in one call. Why tags need a taggable store like Redis, with a real posts example.
  6. 6 Sessions and queues on Redis Run Laravel sessions and queues on Redis with SESSION_DRIVER=redis and QUEUE_CONNECTION=redis. Why Redis fits both, plus dispatch and queue:work.
Redis Basics Go to course