Reditore is Clojure Ring session store implemented on top of redis db. It uses 2.x version of Clojure redis client Carmine.
Inspiration came from old implmentation clj-session-store and from mongo session store Monger.
Add
[reditore "0.9.0"]
to :dependencies
in your project.clj
.
reditore.core
implements two ways how to store data in redis
- Clojure mode
reditore.core/session-redis-store
. It serializes all objects into Clojure form, which can be decode again only in clojure. It is prefered if you dont need to load session in another language/applications. - Compatible mode
reditore.core/json-session-redis-store
. This serializes data to pure json. Which is easy to load them from any other language/applications.
Warning If you switch one mode for another drop all your sessions to prevent application exceptions from loading wrong format.
(ns myapp
(:require [ring.middleware.session :refer [wrap-session]]
[reditore.core :refer [session-redis-store]]))
(def redis-connection
{:pool {}
:spec {:host "127.0.0.1"
:port 6379}})
(def app
(-> your-routes
... other middlewares ...
(wrap-session {:store (session-redis-store redis-connection)})
... other middlewares ...))
(ns myapp
(:require [noir.util.middleware :refer [app-handler]]
[reditore.core :refer [session-redis-store]]))
(def redis-connection
{:pool {}
:spec {:host "127.0.0.1"
:port 6379}})
(def app
(app-handler [my-routes]
:store (session-redis-store redis-connection)
:middleware [])
When you want to use json compatible mode
; require compatible json-session-redis-store
(:require [reditore.core :refer [json-session-redis-store]])
; use that
(json-session-redis-store redis-connection)
Want sessions to automatically expire?
; expire after 12 hours
(session-redis-store redis-connection {:expire-secs (* 3600 12)})
Or different prefix for redis key?
; Change prefix
(session-redis-store redis-connection {:prefix "my-sessions"})
Reditor is released under the MIT License.