Installing Redis on macOS
Saturday, March 8th, 2025I have always liked redis as a wonderful example of very targeted software done very well. It's a single-threaded C app that does one thing, very well, and in the years since I started using it, it's only gotten better. As I've been building a new Clojure web app, one of the things I wanted to take advantage of, was the stored session state, specifically so that when I have multiple boxes running the code, they can all share the one session state - and quickly.
I've been getting my WebAuthN authentication going, and that is using session state as the place to store the :identity of the logged in user. After I worked out the serialization of the Authenticator for WebAuthN, I then turned my attention to persisting the session state with Ring's SessionStore.
I've started using Ring's wrap-defaults middleware. It's easily added to the options for wrap-defaults with:
; pull in the wrapper and base defaults (:require [ring.middleware.defaults :refer [wrap-defaults site-defaults]]) ; augment the site defaults with the SessionStore from Carmine (def my-site-defaults (assoc site-defaults :session {:flash true :store (carmine-store)})) ; put it in the stack of the app routes... (-> app-routes (wrap-access-rules {:rules rules :on-error unauthorized-handler}) (wrap-authorization backend) (wrap-authentication backend) wrap-user wrap-json-with-padding (wrap-defaults my-site-defaults) wrap-logging wrap-gzip)))
I've been a huge fan of carmine for many years, as it's a pure Clojure library for redis, and it's exceptionaly fast.
But first, I needed to install redis locally so that I can do laptop development and not have to have a connection to a hosted service. Simply:
$ brew install redis
and then to make sure it's started through launchd, simply:
$ brew services start redis
just like with Postgres. It's really very simple.
At this point, restarting the web server will automatically store the session data in the locally running redis, and for production deployments, it's easy enough to use redis cloud, or redis at AWS, Google Cloud, etc. It's super simple, and it's exceptionally reliable.
The web server can now be restarted without impact to the customers as redis has their session state, and postgres has their Authenticator for WebAuthN.