What Redis is: an in-memory data structure server

Free preview 3 min to read

Redis's documentation opens its data types page with a short claim: "Redis is a data structure server". That makes it neither a relational database nor a plain cache. It's a separate network service your app talks to. It holds data in RAM, organized as a set of named data structures instead of rows and columns.

This app never talks to one. A grep across this app's Gemfile and Gemfile.lock for redis, in any casing, returns nothing: no gem and no transitive dependency. The earlier course "Job processors: Sidekiq aware" reached the same result from another angle. Sidekiq, the gem many Rails developers associate with background jobs, requires Redis as its storage layer, and this app runs Solid Queue instead. That course also covered two facts this course won't re-derive. Redis keeps data in RAM, and it has two persistence mechanisms, RDB snapshots (on by default) and an AOF log (off by default), that decide how much survives a crash.

So why does a course on Redis exist in an app that doesn't use it?

Because "in-memory data store" covers more than Sidekiq's queue. Redis is one of the most widely deployed pieces of infrastructure, and its data structures, persistence tradeoffs and pub/sub mechanism are worth knowing whether or not a given app adopts it. This course checks each Redis claim against Redis's documentation. It also keeps pointing at this app's choice not to run Redis, as the previous course did for Sidekiq.

The shape of the comparison

In many Rails apps, Redis does three jobs that this app handles with its database. "Solid Cache: database caching" covered Rails.cache backed by the SolidCache::Entry table. "Solid Queue: background jobs" covered this app's job queue, backed by Postgres tables. The third is Action Cable's adapter: this app's Gemfile has gem "solid_cable", so broadcasts go through Postgres too. Cache, queue and Action Cable's pub/sub layer, the three roles Redis commonly plays in a Rails app, all run on this app's Postgres server. The closing lesson puts that together.

What this course covers

Seven lessons. Each Redis claim is checked against Redis's documentation, and each claim about this app against its current Gemfile and config. Lessons 2 to 4 cover Redis's core data types: strings, then lists and sets, then hashes and sorted sets. Lesson 5 covers how Redis decides what to evict when RAM runs out, with a short recap of the persistence tradeoffs from the Sidekiq course. Lesson 6 covers pub/sub, next to this app's Action Cable adapter. Lesson 7 brings this app's Redis-free setup back together.

Lesson 1 of 7 · free

Keep going with lesson 2

Redis strings: the simplest data type, and what SET/GET do

Covers Redis strings, SET, GET, MSET, MGET and atomic INCR, compared with Solid Cache's row-locked increment.

A free account also gives you the quizzes, your progress and notes, and the discussion.

Type to start searching...