Back Button Tooling

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.

7 episodes
1:14:36 hrs
Start Series
  • Latest Episode: Fetch In Progress Articles

  • Like this series? Share the love!

    1. 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.

    2. 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.

    3. 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.

    4. Run Time 11:24

      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.

    5. Run Time 14:00

      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.

    6. 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.

    7. 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.