Skip to content

Commit

Permalink
Delay db evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhe Wu committed Sep 20, 2012
1 parent d0e8fce commit d4aaad1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Installation

Add

[clj-redis-session "0.3.0"]
[clj-redis-session "0.4.0"]

to `:dependencies` in your `project.clj`.

Expand All @@ -32,11 +32,13 @@ Usage
[clj-redis-session.core :only [redis-store]]
[clj-redis.client :only [redis])

(def store (redis/init {:url "redis://127.0.0.1:6379"}))
(def STORE (atom nil))
(reset! STORE (redis/init {:url "redis://127.0.0.1:6379"}))

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

Want sessions to automatically expire?
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject clj-redis-session "0.3.0"
(defproject clj-redis-session "0.4.0"
:description "Redis-backed Clojure/Ring session store"
:dependencies [[org.clojure/clojure "1.4.0"]
[ring/ring-core "1.1.5"]
Expand Down
8 changes: 4 additions & 4 deletions src/clj_redis_session/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
SessionStore
(read-session [_ session-key]
(when session-key
(when-let [data (r/get db session-key)]
(when-let [data (r/get @db session-key)]
(read-string data))))
(write-session [_ session-key data]
(let [session-key (or session-key (new-session-key prefix))
data-str (binding [*print-dup* true]
(print-str data))]
(if expiration
(r/setex db session-key expiration data-str)
(r/set db session-key data-str))
(r/setex @db session-key expiration data-str)
(r/set @db session-key data-str))
session-key))
(delete-session [_ session-key]
(r/del db [session-key])
(r/del @db [session-key])
nil))

(defn redis-store
Expand Down

0 comments on commit d4aaad1

Please sign in to comment.