Skip to content

Commit

Permalink
added delete-val function
Browse files Browse the repository at this point in the history
  • Loading branch information
shughes committed Sep 23, 2009
1 parent 705434b commit 2c21526
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/clojure/memcached.clj
Expand Up @@ -63,8 +63,9 @@
os (new DataOutputStream (. client getOutputStream))
is (new DataInputStream (. client getInputStream))]
(f os is))
(catch UnknownHostException e e)
(catch IOException e e)))
(catch UnknownHostException e (println e))
(catch IOException e (println e))))


(defn set-val
"Sets a value in memcached. If a value already exists with that key, it
Expand All @@ -80,6 +81,13 @@
(not= (. response trim) "STORED") (recur)
:else true))))))

(defn delete-val [sockets key]
(init sockets key
(fn [os is]
(. os (writeBytes (str "delete " key "\r\n")))
(let [response (. (. is readLine) trim)]
response))))

(defn get-val
"Gets the key's value in memcached."
[sockets key]
Expand All @@ -92,4 +100,9 @@
(cond (= nil response) ""
(= "END" (. response trim)) (conj full-response response)
(not= "END" (. response trim)) (recur (conj full-response response)))))]
(first (rest r))))))
(if (= (count r) 1)
nil
(first (rest r)))))))



0 comments on commit 2c21526

Please sign in to comment.