Permalink
Browse files

delay the redis connection

  • Loading branch information...
1 parent bfcbc1f commit 2aca28bb228c36374e5a21bccbb774438bc1c223 @dmix committed Feb 16, 2012
Showing with 16 additions and 15 deletions.
  1. +13 −12 src/documeds/models/medication.clj
  2. +3 −3 src/documeds/scrapers/ncbi.clj
View
25 src/documeds/models/medication.clj
@@ -15,27 +15,28 @@
documeds.models.keys))
; [aleph.redis :only (redis-client)]
-(def r (redis-client {:host redis-url :password redis-pass :port redis-port}))
+
+(def r (delay (redis-client {:host redis-url :password redis-pass :port redis-port})))
; (def r ())
; Index ------------------------------------------------------------------------
(defn index []
- @(r [:smembers (key-medications-index)]))
+ @(@r [:smembers (key-medications-index)]))
(defn add-index [id]
- @(r [:sadd (key-medications-index) id]))
+ @(@r [:sadd (key-medications-index) id]))
(defn remove-index [id]
- @(r [:srem (key-medications-index) id]))
+ @(@r [:srem (key-medications-index) id]))
(defn increment []
- @(r [:incr (key-increment-medications)]))
+ @(@r [:incr (key-increment-medications)]))
; Getters ------------------------------------------------------------------------
(defn retrieve [id]
- (let [medication (apply hash-map @(r [:hgetall (key-medication id)]))]
+ (let [medication (apply hash-map @(@r [:hgetall (key-medication id)]))]
(when (not (empty? medication))
{:id (medication "id")
:title (medication "title")
@@ -49,20 +50,20 @@
; Setters ------------------------------------------------------------------------
(defn set-id [id new-id]
- @(r [:hset (key-medication id) "id" new-id]))
+ @(@r [:hset (key-medication id) "id" new-id]))
(defn set-title [id new-title]
- @(r [:hset (key-medication id) "title" new-title]))
+ @(@r [:hset (key-medication id) "title" new-title]))
(defn set-dosage [id new-dosage]
- @(r [:hset (key-medication id) "dosage" new-dosage]))
+ @(@r [:hset (key-medication id) "dosage" new-dosage]))
(defn add! [medication]
(let [id (increment)
title (medication "title")
dosage (medication "dosage")]
(add-index id) ; Add id to medications seq of IDs
- @(r [:hmset (key-medication id) "id" id
+ @(@r [:hmset (key-medication id) "id" id
"title" title
"dosage" dosage])))
@@ -75,14 +76,14 @@
(let [id (medication :id)
title (medication :title)
dosage (medication :dosage)]
- @(r [:hmset (key-medication id) "id" id
+ @(@r [:hmset (key-medication id) "id" id
"title" title
"dosage" dosage])))
(defn remove! [medication]
(let [id (medication :id)]
(remove-index id) ; Remove id to medications seq of IDs
- @(r [:del (key-medication id)])))
+ @(@r [:del (key-medication id)])))
; Validation ------------------------------------------------------------------------
View
6 src/documeds/scrapers/ncbi.clj
@@ -1,10 +1,10 @@
(ns documeds.scrapers.ncbi
(:use [net.cgrand.enlive-html :as html]
net.cgrand.moustache
- aleph.redis))
+ [aleph.redis :only (redis-client)]))
(def letters (map char (concat (range 97 123))))
-(def r (redis-client {:host redis-url :password redis-pass :port redis-port}))
+(def r (delay (redis-client {:host redis-url :password redis-pass :port redis-port})))
(defn info-url [url]
(str "http://www.ncbi.nlm.nih.gov" url))
@@ -21,4 +21,4 @@
(defn store-urls []
(doseq [letter letters]
(doseq [item (parse-urls letter)]
- @(r [:sadd "medication-urls" ((item :attrs) :href)]))))
+ @(@r [:sadd "medication-urls" ((item :attrs) :href)]))))

0 comments on commit 2aca28b

Please sign in to comment.