GithubHelp home page GithubHelp logo

setzer22 / redis-atom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sfertman/redis-atom

0.0 1.0 0.0 71 KB

Share clojure atoms between services via redis with one line of code

License: MIT License

Shell 0.33% Clojure 99.67%

redis-atom's Introduction

redis-atom

Share clojure atoms between services via redis with one line of code.

Clojars Project

Using

Define redis connection spec like with taoensso.carmine. Define an atom by passing in the connetion spec, a key that will point to the atom value on Redis and the atom value. Note that if the input key already exists on redis backend then the input value will not be assigned to it. Everything else is exactly the same as with Clojure atoms.

(require '[redis-atom.core :refer [redis-atom]])

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

(def a (redis-atom conn :redis-key {:my-data "42" :more-data 43}))

a ; => #object[redis_atom.core.RedisAtom 0x471a378 {:status :ready, :val {:my-data "42", :more-data 43}}]
@a ; => {:my-data "42" :more-data 43}

(def b (redis-atom conn :redis-key 42))
@b ; => {:my-data "42" :more-data 43}

(reset! a 42) ; => 42
@b ; => 42

(reset-vals! a 43) ; => [42 43]
(swap! a inc) ; => 44
(swap-vals! a inc) ; => [44 45]

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.

redis-atom's People

Contributors

sfertman avatar kwisath avatar setzer22 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.