Skip to content
Integrant methods for connecting to a Redis database via Carmine
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/duct/database/redis
test/duct/database/redis
.gitignore
.travis.yml
README.md
project.clj

README.md

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.

You can’t perform that action at this time.