Skip to content

Integrant methods for connecting to a Redis database via Carmine

Notifications You must be signed in to change notification settings

duct-framework/database.redis.carmine

Repository files navigation

Duct database.redis.carmine

Build Status

Integrant methods for connecting to a Redis database via Carmine.

Installation

To install, add the following to your project :dependencies:

[duct/database.redis.carmine "0.1.1"]

Usage

This library provides two things: a Boundary record that holds connection options for Carmine, and a multimethod for :duct.database.redis/carmine that initiates a those options into the Boundary.

{:duct.database.redis/carmine {:spec {:host "127.0.0.1", :port 6379}}}

When you write functions against the Redis database, consider using a protocol and extending the Boundary record. This will allow you to easily mock or stub out the database using a tool like Shrubbery.

Example

Consider a redis database where users are stored as hashmap with keys like user:{username}.

The connection spec needed by Carmine can be extracted from this module Boundary by using the :conn-opts key.

(ns my-project.boundary.user-db
  (:require [duct.database.redis.carmine]
            [taoensso.carmine :as car :refer (wcar)]))
            
(defprotocol UserDatabase
  (get-user [db username]))
  
(extend-protocol UserDatabase
  duct.database.redis.carmine.Boundary
  (get-user [db username]
    (car/wcar (:conn-opts db) 
      (car/hgetall (str "user:" username))))) 

License

Copyright © 2018 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Integrant methods for connecting to a Redis database via Carmine

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published