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.
Progress
Series Info
- Episodes
- 7
- Run Time
- 1h 14m
- Difficulty
- Intermediate
- Last Updated
- Nov 14, 2016
- Version
- Latest
Series Episodes
- Episodes (7)
Installation and a Visitor Counter
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.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.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.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'sCachecomponent, and how that fits in with our Redis review.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 customrememberfunction, before switching over to Laravel'sCachecomponent.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 toCache::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.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.
