-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8b2b099
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/target | ||
/lib | ||
/classes | ||
/checkouts | ||
pom.xml | ||
*.jar | ||
*.class | ||
.lein-deps-sum | ||
.lein-failures | ||
.lein-plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: clojure | ||
lein: lein2 | ||
script: lein2 all test | ||
jdk: | ||
- openjdk6 | ||
- openjdk7 | ||
- oraclejdk7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# What is Spyglass | ||
|
||
Spyglass is a Clojure client for Memcached built on top of [SpyMemcached](http://code.google.com/p/spymemcached/) | ||
|
||
|
||
## This is a Work In Progress | ||
|
||
Spyglass is *very* young and incomplete. Nothing to see here yet, move along. | ||
|
||
|
||
## Development | ||
|
||
Spyglass uses [Leiningen 2](https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md). Make sure you have it installed and then run tests against | ||
all supported Clojure versions using | ||
|
||
lein2 all test | ||
|
||
Then create a branch and make your changes on it. Once you are done with your changes and all tests pass, submit | ||
a pull request on Github. | ||
|
||
|
||
## License | ||
|
||
Copyright (C) 2012 Michael S. Klishin | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(defproject clojurewerkz/spyglass "1.0.0-SNAPSHOT" | ||
:description "A Clojure client for Memcached implemented as a very thin layer on top of SpyMemcached" | ||
:url "http://github.com/clojurewerkz/spyglass" | ||
:license {:name "Eclipse Public License" | ||
:url "http://www.eclipse.org/legal/epl-v10.html"} | ||
:dependencies [[org.clojure/clojure "1.3.0"] | ||
[ spy/spymemcached "2.8.1"]] | ||
:repositories {"spy-memcached" {:url "http://files.couchbase.com/maven2/" | ||
:checksum :ignore} | ||
"sonatype" {:url "http://oss.sonatype.org/content/repositories/releases" | ||
:snapshots false | ||
:releases {:checksum :fail :update :always}} | ||
"sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots" | ||
:snapshots true | ||
:releases {:checksum :fail :update :always}}} | ||
:source-paths ["src/clojure"] | ||
:warn-on-reflection true | ||
:profiles {:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]} | ||
:1.5 {:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]}} | ||
:aliases {"all" ["with-profile" "dev:dev,1.4:dev,1.5"]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns clojurewerkz.spyglass.client | ||
(:refer-clojure :exclude [set get]) | ||
(:import [net.spy.memcached MemcachedClient DefaultConnectionFactory BinaryConnectionFactory AddrUtil])) | ||
|
||
|
||
|
||
|
||
(defn- servers | ||
[^String server-list] | ||
(AddrUtil/getAddresses server-list)) | ||
|
||
(defn text-connection | ||
"Returns a new text protocol client that will use the provided list of servers" | ||
[^String server-list] | ||
(MemcachedClient. (DefaultConnectionFactory.) (servers server-list))) | ||
|
||
(defn bin-connection | ||
"Returns a new binary protocol client that will use the provided list of servers" | ||
[^String server-list] | ||
(MemcachedClient. (BinaryConnectionFactory.) (servers server-list))) | ||
|
||
|
||
(defn set | ||
"Set an object in the cache (using the default transcoder) regardless of any existing value" | ||
[^MemcachedClient client ^String key ^long expiration value] | ||
(.set client (name key) expiration value)) | ||
|
||
(defn get | ||
"Get with a single key and decode using the default transcoder" | ||
[^MemcachedClient client ^String key] | ||
(.get client (name key))) | ||
|
||
(defn touch | ||
"Touch the given key to reset its expiration time" | ||
[^MemcachedClient client ^String key ^long expiration] | ||
(.touch client (name key) expiration)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(ns clojurewerkz.spyglass.test.client-test | ||
(:require [clojurewerkz.spyglass.client :as c]) | ||
(:use clojure.test)) | ||
|
||
|
||
(def tc (c/text-connection "localhost:11211")) | ||
(def bc (c/bin-connection "localhost:11211")) | ||
|
||
(deftest test-set-then-get | ||
(testing "with text protocol" | ||
(are [k v] | ||
(do (c/set tc k 10 v) | ||
(is (= v (c/get tc k)))) | ||
"s-key" "s-value" | ||
"l-key" 100000 | ||
"kw-key" :memcached | ||
:sym 'symbol | ||
"ratio-key" 3/8)) | ||
(testing "with binary protocol" | ||
(are [k v] | ||
(do (c/set bc k 10 v) | ||
(is (= v (c/get bc k)))) | ||
"s-key" "s-value" | ||
"l-key" 100000 | ||
"kw-key" :memcached | ||
:sym 'symbol | ||
"ratio-key" 3/8))) | ||
|
||
|
||
(deftest test-set-then-touch | ||
(testing "with text protocol" | ||
(are [k v] | ||
(do (c/set tc k 10 v) | ||
;; touch is not supported by the text protocol | ||
(is (thrown? UnsupportedOperationException | ||
(.get (c/touch tc k 4))))) | ||
"s-key" "s-value" | ||
"l-key" 100000 | ||
"kw-key" :memcached | ||
:sym 'symbol | ||
"ratio-key" 3/8)) | ||
(testing "with binary protocol" | ||
(are [k v] | ||
(do (c/set bc k 10 v) | ||
(is (.get (c/touch bc k 4)))) | ||
"s-key" "s-value" | ||
"l-key" 100000 | ||
"kw-key" :memcached | ||
:sym 'symbol | ||
"ratio-key" 3/8))) |