Liking cljdoc? Tell your friends :D

What is clj-redis-session

clj-redis-session uses redis as a Clojure/Ring's HTTP session storage engine. What makes it different is its support for hierarchical data, actually any print-strable clojure data types.

Why clj-redis-session

The reason I wrote clj-redis-session is that the only redis-backed sesssion store I could find (rrss) doesn't support hierarchical data structures, e.g. lists, maps.



[clj-redis-session "2.1.0"]

to :dependencies in your project.clj.


clj-redis-session is a drop-in replacement for Ring native session stores. clj-redis-session uses Carmine as its Redis client.

(ns hello
    [clj-redis-session.core :only [redis-store]]))

;; clj-redis-session use Carmine as its Redis client
(def redis-conn {:pool {<pool-opts>} :spec {<spec-opts>}})

(def app
  (-> your-routes
      ... other middlewares ...
      (wrap-session {:store (redis-store redis-conn)})

Want sessions to automatically expire?

# expire after 12 hours
(wrap-session your-app {:store (redis-store redis-conn {:expire-secs (* 3600 12)})})

Extend session expiration time while reading the session

# everytime when session gets read, it will reset current session expiration time.
(wrap-session your-app {:store (redis-store redis-conn {:expire-secs (* 3600 12)
                                                        :reset-on-read true})})

You can also change the prefix (default to session) for the keys in redis:

(wrap-session your-app {:store (redis-store redis-conn {:prefix "i-am-prefix"})})


Copyright (C) 2013 Zhe Wu

Distributed under the Eclipse Public License, the same as Clojure.

Can you improve this documentation? These fine people already did:
Zhe Wu, L, klodio, Wu Zhe & Sam Ritchie
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close