Skip to content

Clojure refs on Redis with one line of code

License

Notifications You must be signed in to change notification settings

sfertman/molecula

Repository files navigation

molecula

Clojure refs on redis with one line of code (experimental).

Clojars Project cljdoc badge Clojure CI

require

(require '[molecula.core :as mol :refer [redis-ref]])

redis connection

(def conn {:pool {} :spec {:uri "redis://localhost:6379"}})

def ref

;; was: (def rr (ref {:so {:much "data"}})), and now:
(def rr (redis-ref conn :ref-key {:so {:much "data"}}))

dosync

;; was (dosync ..., and now:
(mol/dosync conn
  (alter this inc)
  (println "hello")
  (alter that dec)
  (println "all-done"))

Everything else is (or should be) the same as refs except redis-ref uses optimistic locking instead of implementing STM on Redis.

Some stuff is still on TODO list:

  • transaction timeout
  • dispatch agents
  • some exceptions are not exactly the same
  • tests, tests and more tests

Testing

Running the test suite requires redis backend service which can be easily created with docker-compose. To start a local backend:

$ cd redis
$ docker-compose up -d

This will start a redis server on 6379 and a redis-commander on 8081. If you are a fan of redis-cli, run redis-cli.sh script in the same dir for the console.

About

Clojure refs on Redis with one line of code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published