Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created January 13, 2011 12:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepijndevos/777770 to your computer and use it in GitHub Desktop.
Save pepijndevos/777770 to your computer and use it in GitHub Desktop.
(ns slouchdb)
; Fast scalable in-memory concurrent NoSQL database
(def db (ref {:bob {:age 59 :sex :male}
:bill {:age 17 :sex :male}
:mary {:age 28 :sex :female}}))
;; Views ;;
(defn total-age []
(reduce + (pmap (comp :age val) @db))) ; Parallel MapReduce!
;; Examples ;;
(println (apply str (interpose \newline
["Get an item"
(:bob @db)
"MapReduce"
(total-age)
"Add/update an item"
(dosync (alter db assoc-in [:bill :age] 25))
"Delete an item"
(dosync (alter db dissoc :mary))])))
; For scaling, press CMD or CTRL and + or -
; For a persistent version, see java.io.Serializable
; For a REST API, check out Moustache and Aleph.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment