Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sfertman/molecula
Clojure refs on Redis with one line of code
https://github.com/sfertman/molecula
Last synced: 19 days ago
JSON representation
Clojure refs on Redis with one line of code
- Host: GitHub
- URL: https://github.com/sfertman/molecula
- Owner: sfertman
- License: mit
- Created: 2020-02-25T16:22:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T21:28:24.000Z (8 months ago)
- Last Synced: 2024-10-11T23:24:37.083Z (about 1 month ago)
- Language: Clojure
- Homepage:
- Size: 139 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# molecula
Clojure refs on redis with one line of code (experimental).[![Clojars Project](https://img.shields.io/clojars/v/molecula.svg)](https://clojars.org/molecula)
[![cljdoc badge](https://cljdoc.org/badge/molecula/molecula)](https://cljdoc.org/d/molecula/molecula/CURRENT/doc/readme)
![Clojure CI](https://github.com/sfertman/molecula/workflows/Clojure%20CI/badge.svg?branch=master)require
```clojure
(require '[molecula.core :as mol :refer [redis-ref]])
```redis connection
```clojure
(def conn {:pool {} :spec {:uri "redis://localhost:6379"}})
```def ref
```clojure
;; was: (def rr (ref {:so {:much "data"}})), and now:
(def rr (redis-ref conn :ref-key {:so {:much "data"}}))
```dosync
```clojure
;; 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](https://docs.docker.com/compose/install/).
To start a local backend:
```shell
$ 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.