Intermediate

Learn Redis Through Examples

You've probably known for a while now that Redis is a thing. But, like so many others, maybe you've had trouble understanding exactly when you would reach for a key-value database like this. What's wrong with just using MySQL for everything, right? Well, as you'll find, there are a number of situations when Redis emerges as the best possible tool for the job. In this series, you'll work through a number of examples to get up and running with Laravel and Redis as quickly as possible.

Start Series

Share this series on:

  • 01

    Episode 1 Run Time 4:39

    Installation and a Visitor Counter Free

    In this opening episode, we'll get Redis installed on your machine, before moving on to basic Redis usage in Laravel. Let's start with the most old-school of examples: a site visitor counter. As silly as it may be, should you need such a counter, Redis is a perfect choice.
  • 02

    Episode 2 Run Time 6:40

    Counters and Namespacing

    Okay okay, so a website visitor counter is a bit old-fashioned. But, if you think about it, we increment counters all over the place: your number of followers, the times a video has been downloaded, the number of articles you've favorited, etc. Let's review one example in this episode, while also taking time to discuss key name-spacing.
  • 03

    Episode 3 Run Time 19:07

    Trending Articles with Sorted Sets

    You're going to love sorted sets. Think of them as unique arrays that automatically sort their items, according to a particular score that you define. You might sort the top scoring basketball teams, a forum leaderboard, or even the most popular video tutorials at Laracasts! When it comes to Redis, even two lines of code can accomplish so much.
  • 04

    Episode 4 Run Time 11:24

    Hashes and Caching

    Next up, let's review Redis' hash data type. Think of these as a Redis equivalent to PHP's associative array. When you need to associate a number of key-value pairs with a single key, this is the type you should reach for. Near the conclusion of this lesson, we'll also touch upon Laravel's Cache component, and how that fits in with our Redis review.

  • 05

    Episode 5 Run Time 14:00

    Caching With Redis

    Caching, of course, is an incredible use-case for Redis. Whether you're caching database queries, API calls, or even HTML fragments, you'll get a lot of use out of the techniques within this episode. We'll begin by building up a custom remember function, before switching over to Laravel's Cache component.
  • 06

    Episode 6 Run Time 8:38

    How to Structure Your Caching Layer

    Before we move on to learning about PubSub in Redis, let's take a short break to review how we might organize our PHP to best take advantage of caching. In the previous episode, we simply wrapped our database query in a call to Cache::remember(). But, what if we want to dry up our code a bit, or even turn the caching on and off (through the use of decorators), like the flick of a switch? In this episode, I'll demonstrate a few options that you might consider.

  • 07

    Episode 7 Run Time 10:08

    Fetch In Progress Articles

    Laracasts offers the ability to view recent series that you are currently working through. While this can easily be accomplished with a traditional MySQL pivot table, leveraging Redis is faster, and more practical. In this episode, I'll demonstrate the basic workflow to implement such a feature on your own website.