Redis Pooler, Request-ID Middlewares

New Lack libraries have been pushed to GitHub:

lack-middleware-redis

The lack-middleware-redis middleware provides Redis connection pools to your application that can be used for arbitrary purposes, such as various types of caching, or writing job data to the store of a work queue such as Psychiq.

The implementation of this middleware closely resembles the recently released lack-middleware-postmodern, as both middlewares rely on anypool to abstract away connection management logic, and both allow configuring multiple pools.

(lack:builder
 (:redis :pools '((:pool-id :cache
                   :host "redis01.example.com"
                   :port 6379
                   :max-open-count 10
                   :max-idle-count 4
                   :timeout 2000
                   :idle-timeout 40000)
                  (:pool-id :jobs
                   :host "redis02.example.com"
                   :max-open-count 12)))
 *app*)

From your application, you can checkout an idle connection from a specific pool by calling the WITH-REDIS macro:

(with-redis (:cache)
  (red:set "foo" "bar"))

lack-session-store-redis-pool

This project is a fork of the official lack-session-store-redis library, and also relies on anypool. It provides a pool of Redis connections used specifically for session storage.

(lack/builder
  (:session :state (lack/session/state/cookie:make-cookie-state
                     :cookie-key "_sid"
                     :path "/"
                     :domain "localhost"
                     :expires 3600
                     :httponly t
                     :secure nil
                     :samesite :strict)
            :store (lack/middleware/session/store/redis-pool:make-redis-store
                     :host "redis01.acme.example.com"
                     :max-open-count 10
                     :max-idle-count 3))
  *app*)

lack-middleware-request-id

Lack-middleware-request-id adds REQUEST-ID to the Lack ENV and X-Request-Id to the response headers.

When the request already has an X-Request-Id header, as when set by an upstream server, the middleware uses that value; otherwise it generates a new request-ID using frugal-uuid.

The X-Request-Id header can be used for purposes of request correlation and distributed tracing.

(lack/builder:builder
 :request-id
 *app*)

demo-app update

The Vinland To Do app has been updated to demonstrate these new libraries: